PERF: short-circuit array_equivalent and equals comparisons#65192
Merged
Conversation
b80c4e6 to
615f167
Compare
Add short-circuiting Cython functions for array equality checks: - array_equivalent_float: single-pass NaN-aware float comparison, replacing the 4-temporary-array expression ((left == right) | (isnan(left) & isnan(right))).all() - array_equivalent_bytes: memcmp-based comparison for int/bool/datetime arrays, replacing np.array_equal - has_nans/all_nans: short-circuiting replacements for np.isnan(arr).any()/all() For non-contiguous inputs, falls back to the original numpy expressions with no regression. closes pandas-dev#32339 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
615f167 to
5da15fe
Compare
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
44a6e3f to
ebd1b21
Compare
rhshadrach
approved these changes
May 9, 2026
Comment on lines
+586
to
+588
| C-contiguous inputs. Not safe for dtypes where distinct bit patterns can | ||
| represent the same value (e.g. floats with -0.0/+0.0 or NaN) or for arrays | ||
| that contain object pointers. |
Member
There was a problem hiding this comment.
Is it worth adding asserts for the common unsafe ones (float/complex/object I think)?
Member
Author
There was a problem hiding this comment.
i dont think so; the caller is responsible for gating
Member
|
Thanks @jbrockmendel |
Sharl0tteIsTaken
added a commit
to Sharl0tteIsTaken/pandas
that referenced
this pull request
May 10, 2026
…-comparison * upstream/main: (78 commits) PERF: short-circuit array_equivalent and equals comparisons (pandas-dev#65192) DOC: clarify GroupBy.resample parameters (pandas-devGH-54295) (pandas-dev#65545) TYP: type-check pandas.core.sample (pandas-dev#65533) DOC: drop dead redirects, generate ExtensionDtype member pages (pandas-dev#65527) CLN: drop stale pre-commit exclude for deleted code_style.rst (pandas-dev#65531) TYP: enable mypy checking for pandas.core.window.online (pandas-dev#65534) TYP: enable mypy on core.internals.api (pandas-dev#65535) TYP: enable mypy checks on pandas.core.dtypes.generic (pandas-dev#65537) DOC: document Rolling.apply Series index when on= is specified (pandas-dev#65539) TYP: enable mypy disallow_untyped_defs for pandas.core.roperator (pandas-dev#65540) TYP: enable mypy checking for pandas.core.sorting (pandas-dev#65541) DOC: clarify result_type has no effect for ufuncs in DataFrame.apply (pandas-dev#65542) TYP: enable mypy on pandas.compat.numpy.function (pandas-dev#65543) DOC: clarify read_fwf filepath_or_buffer description (pandas-devGH-55790) (pandas-dev#65544) DOC: fix relativedelta link in DateOffset See Also (pandas-dev#65546) TYP: annotate pandas/io/excel/_pyxlsb and drop from mypy overrides (pandas-dev#65547) TYP: annotate pandas/_config/config.py (pandas-dev#65549) PERF: skip to_datetime cache=True overhead for no-help input shapes (GH#65380) (pandas-dev#65409) BUG:to_datetime with origin (pandas-dev#63915) BUG: Series.transform now raises SpecificationError for duplicate function names (GH#54929) (pandas-dev#65156) ...
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pandas/_libs/lib.pyx:array_equivalent_float: single-pass NaN-aware float comparison, replacing the 4-temporary-array expression((left == right) | (isnan(left) & isnan(right))).all()array_equivalent_bytes:memcmp-based comparison for int/bool/datetime arrays, replacingnp.array_equalhas_nans/all_nans: short-circuiting replacements fornp.isnan(arr).any()/.all()array_equivalent,_array_equivalent_float,_array_equivalent_datetimelike, and theequalsmethods onDatetimeLikeIndex,MultiIndex,MaskedArray, andCategoricalarray_equivalentwithdtype_equal=True, 10^6 elements:DataFrame.equalson 1000x1000:closes #32339
Test plan
🤖 Generated with Claude Code