-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix assert_equal with check_dim_order=False for mixed dimension orders #10718
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
Open
max-sixty
wants to merge
13
commits into
pydata:main
Choose a base branch
from
max-sixty:10704
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−13
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
…imension orders Fixes pydata#10704 The bug: assert_equal with check_dim_order=False was failing when comparing Datasets containing variables with different dimension orders. It would even fail when comparing a Dataset to itself. The fix: Transpose both objects to a canonical dimension order using the intersection of their dimensions. The ellipsis (...) handles any dimensions unique to either object, making the solution general and elegant. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
shoyer
requested changes
Sep 8, 2025
- Use list(common_dims) instead of sorted(common_dims) since dimensions only need to be hashable, not sortable - Add test case for datasets with non-sortable dimension names (e.g., int and str) - Transpose both a and b to the same canonical order for consistency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
for more information, see https://pre-commit.ci
- Add test for no common dimensions path - Add test for Variable type specifically (not just DataArray) - Now all code paths in maybe_transpose_dims are covered 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
for more information, see https://pre-commit.ci
The reviewer was correct - the DataTree handling was wrong. We were only transposing b, but for consistency we need to transpose both a and b to the same canonical order, just like we do for Dataset. This fixes the issue and adds a comprehensive test case. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
for more information, see https://pre-commit.ci
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
assert_equalwithcheck_dim_order=Falsenow works correctly for Datasets containing variables with different dimension ordersThe Bug
When comparing Datasets with
check_dim_order=False, the comparison would fail if individual variables had different dimension orders, even when comparing a Dataset to itself:The Fix
The solution transposes both objects to a canonical dimension order using the intersection of their dimensions. The ellipsis (
...) handles any dimensions unique to either object:This elegant approach works uniformly for Variables, DataArrays, and Datasets without special casing.
Test plan
test_assert_equal_dataset_check_dim_orderthat reproduces the issueassert_equalandassert_allclose🤖 Generated with Claude Code