-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
pd.Series.map never maps NAs through a dictionary #17648
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
Comments
e.g.
|
In my case, I have some series I got out of a Stata dataset that I'm turning into Categoricals based on a codebook. What appears as an NA in the original series is often given a descriptive label by the codebook, analogously to the non-missing values. And I want to preserve the order of categories and the presence of categories with no corresponding values. So I wrote
But |
@Kodiologist ok, so pls submit a PR for the docs issue. always best from a user perspective. I'll mark this as a bug in any event, its a bit tricky though. welcome to have a look. |
xref #14210 |
Looks to work on master. Could use a test.
|
Code Sample
This prints:
Problem description
The parameter
na_action
ofpd.Series.map
is ignored if the first argument ofmap
is a dictionary. Rather than mapping NAs ifna_action
isNone
and passing them through unaltered if it's"ignore"
, pandas always passes NAs through unaltered, as ifna_action
were"ignore"
. (The default isNone
.)Expected Output
Output of
pd.show_versions()
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.10.0-33-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.20.3
pytest: 3.0.7
pip: 9.0.1
setuptools: 36.0.1
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: None
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: None
sqlalchemy: 1.1.9
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: