API: Rename arg to func in Series.map for consistency · Issue #61260 · pandas-dev/pandas (original) (raw)
The API of methods taking udf follow certain patterns that make them consistent and easier to learn and use. There are some small differences, which have been listed in #40112 and #61128.
This issue is to rename the arg
parameter of Series.map
to func
, which is the name consistently used in almost all methods. In the case of Series.map
, the argument is slightly different than others, given that arg
or func
can also be a dict
or a Series
, which will make map
replace values from these mappings, instead of executing an elementwise udf.
This issue is for the renaming of the parameter, making the parameter consistent with other methods such as DataFrame.apply
can be considered in another issue. But there are some cases to consider, given that the behavior of map
is slightly different when providing a mapping, than when providing a function that maps. In particular, map
will use NaN
when the mapping returns None
, but it will use None
when the function returns None
. Also, if we stop supporting dictionaries, users in general should just replace their code from Series.map(my_dict)
to Series.map(my_dict.get)
. But there are some special cases, for example when the dictionary is a defaultdict
, .get
will return None
, while the current map
implementation with a defaultdict
will consider the default value.