ENH: Add kwargs to Series.map
#59814
Labels
API - Consistency
Internal Consistency of API/Behavior
Apply
Apply, Aggregate, Transform, Map
Enhancement
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 bypandas.Series.map
. It would be more consistent and useful if bothmap
functions had the same signatureFeature Description
The signature of
Series.map
would be 'Series.map(func, na_action=None, **kwargs)' rather thanSeries.map(arg, na_action=None)
with the additionalkwargs
provided to thefunc
at the point when mapping is performedAlternative Solutions
Users can replace their function
func
withfunctools.partial(func, **kwargs)
to achieve the same functionality - this is whatDataFrame.map
seems to use internally.Additional Context
Presumably the difference is because
Series.map()
supports functions, dicts, or Series instances, whereasDataFrame.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 bothmap
functions had the same feature set, one way or anotherThe text was updated successfully, but these errors were encountered: