PERF: MultiIndex.equals for equal length indexes by lukemanley · Pull Request #56990 · pandas-dev/pandas (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation3 Commits3 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
- Tests added and passed if fixing a bug or adding a new feature
- All code checks passed.
- Added type annotations to new arguments/methods/functions.
- Added an entry in the latest
doc/source/whatsnew/v2.3.0.rst
file if fixing a bug or adding a new feature.
Avoids densifying the levels of the multiindex to check for equality.
from asv_bench.benchmarks.multiindex_object import Equals
b = Equals()
b.setup()
%timeit b.time_equals_deepcopy()
# 56.4 ms ± 1.03 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) -> main
# 3.77 ms ± 58.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) -> PR
lukemanley changed the title
PERF: MultiIndex.equals PERF: MultiIndex.equals for equal length indexes
) |
---|
if not np.array_equal(self_codes, new_codes): |
return False |
if not self_level[:0].equals(other_level[:0]): |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just use is_dtype_equal
?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The equality rules for numpy dtypes are not as strict as is_dtype_equal
:
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: idx = pd.Index([1])
In [4]: idx.astype("int64").equals(idx.astype("int32"))
Out[4]: True
In [5]: pd.core.dtypes.common.is_dtype_equal(np.int64, np.int32)
Out[5]: False
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request
avoid densifying level values in MultiIndex.equals
whatsnew
2 participants