Skip to content

REF: Dispatch TimedeltaBlock.fillna to TimedeltaArray #39811

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
Feb 15, 2021
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
24 changes: 7 additions & 17 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
is_datetime64tz_dtype,
is_dtype_equal,
is_extension_array_dtype,
is_integer,
is_list_like,
is_object_dtype,
is_sparse,
Expand Down Expand Up @@ -442,8 +441,7 @@ def fillna(
if self._can_hold_element(value):
nb = self if inplace else self.copy()
putmask_inplace(nb.values, mask, value)
# TODO: should be nb._maybe_downcast?
return self._maybe_downcast([nb], downcast)
return nb._maybe_downcast([nb], downcast)

if noop:
# we can't process the value, but nothing to do
Expand Down Expand Up @@ -2160,10 +2158,8 @@ def get_values(self, dtype: Optional[DtypeObj] = None) -> np.ndarray:
def external_values(self):
# NB: this is different from np.asarray(self.values), since that
# return an object-dtype ndarray of Timestamps.
if self.is_datetimetz:
# avoid FutureWarning in .astype in casting from dt64t to dt64
return self.values._data
return np.asarray(self.values.astype("datetime64[ns]", copy=False))
# avoid FutureWarning in .astype in casting from dt64t to dt64
return self.values._data

def fillna(
self, value, limit=None, inplace: bool = False, downcast=None
Expand Down Expand Up @@ -2228,16 +2224,10 @@ def _holder(self):
def fillna(
self, value, limit=None, inplace: bool = False, downcast=None
) -> List[Block]:
# TODO(EA2D): if we operated on array_values, TDA.fillna would handle
# raising here.
if is_integer(value):
# Deprecation GH#24694, GH#19233
raise TypeError(
"Passing integers to fillna for timedelta64[ns] dtype is no "
"longer supported. To obtain the old behavior, pass "
"`pd.Timedelta(seconds=n)` instead."
)
return super().fillna(value, limit=limit, inplace=inplace, downcast=downcast)
values = self.array_values()
values = values if inplace else values.copy()
new_values = values.fillna(value=value, limit=limit)
return [self.make_block_same_class(values=new_values)]


class ObjectBlock(Block):
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,9 @@ def test_timedelta_fillna(self, frame_or_series):
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

# interpreted as seconds, deprecated
with pytest.raises(TypeError, match="Passing integers to fillna"):
# interpreted as seconds, no longer supported
msg = "value should be a 'Timedelta', 'NaT', or array of those. Got 'int'"
with pytest.raises(TypeError, match=msg):
obj.fillna(1)

result = obj.fillna(Timedelta(seconds=1))
Expand Down