Skip to content

Commit 5b8239c

Browse files
authored
REF: Dispatch TimedeltaBlock.fillna to TimedeltaArray (#39811)
1 parent d5d43e0 commit 5b8239c

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

pandas/core/internals/blocks.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
is_datetime64tz_dtype,
4040
is_dtype_equal,
4141
is_extension_array_dtype,
42-
is_integer,
4342
is_list_like,
4443
is_object_dtype,
4544
is_sparse,
@@ -442,8 +441,7 @@ def fillna(
442441
if self._can_hold_element(value):
443442
nb = self if inplace else self.copy()
444443
putmask_inplace(nb.values, mask, value)
445-
# TODO: should be nb._maybe_downcast?
446-
return self._maybe_downcast([nb], downcast)
444+
return nb._maybe_downcast([nb], downcast)
447445

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

21682164
def fillna(
21692165
self, value, limit=None, inplace: bool = False, downcast=None
@@ -2228,16 +2224,10 @@ def _holder(self):
22282224
def fillna(
22292225
self, value, limit=None, inplace: bool = False, downcast=None
22302226
) -> List[Block]:
2231-
# TODO(EA2D): if we operated on array_values, TDA.fillna would handle
2232-
# raising here.
2233-
if is_integer(value):
2234-
# Deprecation GH#24694, GH#19233
2235-
raise TypeError(
2236-
"Passing integers to fillna for timedelta64[ns] dtype is no "
2237-
"longer supported. To obtain the old behavior, pass "
2238-
"`pd.Timedelta(seconds=n)` instead."
2239-
)
2240-
return super().fillna(value, limit=limit, inplace=inplace, downcast=downcast)
2227+
values = self.array_values()
2228+
values = values if inplace else values.copy()
2229+
new_values = values.fillna(value=value, limit=limit)
2230+
return [self.make_block_same_class(values=new_values)]
22412231

22422232

22432233
class ObjectBlock(Block):

pandas/tests/series/methods/test_fillna.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ def test_timedelta_fillna(self, frame_or_series):
204204
expected = frame_or_series(expected)
205205
tm.assert_equal(result, expected)
206206

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

211212
result = obj.fillna(Timedelta(seconds=1))

0 commit comments

Comments
 (0)