Skip to content

Commit 22d21bc

Browse files
jbrockmendelim-vinicius
authored and
im-vinicius
committed
DEPR: downcast keyword in Index.fillna (pandas-dev#53956)
* DEPR: downcast keyword in Index.fillna * GH ref * docstring fixup
1 parent 25249e4 commit 22d21bc

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ Other API changes
249249
Deprecations
250250
~~~~~~~~~~~~
251251
- Deprecated 'broadcast_axis' keyword in :meth:`Series.align` and :meth:`DataFrame.align`, upcast before calling ``align`` with ``left = DataFrame({col: left for col in right.columns}, index=right.index)`` (:issue:`51856`)
252+
- Deprecated 'downcast' keyword in :meth:`Index.fillna` (:issue:`53956`)
252253
- Deprecated 'fill_method' and 'limit' keywords in :meth:`DataFrame.pct_change`, :meth:`Series.pct_change`, :meth:`DataFrameGroupBy.pct_change`, and :meth:`SeriesGroupBy.pct_change`, explicitly call ``ffill`` or ``bfill`` before calling ``pct_change`` instead (:issue:`53491`)
253254
- Deprecated 'method', 'limit', and 'fill_axis' keywords in :meth:`DataFrame.align` and :meth:`Series.align`, explicitly call ``fillna`` on the alignment results instead (:issue:`51856`)
254255
- Deprecated 'quantile' keyword in :meth:`Rolling.quantile` and :meth:`Expanding.quantile`, renamed as 'q' instead (:issue:`52550`)

pandas/core/indexes/base.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -2927,7 +2927,7 @@ def notna(self) -> npt.NDArray[np.bool_]:
29272927

29282928
notnull = notna
29292929

2930-
def fillna(self, value=None, downcast=None):
2930+
def fillna(self, value=None, downcast=lib.no_default):
29312931
"""
29322932
Fill NA/NaN values with the specified value.
29332933
@@ -2941,6 +2941,8 @@ def fillna(self, value=None, downcast=None):
29412941
or the string 'infer' which will try to downcast to an appropriate
29422942
equal type (e.g. float64 to int64 if possible).
29432943
2944+
.. deprecated:: 2.1.0
2945+
29442946
Returns
29452947
-------
29462948
Index
@@ -2958,6 +2960,16 @@ def fillna(self, value=None, downcast=None):
29582960
"""
29592961
if not is_scalar(value):
29602962
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}")
2963+
if downcast is not lib.no_default:
2964+
warnings.warn(
2965+
f"The 'downcast' keyword in {type(self).__name__}.fillna is "
2966+
"deprecated and will be removed in a future version. "
2967+
"It was previously silently ignored.",
2968+
FutureWarning,
2969+
stacklevel=find_stack_level(),
2970+
)
2971+
else:
2972+
downcast = None
29612973

29622974
if self.hasnans:
29632975
result = self.putmask(self._isnan, value)

pandas/tests/indexes/test_old_base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,11 @@ def test_fillna(self, index):
593593
idx = type(index)(values)
594594

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

600602
expected = np.array([False] * len(idx), dtype=bool)
601603
expected[1] = True

0 commit comments

Comments
 (0)