Repository: pandas-dev/pandas

Issue:
fillna is broken for Datetime columns [regression]
In 823af7639b94a39609c06a2228ba9e0f31155724 a call to `block._try_coerce_args()` was incorrectly replaced with call to `block._can_hold_element()` (I think under assumption that all block types have identical implementations of `_try_coerce_args` which is not true).

For Datetime blocks this leads to blowing up with `RecursionError: maximum recursion depth exceeded in comparison`.

Prior to the commit I indicated it worked fine, so I consider this a regression.

#### Small reproducer
```python
import pandas as pd
import numpy as np
from io import StringIO as sio

d1 = pd.read_csv(sio('2010,\n,\n2000\n'),header=None,parse_dates=[0])
f1 = np.dtype('datetime64[ms]').type('1970-01-01').astype('datetime64[ms]')
d1[0].fillna(f1)
```
#### Problem description
When the reproducer is launched, it's output is a long stacktrace caused by `RecursionError`.

#### Expected Output
The sample should not raise.

#### Output of ``pd.show_versions()``

<details>

commit           : None
python           : 3.6.8.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.15.0-47-generic
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.0rc0+67.g2ed1f28cf
numpy            : 1.16.2
pytz             : 2018.4
dateutil         : 2.6.0
pip              : 10.0.1
setuptools       : 39.0.1.post20180504
Cython           : 0.29.6
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.10.1
IPython          : None
pandas_datareader: None
bs4              : 4.7.1
bottleneck       : None
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : 0.9.0
pytables         : None
s3fs             : None
scipy            : 1.2.1
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None

</details>

#### Proposed solution
Revert the changes to `fillna()` function here: https://github.com/pandas-dev/pandas/commit/823af7639b94a39609c06a2228ba9e0f31155724?diff=unified#diff-8f51ce8697bdff680b3f71b196c582eeL388


Discussion:
cc @jbrockmendel.

Right now, the `value` in `ExtensionArray.fillna(value)` is supposed to match the `ExtensionArray.dtype.type`. We don't allow coercion of the array here.

We'll probably want to special-case this for backwards compatibility. Not sure about whether we should deprecate non-ns precisions `value`.
I'll take a look at this.  Ultimately we should be dispatching the try_coerce/can_hold stuff to DTA/TDA/PA/EA

Resolving patch:
diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py
--- a/pandas/core/internals/blocks.py
+++ b/pandas/core/internals/blocks.py
@@ -2250,7 +2250,12 @@ def _astype(self, dtype, **kwargs):
     def _can_hold_element(self, element):
         tipo = maybe_infer_dtype_type(element)
         if tipo is not None:
-            return is_dtype_equal(tipo, self.dtype)
+            if self.is_datetimetz:
+                # require exact match, since non-nano does not exist
+                return is_dtype_equal(tipo, self.dtype)
+
+            # GH#27419 if we get a non-nano datetime64 object
+            return is_datetime64_dtype(tipo)
         elif element is NaT:
             return True
         elif isinstance(element, datetime):


Test patch:
diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py
--- a/pandas/tests/series/test_missing.py
+++ b/pandas/tests/series/test_missing.py
@@ -437,6 +437,17 @@ def test_datetime64_tz_fillna(self):
         )
         assert_series_equal(df.fillna(method="bfill"), exp)
 
+    def test_datetime64_non_nano_fillna(self):
+        # GH#27419
+        ser = Series([Timestamp("2010-01-01"), pd.NaT, Timestamp("2000-01-01")])
+        val = np.datetime64("1975-04-05", "ms")
+
+        result = ser.fillna(val)
+        expected = Series(
+            [Timestamp("2010-01-01"), Timestamp("1975-04-05"), Timestamp("2000-01-01")]
+        )
+        tm.assert_series_equal(result, expected)
+
     def test_fillna_consistency(self):
         # GH 16402
         # fillna with a tz aware to a tz-naive, should result in object