Repository navigation
Conversation
With pandas < 3, DatetimeIndex.equals and TimedeltaIndex.equals return False for indexes with identical values but different units (e.g. "s" vs "ns"). This made DataArray.equals / Dataset.equals disagree with broadcast_equals and with the behavior for data variables. Cast both indexes to the finer unit before comparing. Closes pydata#10045 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient. |
This branch has not been deployed
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.
Description
With pandas < 3,
DatetimeIndex.equals/TimedeltaIndex.equalsreturnFalsewhen two indexes hold identical values with different units (e.g.datetime64[s]vsdatetime64[ns]). BecausePandasIndex.equalsandIndexVariable._data_equalsdelegate to pandas,DataArray.equalson coordinates disagreed withbroadcast_equalsand with how data variables are compared (#10045). Still reproduces on main with pandas 2.3.3, which is the minimum supported version; pandas 3 already compares these as equal.This adds a small
pandas_index_equalshelper inxarray/core/indexes.pythat casts both datetime (or both timedelta) indexes to the finer unit before comparing, and uses it inPandasIndex.equalsandIndexVariable._data_equals. If a value in the coarser index is out of bounds for the finer unit, it cannot match any value there, so the comparison returnsFalse.Tested locally with the full test suite on pandas 2.3.3 and 3.1.1 (numpy 2.4); the new tests fail on main with pandas 2.3.
Checklist
whats-new.rstAI Disclosure
Tools: Claude Code (Claude Opus 5.5). Prompt: "contribute to https://github.com/pydata/xarray"; the issue was chosen among open bugs without linked PRs.
[This is Claude Code on behalf of ved1j]
🤖 Generated with Claude Code