Skip to content

Commit 96eee10

Browse files
jbrockmendelphofl
authored andcommitted
DEPR Series[td64].fillna(incompatible) (pandas-dev#49479)
1 parent 34e5da8 commit 96eee10

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ Removal of prior version deprecations/changes
409409
- Changed behavior of setitem-like operations (``__setitem__``, ``fillna``, ``where``, ``mask``, ``replace``, ``insert``, fill_value for ``shift``) on an object with :class:`DatetimeTZDtype` when using a value with a non-matching timezone, the value will be cast to the object's timezone instead of casting both to object-dtype (:issue:`44243`)
410410
- Changed behavior of :class:`Index`, :class:`Series`, :class:`DataFrame` constructors with floating-dtype data and a :class:`DatetimeTZDtype`, the data are now interpreted as UTC-times instead of wall-times, consistent with how integer-dtype data are treated (:issue:`45573`)
411411
- Removed the deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`)
412+
- Changed behavior of :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtype and an incompatible ``fill_value``; this now casts to ``object`` dtype instead of raising, consistent with the behavior with other dtypes (:issue:`45746`)
412413
- Change the default argument of ``regex`` for :meth:`Series.str.replace` from ``True`` to ``False``. Additionally, a single character ``pat`` with ``regex=True`` is now treated as a regular expression instead of a string literal. (:issue:`36695`, :issue:`24804`)
413414
- Changed behavior of :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``; object-dtype columns with all-bool values will no longer be included, manually cast to ``bool`` dtype first (:issue:`46188`)
414415
- Changed behavior of comparison of a :class:`Timestamp` with a ``datetime.date`` object; these now compare as un-equal and raise on inequality comparisons, matching the ``datetime.datetime`` behavior (:issue:`36131`)

pandas/core/internals/blocks.py

-31
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
cast,
1212
final,
1313
)
14-
import warnings
1514

1615
import numpy as np
1716

@@ -36,7 +35,6 @@
3635
)
3736
from pandas.errors import AbstractMethodError
3837
from pandas.util._decorators import cache_readonly
39-
from pandas.util._exceptions import find_stack_level
4038
from pandas.util._validators import validate_bool_kwarg
4139

4240
from pandas.core.dtypes.astype import astype_array_safe
@@ -1545,35 +1543,6 @@ def putmask(self, mask, new) -> list[Block]:
15451543

15461544
return [self]
15471545

1548-
def fillna(
1549-
self, value, limit: int | None = None, inplace: bool = False, downcast=None
1550-
) -> list[Block]:
1551-
# Caller is responsible for validating limit; if int it is strictly positive
1552-
1553-
if self.dtype.kind == "m":
1554-
try:
1555-
res_values = self.values.fillna(value, limit=limit)
1556-
except (ValueError, TypeError):
1557-
# GH#45746
1558-
warnings.warn(
1559-
"The behavior of fillna with timedelta64[ns] dtype and "
1560-
f"an incompatible value ({type(value)}) is deprecated. "
1561-
"In a future version, this will cast to a common dtype "
1562-
"(usually object) instead of raising, matching the "
1563-
"behavior of other dtypes.",
1564-
FutureWarning,
1565-
stacklevel=find_stack_level(),
1566-
)
1567-
raise
1568-
else:
1569-
res_blk = self.make_block(res_values)
1570-
return [res_blk]
1571-
1572-
# TODO: since this now dispatches to super, which in turn dispatches
1573-
# to putmask, it may *actually* respect 'inplace=True'. If so, add
1574-
# tests for this.
1575-
return super().fillna(value, limit=limit, inplace=inplace, downcast=downcast)
1576-
15771546
def delete(self, loc) -> Block:
15781547
# This will be unnecessary if/when __array_function__ is implemented
15791548
values = self.values.delete(loc)

pandas/tests/series/methods/test_fillna.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,12 @@ def test_timedelta_fillna(self, frame_or_series):
243243
expected = frame_or_series(expected)
244244
tm.assert_equal(result, expected)
245245

246-
# interpreted as seconds, no longer supported
247-
msg = "value should be a 'Timedelta', 'NaT', or array of those. Got 'int'"
248-
wmsg = "In a future version, this will cast to a common dtype"
249-
with pytest.raises(TypeError, match=msg):
250-
with tm.assert_produces_warning(FutureWarning, match=wmsg):
251-
# GH#45746
252-
obj.fillna(1)
246+
# GH#45746 pre-1.? ints were interpreted as seconds. then that was
247+
# deprecated and changed to raise. In 2.0 it casts to common dtype,
248+
# consistent with every other dtype's behavior
249+
res = obj.fillna(1)
250+
expected = obj.astype(object).fillna(1)
251+
tm.assert_equal(res, expected)
253252

254253
result = obj.fillna(Timedelta(seconds=1))
255254
expected = Series(

0 commit comments

Comments
 (0)