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: assert_frame_equal / assert_series_equal #55971

Merged
merged 9 commits into from Nov 17, 2023

Conversation

lukemanley
Copy link
Member

Follow-up to #55949 addressing some of @jbrockmendel's comments and also expanding to non-multiindex cases:

import pandas as pd

N = 1_000_000

idx = pd._testing.makeStringIndex(N)

ser1 = pd.Series(1, index=idx.copy(deep=True))
ser2 = pd.Series(1, index=idx.copy(deep=True))

%timeit pd.testing.assert_series_equal(ser1, ser2)

# 17.8 s ± 129 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
# 48.1 ms ± 3.28 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

@lukemanley lukemanley added Testing pandas testing functions or related to the test suite Performance Memory or execution speed performance labels Nov 15, 2023
@lukemanley lukemanley added this to the 2.2 milestone Nov 15, 2023
@@ -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):
Copy link
Member

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?

Copy link
Member Author

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)

@mroeschke mroeschke merged commit 32ebcfc into pandas-dev:main Nov 17, 2023
40 checks passed
@mroeschke
Copy link
Member

Thanks @lukemanley

@lukemanley lukemanley deleted the perf-assert-functions branch November 22, 2023 01:59
return lib.array_equivalent_object(ensure_object(left), ensure_object(right))

for left_value, right_value in zip(left, right):
left = ensure_object(left)
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Memory or execution speed performance Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants