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

Comments

@colinfang
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Contributor

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

jreback added a commit that referenced this issue May 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.