ENH: Add kwargs to Series.map (original) (raw)
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