question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option to Raise Exception on Unmapped Value in Series.map

See original GitHub issue

Add a flag (or extend na_action) to raise an exception in Series.map if a value is not successfully mapped (ie in the case where arg is a dict.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cancan101commented, Sep 13, 2016

If I were do this:

Series(['a', 'b']).map({'a': 1, 'b': 3})

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).

0reactions
bollardcommented, Dec 5, 2022

Quite the 6-year necroraise, but little bump that would be really useful to have an na_action="raise" on Series.map

A workaround for the moment is to (re)define __missing__ to raise, i.e.

class WillRaise(dict):
    def __missing__(self, key):
        raise KeyError(key)

mapping = WillRaise({"Foo": 1})
pd.Series(["Foo", "Bar"]).map(mapping) # KeyError: 'Bar'
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring Unmapped Properties with MapStruct - Baeldung
In order to ignore unmapped properties and get no output warnings, we should assign the IGNORE value to the unmappedTargetPolicy. There are ...
Read more >
Jackson exception handling - How to get all unmapped fields
You should rely on validation to respond to such case. First, add the dependency (I assume you use spring boot)
Read more >
pandas.Series.map — pandas 1.5.2 documentation
Map values of Series according to an input mapping or function. Used for substituting each value in a Series with another value, that...
Read more >
Sequence Alignment/Map Format Specification - Samtools
SAM stands for Sequence Alignment/Map format. It is a TAB-delimited text format consisting of a header section, which is optional, ...
Read more >
MapStruct 1.5.3.Final Reference Guide
Supported values are: ERROR : any unmapped source property will cause the mapping code generation to fail. WARN : any unmapped ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found