Skip to content

Commit 882b228

Browse files
authored
CLN: Change Categorical.map(na_action=) default to None (pandas-dev#58625)
1 parent ad06bbb commit 882b228

File tree

9 files changed

+9
-37
lines changed

9 files changed

+9
-37
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Removal of prior version deprecations/changes
243243
- Removed the "closed" and "unit" keywords in :meth:`TimedeltaIndex.__new__` (:issue:`52628`, :issue:`55499`)
244244
- All arguments in :meth:`Index.sort_values` are now keyword only (:issue:`56493`)
245245
- All arguments in :meth:`Series.to_dict` are now keyword only (:issue:`56493`)
246+
- Changed the default value of ``na_action`` in :meth:`Categorical.map` to ``None`` (:issue:`51645`)
246247
- Changed the default value of ``observed`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby` to ``True`` (:issue:`51811`)
247248
- Enforce deprecation in :func:`testing.assert_series_equal` and :func:`testing.assert_frame_equal` with object dtype and mismatched null-like values, which are now considered not-equal (:issue:`18463`)
248249
- Enforced deprecation ``all`` and ``any`` reductions with ``datetime64``, :class:`DatetimeTZDtype`, and :class:`PeriodDtype` dtypes (:issue:`58029`)

pandas/core/arrays/arrow/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ def to_numpy(
14251425
result[~mask] = data[~mask]._pa_array.to_numpy()
14261426
return result
14271427

1428-
def map(self, mapper, na_action=None):
1428+
def map(self, mapper, na_action: Literal["ignore"] | None = None):
14291429
if is_numeric_dtype(self.dtype):
14301430
return map_array(self.to_numpy(), mapper, na_action=na_action)
14311431
else:

pandas/core/arrays/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
22702270

22712271
return arraylike.default_array_ufunc(self, ufunc, method, *inputs, **kwargs)
22722272

2273-
def map(self, mapper, na_action=None):
2273+
def map(self, mapper, na_action: Literal["ignore"] | None = None):
22742274
"""
22752275
Map values using an input mapping or function.
22762276

pandas/core/arrays/categorical.py

+2-18
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ def remove_unused_categories(self) -> Self:
14831483
def map(
14841484
self,
14851485
mapper,
1486-
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
1486+
na_action: Literal["ignore"] | None = None,
14871487
):
14881488
"""
14891489
Map categories using an input mapping or function.
@@ -1501,15 +1501,10 @@ def map(
15011501
----------
15021502
mapper : function, dict, or Series
15031503
Mapping correspondence.
1504-
na_action : {None, 'ignore'}, default 'ignore'
1504+
na_action : {None, 'ignore'}, default None
15051505
If 'ignore', propagate NaN values, without passing them to the
15061506
mapping correspondence.
15071507
1508-
.. deprecated:: 2.1.0
1509-
1510-
The default value of 'ignore' has been deprecated and will be changed to
1511-
None in the future.
1512-
15131508
Returns
15141509
-------
15151510
pandas.Categorical or pandas.Index
@@ -1561,17 +1556,6 @@ def map(
15611556
>>> cat.map({"a": "first", "b": "second"}, na_action=None)
15621557
Index(['first', 'second', nan], dtype='object')
15631558
"""
1564-
if na_action is lib.no_default:
1565-
warnings.warn(
1566-
"The default value of 'ignore' for the `na_action` parameter in "
1567-
"pandas.Categorical.map is deprecated and will be "
1568-
"changed to 'None' in a future version. Please set na_action to the "
1569-
"desired value to avoid seeing this warning",
1570-
FutureWarning,
1571-
stacklevel=find_stack_level(),
1572-
)
1573-
na_action = "ignore"
1574-
15751559
assert callable(mapper) or is_dict_like(mapper)
15761560

15771561
new_categories = self.categories.map(mapper)

pandas/core/arrays/datetimelike.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ def _unbox(self, other) -> np.int64 | np.datetime64 | np.timedelta64 | np.ndarra
728728
# pandas assumes they're there.
729729

730730
@ravel_compat
731-
def map(self, mapper, na_action=None):
731+
def map(self, mapper, na_action: Literal["ignore"] | None = None):
732732
from pandas import Index
733733

734734
result = map_array(self, mapper, na_action=na_action)

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ def max(self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs):
13181318
)
13191319
return self._wrap_reduction_result("max", result, skipna=skipna, axis=axis)
13201320

1321-
def map(self, mapper, na_action=None):
1321+
def map(self, mapper, na_action: Literal["ignore"] | None = None):
13221322
return map_array(self.to_numpy(), mapper, na_action=na_action)
13231323

13241324
@overload

pandas/core/arrays/sparse/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
12531253

12541254
return self._simple_new(sp_values, self.sp_index, dtype)
12551255

1256-
def map(self, mapper, na_action=None) -> Self:
1256+
def map(self, mapper, na_action: Literal["ignore"] | None = None) -> Self:
12571257
"""
12581258
Map categories using an input mapping or function.
12591259

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10369,7 +10369,7 @@ def apply(
1036910369
return op.apply().__finalize__(self, method="apply")
1037010370

1037110371
def map(
10372-
self, func: PythonFuncType, na_action: str | None = None, **kwargs
10372+
self, func: PythonFuncType, na_action: Literal["ignore"] | None = None, **kwargs
1037310373
) -> DataFrame:
1037410374
"""
1037510375
Apply a function to a Dataframe elementwise.

pandas/tests/arrays/categorical/test_map.py

-13
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,3 @@ def test_map_with_dict_or_series(na_action):
134134
result = cat.map(mapper, na_action=na_action)
135135
# Order of categories in result can be different
136136
tm.assert_categorical_equal(result, expected)
137-
138-
139-
def test_map_na_action_no_default_deprecated():
140-
# GH51645
141-
cat = Categorical(["a", "b", "c"])
142-
msg = (
143-
"The default value of 'ignore' for the `na_action` parameter in "
144-
"pandas.Categorical.map is deprecated and will be "
145-
"changed to 'None' in a future version. Please set na_action to the "
146-
"desired value to avoid seeing this warning"
147-
)
148-
with tm.assert_produces_warning(FutureWarning, match=msg):
149-
cat.map(lambda x: x)

0 commit comments

Comments
 (0)