Skip to content
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

ENH: Add kwargs to Series.map #59814

Open
1 of 3 tasks
RomeshA opened this issue Sep 16, 2024 · 3 comments · May be fixed by #59843
Open
1 of 3 tasks

ENH: Add kwargs to Series.map #59814

RomeshA opened this issue Sep 16, 2024 · 3 comments · May be fixed by #59843
Assignees
Labels
API - Consistency Internal Consistency of API/Behavior Apply Apply, Aggregate, Transform, Map Enhancement

Comments

@RomeshA
Copy link

RomeshA commented Sep 16, 2024

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

In version 2.2, pandas.DataFrame.map supports passing additional arguments to functions used when mapping values. However, this functionality is not provided by pandas.Series.map. It would be more consistent and useful if both map functions had the same signature

Feature Description

The signature of Series.map would be 'Series.map(func, na_action=None, **kwargs)' rather than Series.map(arg, na_action=None) with the additional kwargs provided to the func at the point when mapping is performed

Alternative Solutions

Users can replace their function func with functools.partial(func, **kwargs) to achieve the same functionality - this is what DataFrame.map seems to use internally.

Additional Context

Presumably the difference is because Series.map() supports functions, dicts, or Series instances, whereas DataFrame.map() only supports functions? Since their use cases are so similar and they even share a name, it would probably be easiest for both users if both map functions had the same feature set, one way or another

@RomeshA RomeshA added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 16, 2024
@rhshadrach
Copy link
Member

Thanks for the request. Agreed we should be consistent here by adding kwargs to Series.map.

@rhshadrach rhshadrach added Apply Apply, Aggregate, Transform, Map API - Consistency Internal Consistency of API/Behavior and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 18, 2024
@sfc-gh-nkumar
Copy link

take

@nemausus nemausus linked a pull request Sep 19, 2024 that will close this issue
5 tasks
@yuanx749
Copy link
Contributor

Series.apply has kwargs. Just curious, is there a performance difference between Series.apply and Series.map?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Apply Apply, Aggregate, Transform, Map Enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants