Skip to content

Commit 2752059

Browse files
Add deprecation to all subclasses of map for signature consistency
1 parent 0488502 commit 2752059

File tree

5 files changed

+73
-8
lines changed

5 files changed

+73
-8
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,11 +1477,18 @@ def to_numpy(
14771477
result[~mask] = data[~mask]._pa_array.to_numpy()
14781478
return result
14791479

1480-
def map(self, mapper, skipna: bool = False):
1480+
def map(
1481+
self,
1482+
mapper,
1483+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
1484+
skipna: bool = False,
1485+
):
14811486
if is_numeric_dtype(self.dtype):
1482-
return map_array(self.to_numpy(), mapper, skipna=skipna)
1487+
return map_array(
1488+
self.to_numpy(), mapper, na_action=na_action, skipna=skipna
1489+
)
14831490
else:
1484-
return super().map(mapper, skipna=skipna)
1491+
return super().map(mapper, na_action=na_action, skipna=skipna)
14851492

14861493
@doc(ExtensionArray.duplicated)
14871494
def duplicated(

pandas/core/arrays/categorical.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
cast,
1111
overload,
1212
)
13+
import warnings
1314

1415
import numpy as np
1516

@@ -22,6 +23,7 @@
2223
)
2324
from pandas._libs.arrays import NDArrayBacked
2425
from pandas.compat.numpy import function as nv
26+
from pandas.util._exceptions import find_stack_level
2527
from pandas.util._validators import validate_bool_kwarg
2628

2729
from pandas.core.dtypes.cast import (
@@ -1497,6 +1499,7 @@ def remove_unused_categories(self) -> Self:
14971499
def map(
14981500
self,
14991501
mapper,
1502+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
15001503
skipna: bool = False,
15011504
):
15021505
"""
@@ -1515,6 +1518,11 @@ def map(
15151518
----------
15161519
mapper : function, dict, or Series
15171520
Mapping correspondence.
1521+
na_action : {None, 'ignore'}, default None
1522+
If 'ignore', propagate NaN values, without passing them to func.
1523+
1524+
.. deprecated:: 3.0.0
1525+
Use ``skipna`` instead.
15181526
skipna : bool, default False
15191527
If ``True``, propagate NA values, without passing them to the
15201528
mapping correspondence.
@@ -1572,6 +1580,21 @@ def map(
15721580
"""
15731581
assert callable(mapper) or is_dict_like(mapper)
15741582

1583+
if na_action != lib.no_default:
1584+
warnings.warn(
1585+
"The ``na_action`` parameter has been deprecated and it will be "
1586+
"removed in a future version of pandas. Use ``skipna`` instead.",
1587+
FutureWarning,
1588+
stacklevel=find_stack_level(),
1589+
)
1590+
if na_action == "ignore":
1591+
skipna = True
1592+
elif na_action not in (None, "ignore"):
1593+
raise ValueError(
1594+
"na_action must either be 'ignore' or None, "
1595+
f"{na_action!r} was passed"
1596+
)
1597+
15751598
new_categories = self.categories.map(mapper)
15761599

15771600
has_nans = np.any(self._codes == -1)

pandas/core/arrays/datetimelike.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,15 @@ def _unbox(self, other) -> np.int64 | np.datetime64 | np.timedelta64 | np.ndarra
743743
# pandas assumes they're there.
744744

745745
@ravel_compat
746-
def map(self, mapper, skipna: bool = False):
746+
def map(
747+
self,
748+
mapper,
749+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
750+
skipna: bool = False,
751+
):
747752
from pandas import Index
748753

749-
result = map_array(self, mapper, skipna=skipna)
754+
result = map_array(self, mapper, na_action=na_action, skipna=skipna)
750755
result = Index(result)
751756

752757
if isinstance(result, ABCMultiIndex):

pandas/core/arrays/masked.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,13 @@ def max(self, *, skipna: bool = True, axis: AxisInt | None = 0, **kwargs):
13241324
)
13251325
return self._wrap_reduction_result("max", result, skipna=skipna, axis=axis)
13261326

1327-
def map(self, mapper, skipna: bool = False):
1328-
return map_array(self.to_numpy(), mapper, skipna=skipna)
1327+
def map(
1328+
self,
1329+
mapper,
1330+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
1331+
skipna: bool = False,
1332+
):
1333+
return map_array(self.to_numpy(), mapper, na_action=na_action, skipna=skipna)
13291334

13301335
@overload
13311336
def any(

pandas/core/arrays/sparse/array.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,14 +1309,24 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
13091309

13101310
return self._simple_new(sp_values, self.sp_index, dtype)
13111311

1312-
def map(self, mapper, skipna: bool = False) -> Self:
1312+
def map(
1313+
self,
1314+
mapper,
1315+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
1316+
skipna: bool = False,
1317+
) -> Self:
13131318
"""
13141319
Map categories using an input mapping or function.
13151320
13161321
Parameters
13171322
----------
13181323
mapper : dict, Series, callable
13191324
The correspondence from old values to new.
1325+
na_action : {None, 'ignore'}, default None
1326+
If 'ignore', propagate NaN values, without passing them to func.
1327+
1328+
.. deprecated:: 3.0.0
1329+
Use ``skipna`` instead.
13201330
skipna : bool, default False
13211331
If ``True``, propagate NA values, without passing them to the
13221332
mapping correspondence.
@@ -1349,6 +1359,21 @@ def map(self, mapper, skipna: bool = False) -> Self:
13491359
IntIndex
13501360
Indices: array([1, 2], dtype=int32)
13511361
"""
1362+
if na_action != lib.no_default:
1363+
warnings.warn(
1364+
"The ``na_action`` parameter has been deprecated and it will be "
1365+
"removed in a future version of pandas. Use ``skipna`` instead.",
1366+
FutureWarning,
1367+
stacklevel=find_stack_level(),
1368+
)
1369+
if na_action == "ignore":
1370+
skipna = True
1371+
elif na_action not in (None, "ignore"):
1372+
raise ValueError(
1373+
"na_action must either be 'ignore' or None, "
1374+
f"{na_action!r} was passed"
1375+
)
1376+
13521377
is_map = isinstance(mapper, (abc.Mapping, ABCSeries))
13531378

13541379
fill_val = self.fill_value

0 commit comments

Comments
 (0)