Code Sample
>>> import pandas as pd
>>> pd.Series(list("cabaa")).map(print)
c
a
b
a
a
0 None
1 None
2 None
3 None
4 None
dtype: object
>>> pd.Series(list("cabaa"), dtype = "category").map(print)
a
b
c
/usr/local/lib/python3.6/site-packages/pandas/core/categorical.py:952: FutureWarning:
Setting NaNs in `categories` is deprecated and will be removed in a future version of pandas.
ordered=self.ordered)
0 None
1 None
2 None
3 None
4 None
dtype: object
Problem description
Either Categorical Series should act the same as other Series, or this special behavior for Categoricals should be mentioned in the documentation for Series.map
.
A limitation of the current behavior for Categoricals is that the function is never called for any nulls (codes equal to -1).
Output of pd.show_versions()
Comment From: jreback
this is the point of a categorical. by-definition you have uniques which you can act on.
I suppose you could add some more documentation (or an example).
Comment From: topper-123
It's like mentioned by @jreback: Categorical.map
is designed to work on the categories, so will not necessarily work on each value in the array. This is mentioned in the doc string "Maps the categories to new categories.", but could maybe be written clearer.
So IMO everything works as intended and this issue can be.closed.