-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
PERF: assert_frame_equal / assert_series_equal #55971
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
Conversation
pandas/_testing/asserters.py
Outdated
@@ -328,7 +319,7 @@ def _get_ilevel_values(index, level): | |||
diff = np.sum(mismatch.astype(int)) * 100.0 / len(left) | |||
msg = f"{obj} values are different ({np.round(diff, 5)} %)" | |||
raise_assert_detail(obj, msg, left, right) | |||
else: | |||
elif not left.equals(right): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know that .equals is the correct amount of strict?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, but after reviewing again I've reverted this line in favor of a lower level change to _array_equivalent_object
.
This has the benefit of improving performance for more cases, e.g. not just the index values but in this case the series values:
import pandas as pd
N = 100_000
values = pd._testing.makeStringIndex(N).values
ser1 = pd.Series(values.copy())
ser2 = pd.Series(values.copy())
%timeit pd.testing.assert_series_equal(ser1, ser2)
1.92 s ± 56.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
22.3 ms ± 4.18 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
Thanks @lukemanley |
return lib.array_equivalent_object(ensure_object(left), ensure_object(right)) | ||
|
||
for left_value, right_value in zip(left, right): | ||
left = ensure_object(left) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we get here in cases that are not already object? seems like if that happens then something has gone wrong?
doc/source/whatsnew/v2.2.0.rst
file if fixing a bug or adding a new feature.Follow-up to #55949 addressing some of @jbrockmendel's comments and also expanding to non-multiindex cases: