Skip to content

Commit 26acdca

Browse files
Deprecate na_action in base.map and map_arrary to not break third-party packages
1 parent e0b54be commit 26acdca

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

pandas/core/algorithms.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,10 @@ def union_with_duplicates(
16291629

16301630

16311631
def map_array(
1632-
arr: ArrayLike, mapper, skipna: bool = False
1632+
arr: ArrayLike,
1633+
mapper,
1634+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
1635+
skipna: bool = False,
16331636
) -> np.ndarray | ExtensionArray | Index:
16341637
"""
16351638
Map values using an input mapping or function.
@@ -1638,6 +1641,11 @@ def map_array(
16381641
----------
16391642
mapper : function, dict, or Series
16401643
Mapping correspondence.
1644+
na_action : {None, 'ignore'}, default None
1645+
If 'ignore', propagate NaN values, without passing them to func.
1646+
1647+
.. deprecated:: 3.0.0
1648+
Use ``skipna`` instead.
16411649
skipna : bool, default False
16421650
If ``True``, propagate NA values, without passing them to the
16431651
mapping correspondence.
@@ -1651,6 +1659,20 @@ def map_array(
16511659
"""
16521660
from pandas import Index
16531661

1662+
if na_action != lib.no_default:
1663+
warnings.warn(
1664+
"The ``na_action`` parameter has been deprecated and it will be "
1665+
"removed in a future version of pandas. Use ``skipna`` instead.",
1666+
FutureWarning,
1667+
stacklevel=find_stack_level(),
1668+
)
1669+
if na_action == "ignore":
1670+
skipna = True
1671+
elif na_action not in (None, "ignore"):
1672+
raise ValueError(
1673+
f"na_action must either be 'ignore' or None, {na_action!r} was passed"
1674+
)
1675+
16541676
# we can fastpath dict/Series to an efficient map
16551677
# as we know that we are not going to have to yield
16561678
# python types

pandas/core/arrays/base.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2541,14 +2541,24 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
25412541

25422542
return arraylike.default_array_ufunc(self, ufunc, method, *inputs, **kwargs)
25432543

2544-
def map(self, mapper, skipna: bool = False):
2544+
def map(
2545+
self,
2546+
mapper,
2547+
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default,
2548+
skipna: bool = False,
2549+
):
25452550
"""
25462551
Map values using an input mapping or function.
25472552
25482553
Parameters
25492554
----------
25502555
mapper : function, dict, or Series
25512556
Mapping correspondence.
2557+
na_action : {None, 'ignore'}, default None
2558+
If 'ignore', propagate NaN values, without passing them to func.
2559+
2560+
.. deprecated:: 3.0.0
2561+
Use ``skipna`` instead.
25522562
skipna : bool, default False
25532563
If ``True``, propagate NA values, without passing them to the
25542564
mapping correspondence. If ``True`` is not supported, a
@@ -2561,6 +2571,20 @@ def map(self, mapper, skipna: bool = False):
25612571
If the function returns a tuple with more than one element
25622572
a MultiIndex will be returned.
25632573
"""
2574+
if na_action != lib.no_default:
2575+
warnings.warn(
2576+
"The ``na_action`` parameter has been deprecated and it will be "
2577+
"removed in a future version of pandas. Use ``skipna`` instead.",
2578+
FutureWarning,
2579+
stacklevel=find_stack_level(),
2580+
)
2581+
if na_action == "ignore":
2582+
skipna = True
2583+
elif na_action not in (None, "ignore"):
2584+
raise ValueError(
2585+
"na_action must either be 'ignore' or None, "
2586+
f"{na_action!r} was passed"
2587+
)
25642588
return map_array(self, mapper, skipna=skipna)
25652589

25662590
# ------------------------------------------------------------------------

0 commit comments

Comments
 (0)