-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series.map
is ignoring the na_action
keyword
#46588
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
take |
@shortorian |
@shortorian |
Thanks @shortorian for the report.
The allowed values are in the api documentation but not adverse to adding some run-time validation. Note that from the documentation
we would perhaps expect this to work with at least the So IMO I think perhaps the documentation could also be updated to explain that the |
That's interesting, I would never have interpreted the documentation that way ("mapping correspondence" seemed to specifically indicate something more expansive than a function to me). I ran into this because I expected to be able to use
I wanted output
I realize now that I misunderstood what was going on - I would definitely appreciate a rewrite on the documentation indicating this is only applicable for callable |
agreed, but looking some more it appears that the docstring for the lower level function
and the code there does not handle Interestingly, there is some validation in there too,
so does make sense to also have the run-time validation for the dict-like (and Series) case as you suggested in the OP. |
take |
Hey everyone, if it's OK, I'm planning to update _map_values to check if na_action is in [None, 'ignore'] for Series and dict too. As na_action is not handled for Series and dict, I will also update the docstring to mention this. I'm a first-time contributor haha. |
I added a check for na_action in (None, 'ignore'). I didn't update the docstring because Series.map is working as expected with na_action='ignore'. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
This code should throw an error because
na_action
is invalid, but instead I've gotten a Jupyter notebook, ipython in Powershell, and an online interpreter to generate the following outputI get the same output for
na_action='ignore'
andna_action=None
Expected Behavior
ValueError: na_action must either be 'ignore' or None, True was passed
Installed Versions
pandas : 1.4.1
numpy : 1.22.3
pytz : 2021.3
dateutil : 2.8.2
pip : 22.0.4
setuptools : 58.1.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 7.30.1
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.4.28
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: