Skip to content

Conversation

topper-123
Copy link
Contributor

@topper-123 topper-123 commented Mar 21, 2020

Makes MultiIndex.copy call MultiIndex._shallow_copy rather than the other way around. This is cleaner and let's us copy the existing .cache, so may give performance boost when operating on copied MultiIndexes:

>>> n = 100_000
>>> df = pd.DataFrame({'a': range(n), 'b': range(1, n+1)})
>>> mi = pd.MultiIndex.from_frame(df)
>>> mi.get_loc(mi[0])  # also sets up the cache
>>> %timeit mi.copy().get_loc(mi[0])
8.57 ms ± 157 µs per loop  # master
57.9 µs ± 798 ns per loop  # this PR

Also cleans kwargs from the MultiIndex._shallow_copy signature. This PR is somewhat related to #32669.

@topper-123 topper-123 force-pushed the ref_MultiIndex.copy branch from dc01af3 to 34bb781 Compare March 21, 2020 13:36
@topper-123 topper-123 force-pushed the ref_MultiIndex.copy branch from 34bb781 to 9a396cf Compare March 21, 2020 13:40
@jreback jreback added MultiIndex Performance Memory or execution speed performance labels Mar 21, 2020
@jreback jreback added this to the 1.1 milestone Mar 21, 2020
@jreback jreback merged commit 2784006 into pandas-dev:master Mar 21, 2020
@jreback
Copy link
Contributor

jreback commented Mar 21, 2020

thanks.

@topper-123 topper-123 deleted the ref_MultiIndex.copy branch March 21, 2020 20:49
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MultiIndex Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants