Skip to content
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

PERF: series.map(arg) for category is slow if arg is a dict #23785

Closed
colinfang opened this issue Nov 19, 2018 · 2 comments · Fixed by #26015
Closed

PERF: series.map(arg) for category is slow if arg is a dict #23785

colinfang opened this issue Nov 19, 2018 · 2 comments · Fixed by #26015
Labels
Categorical Categorical Data Type Performance Memory or execution speed performance Usage Question
Milestone

Comments

@colinfang
Copy link

colinfang commented Nov 19, 2018

Are the following 2 methods equivalent? I have to introduce a lambda to gain additional performance when dealing with map of category.

import pandas as pd
x = pd.Series(list('abcd') * 1000).astype('category')
mapper = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
%timeit x.map(mapper)
# 1000 loops, best of 3: 1.11 ms per loop
%timeit x.map(lambda a: mapper[a])
# 1000 loops, best of 3: 291 µs per loop
@gfyoung gfyoung added Performance Memory or execution speed performance Usage Question Categorical Categorical Data Type labels Nov 21, 2018
@gfyoung
Copy link
Member

gfyoung commented Nov 21, 2018

Interesting. x.map(mapper) and x.map(lambda a: mapper[a]) produce different results, likely because one recognizes the categorical nature and the other doesn't.

Not sure which result is correct though...

cc @jreback

@rtlee9
Copy link
Contributor

rtlee9 commented Apr 6, 2019

Good guess @gfyoung. It looks like x.map(mapper) ignores the categorical nature and reindexes all values as opposed to just mapping the categories (see #26015 )

@jreback jreback added this to the 0.25.0 milestone Apr 7, 2019
@jreback jreback changed the title series.map(arg) for category is slow if arg is a dict PERF: series.map(arg) for category is slow if arg is a dict Apr 7, 2019
@jreback jreback modified the milestones: 0.25.0, Contributions Welcome Apr 20, 2019
@jreback jreback modified the milestones: Contributions Welcome, 0.25.0 Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Performance Memory or execution speed performance Usage Question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants