-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
API: Replace na_action parameter in Series/DataFrame/Index.map by the standard skipna #61530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
cd57c9d
77efdfd
4e089d5
d197e29
0474001
142a916
f8a069a
aaf91f7
e0b54be
26acdca
ba424a8
0488502
2752059
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -402,14 +402,6 @@ def nselect_method(request): | |
return request.param | ||
|
||
|
||
@pytest.fixture(params=[None, "ignore"]) | ||
def na_action(request): | ||
""" | ||
Fixture for 'na_action' argument in map. | ||
""" | ||
return request.param | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
@pytest.fixture(params=[True, False]) | ||
def ascending(request): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2541,17 +2541,17 @@ def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs): | |
|
||
return arraylike.default_array_ufunc(self, ufunc, method, *inputs, **kwargs) | ||
|
||
def map(self, mapper, na_action: Literal["ignore"] | None = None): | ||
def map(self, mapper, skipna: bool = False): | ||
|
||
""" | ||
Map values using an input mapping or function. | ||
|
||
Parameters | ||
---------- | ||
mapper : function, dict, or Series | ||
Mapping correspondence. | ||
na_action : {None, 'ignore'}, default None | ||
If 'ignore', propagate NA values, without passing them to the | ||
mapping correspondence. If 'ignore' is not supported, a | ||
skipna : bool, default False | ||
If ``True``, propagate NA values, without passing them to the | ||
mapping correspondence. If ``True`` is not supported, a | ||
``NotImplementedError`` should be raised. | ||
|
||
Returns | ||
|
@@ -2561,7 +2561,7 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None): | |
If the function returns a tuple with more than one element | ||
a MultiIndex will be returned. | ||
""" | ||
return map_array(self, mapper, na_action=na_action) | ||
return map_array(self, mapper, skipna=skipna) | ||
|
||
# ------------------------------------------------------------------------ | ||
# GroupBy Methods | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10641,7 +10641,11 @@ def apply( | |
raise ValueError(f"Unknown engine {engine}") | ||
|
||
def map( | ||
self, func: PythonFuncType, na_action: Literal["ignore"] | None = None, **kwargs | ||
self, | ||
func: PythonFuncType, | ||
skipna: bool = False, | ||
na_action: Literal["ignore"] | None | lib.NoDefault = lib.no_default, | ||
|
||
**kwargs, | ||
) -> DataFrame: | ||
""" | ||
Apply a function to a Dataframe elementwise. | ||
|
@@ -10657,6 +10661,8 @@ def map( | |
---------- | ||
func : callable | ||
Python function, returns a single value from a single value. | ||
skipna : bool = False | ||
If ``True``, propagate missing values without passing them to ``func``. | ||
na_action : {None, 'ignore'}, default None | ||
If 'ignore', propagate NaN values, without passing them to func. | ||
**kwargs | ||
|
@@ -10691,7 +10697,7 @@ def map( | |
|
||
>>> df_copy = df.copy() | ||
>>> df_copy.iloc[0, 0] = pd.NA | ||
>>> df_copy.map(lambda x: len(str(x)), na_action="ignore") | ||
>>> df_copy.map(lambda x: len(str(x)), skipna=True) | ||
0 1 | ||
0 NaN 4 | ||
1 5.0 5 | ||
|
@@ -10719,16 +10725,28 @@ def map( | |
0 1.000000 4.494400 | ||
1 11.262736 20.857489 | ||
""" | ||
if na_action not in {"ignore", None}: | ||
raise ValueError(f"na_action must be 'ignore' or None. Got {na_action!r}") | ||
if na_action != lib.no_default: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case it's not obvious, I'm using |
||
warnings.warn( | ||
"The ``na_action`` parameter has been deprecated and it will be " | ||
"removed in a future version of pandas. Use ``skipna`` instead.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
if na_action == "ignore": | ||
skipna = True | ||
elif na_action not in (None, "ignore"): | ||
raise ValueError( | ||
"na_action must either be 'ignore' or None, " | ||
f"{na_action!r} was passed" | ||
) | ||
|
||
if self.empty: | ||
return self.copy() | ||
|
||
func = functools.partial(func, **kwargs) | ||
|
||
def infer(x): | ||
return x._map_values(func, na_action=na_action) | ||
return x._map_values(func, skipna=skipna) | ||
|
||
return self.apply(infer).__finalize__(self, "map") | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.