You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
my return type is of int64 and everything is mapped.
However for this:
Series(['a', 'b ']).map({'a': 1, 'b': 3}) # note space
my return type is floatX and there is a nan. Instead this is a "mistake" and I would have preferred an exception to be raised.
I could assert that the type is int (brittle and just works for ints) or perhaps check all of the unique values in advance to make sure they are a subset of the mapping arg keys (require another pass over data).
I'd be in favor of adding a 'raise' option when there's a value in the series that doesn't get mapped.
Does anyone know what the na_action parameter actually does? The docs aren't that clear and I can't figure it out with simple testing. Is this controlling NA values in the original series, or the output? Ideally we'd use the errors={'ignore', 'raise'} keyword we're using elsewhere, and deprecate na_action (if it's doing what I think it is).
Hi all,
I find myself with the same need as @cancan101 some years ago: optionally raise an error when a value does not get mapped. It does not look like this has been implemented yet. Are there any plans?
Irene
Activity
jreback commentedon Sep 13, 2016
I am not sure what the intent / meaning of this parameter. @cancan101 can you give an example?
cancan101 commentedon Sep 13, 2016
If I were do this:
my return type is of
int64
and everything is mapped.However for this:
my return type is
floatX
and there is a nan. Instead this is a "mistake" and I would have preferred an exception to be raised.I could assert that the type is int (brittle and just works for ints) or perhaps check all of the unique values in advance to make sure they are a subset of the mapping
arg
keys (require another pass over data).TomAugspurger commentedon Sep 13, 2016
Related (but different from) #13473
I'd be in favor of adding a
'raise'
option when there's a value in the series that doesn't get mapped.Does anyone know what the
na_action
parameter actually does? The docs aren't that clear and I can't figure it out with simple testing. Is this controlling NA values in the original series, or the output? Ideally we'd use theerrors={'ignore', 'raise'}
keyword we're using elsewhere, and deprecatena_action
(if it's doing what I think it is).cancan101 commentedon Sep 13, 2016
@TomAugspurger Funny you should ask: http://stackoverflow.com/questions/39461328/in-pandas-what-does-the-na-action-parameter-to-series-map-do/39461948#39461948
na_action=ignore
result is misleading. #47262bollard commentedon Dec 5, 2022
Quite the 6-year necroraise, but little bump that would be really useful to have an
na_action="raise"
onSeries.map
A workaround for the moment is to (re)define
__missing__
to raise, i.e.IPerezGonzalez commentedon Feb 16, 2023
Hi all,
I find myself with the same need as @cancan101 some years ago: optionally raise an error when a value does not get mapped. It does not look like this has been implemented yet. Are there any plans?
Irene
johnh2o2 commentedon Aug 21, 2024
bump to this! would love a raise na_option
s.map(d, na_action='raise')
#60482kopytjuk commentedon Mar 7, 2025
Hey guys, I prepared a PR in #60482, please review if the functionality and docs are understandable!