-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: Rename arg
to func
in Series.map
#61264
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
Changes from 2 commits
cf6d36b
adb0982
c5d44f6
fed4ace
1d758e6
092e9c0
e12c726
0796d9f
5f270b3
843668e
cbe2c68
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 |
---|---|---|
|
@@ -52,6 +52,9 @@ | |
doc, | ||
set_module, | ||
) | ||
from pandas.util._exceptions import ( | ||
find_stack_level, | ||
) | ||
from pandas.util._validators import ( | ||
validate_ascending, | ||
validate_bool_kwarg, | ||
|
@@ -4320,7 +4323,7 @@ def unstack( | |
|
||
def map( | ||
self, | ||
arg: Callable | Mapping | Series, | ||
func: Callable | Mapping | Series | None = None, | ||
na_action: Literal["ignore"] | None = None, | ||
**kwargs, | ||
) -> Series: | ||
|
@@ -4333,8 +4336,8 @@ def map( | |
|
||
Parameters | ||
---------- | ||
arg : function, collections.abc.Mapping subclass or Series | ||
Mapping correspondence. | ||
func : function, collections.abc.Mapping subclass or Series | ||
Function or mapping correspondence. | ||
na_action : {None, 'ignore'}, default None | ||
If 'ignore', propagate NaN values, without passing them to the | ||
mapping correspondence. | ||
|
@@ -4404,9 +4407,22 @@ def map( | |
3 I am a rabbit | ||
dtype: object | ||
""" | ||
if callable(arg): | ||
arg = functools.partial(arg, **kwargs) | ||
new_values = self._map_values(arg, na_action=na_action) | ||
if func is None: | ||
if "arg" in kwargs: | ||
Comment on lines
+4410
to
+4411
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. Noting this won't be backwards compatible with the use 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. You are totally right. In my first implementation I was raising an exception, and then thought it would be better to allow using But as you, I think is better to just let that unlikely case break compatibility. |
||
# `.map(arg=my_func)` | ||
func = kwargs.pop("arg") | ||
warnings.warn( | ||
"The parameter `arg` has been renamed to `func`, and it " | ||
"will stop being supported in a future version of pandas.", | ||
FutureWarning, | ||
stacklevel=find_stack_level(), | ||
) | ||
else: | ||
raise ValueError("The `func` parameter is required") | ||
|
||
if callable(func): | ||
func = functools.partial(func, **kwargs) | ||
new_values = self._map_values(func, na_action=na_action) | ||
return self._constructor(new_values, index=self.index, copy=False).__finalize__( | ||
self, method="map" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in deprecations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it there. Since it's renaming a parameter both deprecations and API changed made sense, but I have no preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - the way I read API changes is "things I need to change to not have my code break when upgrading". As this is a deprecation, users don't need to do that just yet.