Skip to content

Remove downcast from Index.fillna #57410

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 14, 2024
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
31 changes: 5 additions & 26 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ def notna(self) -> npt.NDArray[np.bool_]:

notnull = notna

def fillna(self, value=None, downcast=lib.no_default):
def fillna(self, value=None):
"""
Fill NA/NaN values with the specified value.

Expand All @@ -2568,12 +2568,6 @@ def fillna(self, value=None, downcast=lib.no_default):
value : scalar
Scalar value to use to fill holes (e.g. 0).
This value cannot be a list-likes.
downcast : dict, default is None
A dict of item->dtype of what to downcast if possible,
or the string 'infer' which will try to downcast to an appropriate
equal type (e.g. float64 to int64 if possible).

.. deprecated:: 2.1.0

Returns
-------
Expand All @@ -2592,28 +2586,13 @@ def fillna(self, value=None, downcast=lib.no_default):
"""
if not is_scalar(value):
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
if downcast is not lib.no_default:
warnings.warn(
f"The 'downcast' keyword in {type(self).__name__}.fillna is "
"deprecated and will be removed in a future version. "
"It was previously silently ignored.",
FutureWarning,
stacklevel=find_stack_level(),
)
else:
downcast = None

if self.hasnans:
result = self.putmask(self._isnan, value)
if downcast is None:
# no need to care metadata other than name
# because it can't have freq if it has NaTs
# _with_infer needed for test_fillna_categorical
return Index._with_infer(result, name=self.name)
raise NotImplementedError(
f"{type(self).__name__}.fillna does not support 'downcast' "
"argument values other than 'None'."
)
# no need to care metadata other than name
# because it can't have freq if it has NaTs
# _with_infer needed for test_fillna_categorical
return Index._with_infer(result, name=self.name)
return self._view()

def dropna(self, how: AnyAll = "any") -> Self:
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/indexes/test_old_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,6 @@ def test_fillna(self, index):

idx = type(index)(values)

msg = "does not support 'downcast'"
msg2 = r"The 'downcast' keyword in .*Index\.fillna is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg2):
with pytest.raises(NotImplementedError, match=msg):
# For now at least, we only raise if there are NAs present
idx.fillna(idx[0], downcast="infer")

expected = np.array([False] * len(idx), dtype=bool)
expected[1] = True
tm.assert_numpy_array_equal(idx._isnan, expected)
Expand Down