Skip to content

BUG: Series.map(dict) doesn't work when dict keys are tuples of length 1? #7333

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

Closed
onesandzeroes opened this issue Jun 4, 2014 · 2 comments · Fixed by #7336
Closed

BUG: Series.map(dict) doesn't work when dict keys are tuples of length 1? #7333

onesandzeroes opened this issue Jun 4, 2014 · 2 comments · Fixed by #7336
Labels
Milestone

Comments

@onesandzeroes
Copy link
Contributor

I ran across an odd issue today where some analysis code that was working pre-pandas 0.14.0 started failing. The issue seems to be specific to trying to use Series.map(some_dict) when the dict keys (and values in the series) are single item tuples. Code to demonstrate the issue:

import pandas as pd
pd.version.version
Out[10]: '0.14.0'

df = pd.DataFrame({'a': [(1,), (2,), (3, 4), (5, 6)]})
label_mappings = {
    (1,): 'A',
    (2,): 'B',
    (3, 4): 'A',
    (5, 6): 'B'
}
df['labels'] = df['a'].map(label_mappings)
df
Out[7]: 
        a labels
0    (1,)    NaN
1    (2,)    NaN
2  (3, 4)      A
3  (5, 6)      B

The expected output here is:

df
Out[7]: 
        a labels
0    (1,)      A
1    (2,)      B
2  (3, 4)      A
3  (5, 6)      B
@jreback jreback added the Bug label Jun 4, 2014
@jreback jreback added this to the 0.14.1 milestone Jun 4, 2014
@jreback
Copy link
Contributor

jreback commented Jun 4, 2014

ok...want to take a stab at fixing?

@onesandzeroes
Copy link
Contributor Author

@jreback OK, it seems like this one might be a fairly simple fix, so I've got a pull request going now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants