Skip to content

Commit f1633c7

Browse files
authored
Remove downcast from Index.fillna (#57410)
1 parent 3caf55f commit f1633c7

File tree

2 files changed

+5
-33
lines changed

2 files changed

+5
-33
lines changed

pandas/core/indexes/base.py

+5-26
Original file line numberDiff line numberDiff line change
@@ -2555,7 +2555,7 @@ def notna(self) -> npt.NDArray[np.bool_]:
25552555

25562556
notnull = notna
25572557

2558-
def fillna(self, value=None, downcast=lib.no_default):
2558+
def fillna(self, value=None):
25592559
"""
25602560
Fill NA/NaN values with the specified value.
25612561
@@ -2564,12 +2564,6 @@ def fillna(self, value=None, downcast=lib.no_default):
25642564
value : scalar
25652565
Scalar value to use to fill holes (e.g. 0).
25662566
This value cannot be a list-likes.
2567-
downcast : dict, default is None
2568-
A dict of item->dtype of what to downcast if possible,
2569-
or the string 'infer' which will try to downcast to an appropriate
2570-
equal type (e.g. float64 to int64 if possible).
2571-
2572-
.. deprecated:: 2.1.0
25732567
25742568
Returns
25752569
-------
@@ -2588,28 +2582,13 @@ def fillna(self, value=None, downcast=lib.no_default):
25882582
"""
25892583
if not is_scalar(value):
25902584
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
2591-
if downcast is not lib.no_default:
2592-
warnings.warn(
2593-
f"The 'downcast' keyword in {type(self).__name__}.fillna is "
2594-
"deprecated and will be removed in a future version. "
2595-
"It was previously silently ignored.",
2596-
FutureWarning,
2597-
stacklevel=find_stack_level(),
2598-
)
2599-
else:
2600-
downcast = None
26012585

26022586
if self.hasnans:
26032587
result = self.putmask(self._isnan, value)
2604-
if downcast is None:
2605-
# no need to care metadata other than name
2606-
# because it can't have freq if it has NaTs
2607-
# _with_infer needed for test_fillna_categorical
2608-
return Index._with_infer(result, name=self.name)
2609-
raise NotImplementedError(
2610-
f"{type(self).__name__}.fillna does not support 'downcast' "
2611-
"argument values other than 'None'."
2612-
)
2588+
# no need to care metadata other than name
2589+
# because it can't have freq if it has NaTs
2590+
# _with_infer needed for test_fillna_categorical
2591+
return Index._with_infer(result, name=self.name)
26132592
return self._view()
26142593

26152594
def dropna(self, how: AnyAll = "any") -> Self:

pandas/tests/indexes/test_old_base.py

-7
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,6 @@ def test_fillna(self, index):
597597

598598
idx = type(index)(values)
599599

600-
msg = "does not support 'downcast'"
601-
msg2 = r"The 'downcast' keyword in .*Index\.fillna is deprecated"
602-
with tm.assert_produces_warning(FutureWarning, match=msg2):
603-
with pytest.raises(NotImplementedError, match=msg):
604-
# For now at least, we only raise if there are NAs present
605-
idx.fillna(idx[0], downcast="infer")
606-
607600
expected = np.array([False] * len(idx), dtype=bool)
608601
expected[1] = True
609602
tm.assert_numpy_array_equal(idx._isnan, expected)

0 commit comments

Comments
 (0)