Skip to content

DEPR Series[td64].fillna(incompatible) #49479

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 2 commits into from
Nov 4, 2022
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ Removal of prior version deprecations/changes
- 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`)
- 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`)
- 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`)
- 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`)
- 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`)
- 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`)
- 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`)
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Any,
Hashable,
)
import warnings

import numpy as np

Expand All @@ -18,7 +17,6 @@
cache_readonly,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_categorical_dtype,
Expand Down
31 changes: 0 additions & 31 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
cast,
final,
)
import warnings

import numpy as np

Expand All @@ -36,7 +35,6 @@
)
from pandas.errors import AbstractMethodError
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level
from pandas.util._validators import validate_bool_kwarg

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

return [self]

def fillna(
self, value, limit: int | None = None, inplace: bool = False, downcast=None
) -> list[Block]:
# Caller is responsible for validating limit; if int it is strictly positive

if self.dtype.kind == "m":
try:
res_values = self.values.fillna(value, limit=limit)
except (ValueError, TypeError):
# GH#45746
warnings.warn(
"The behavior of fillna with timedelta64[ns] dtype and "
f"an incompatible value ({type(value)}) is deprecated. "
"In a future version, this will cast to a common dtype "
"(usually object) instead of raising, matching the "
"behavior of other dtypes.",
FutureWarning,
stacklevel=find_stack_level(),
)
raise
else:
res_blk = self.make_block(res_values)
return [res_blk]

# TODO: since this now dispatches to super, which in turn dispatches
# to putmask, it may *actually* respect 'inplace=True'. If so, add
# tests for this.
return super().fillna(value, limit=limit, inplace=inplace, downcast=downcast)

def delete(self, loc) -> Block:
# This will be unnecessary if/when __array_function__ is implemented
values = self.values.delete(loc)
Expand Down
13 changes: 6 additions & 7 deletions pandas/tests/series/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,12 @@ def test_timedelta_fillna(self, frame_or_series):
expected = frame_or_series(expected)
tm.assert_equal(result, expected)

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

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