Skip to content

BUG: fix+test fillna with non-nano datetime64; closes #27419 #27425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down