Skip to content

Reject ambiguous MultiIndex names in CF compression - #680

Closed
nawaaaaaAaar wants to merge 1 commit into
xarray-contrib:mainfrom
nawaaaaaAaar:fix/compress-level-names
Closed

nawaaaaaAaar wants to merge 1 commit into
xarray-contrib:mainfrom
nawaaaaaAaar:fix/compress-level-names

Conversation

@nawaaaaaAaar

Copy link
Copy Markdown
Contributor

Summary

Fixes #570. Follow-up to my merged #674 and #675.

Reject MultiIndex level names that cannot be represented by CF's whitespace-delimited compress attribute, before resetting indexes or constructing an invalid encoded dataset.

For example, names ("lat name", "lon") currently produce compress="lat name lon"; decoding then raises KeyError: 'lat'. Renaming silently would change the user's coordinate names, so this uses an actionable ValueError instead.

The guard rejects empty/non-string names and any whitespace, not only literal spaces. The docstring documents the error.

Validation

  • All 12 new regressions fail against unchanged main, then pass with the guard.
  • Cover both index levels, internal/leading/trailing spaces, tab, newline and empty names.
  • Verify the input Dataset is unchanged on rejection.
  • Relevant coding suite: 26 passed.
  • Full suite: 313 passed, 10 skipped.
  • Mypy: no issues in 28 source files after installing the repository's type-stub dependencies.
  • All pre-commit hooks pass; wheel and sdist build successfully.
  • git diff --check: clean.

AI-assisted contribution: reproduction, implementation, review and checks were performed by the assistant. No personal account-owner review is asserted.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@nawaaaaaAaar

Copy link
Copy Markdown
Contributor Author

Closing in favor of the earlier #676, which appeared while this implementation was being prepared. Keeping one compression-name validation PR for maintainers to review.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.10%. Comparing base (a9cebee) to head (b227711).
⚠️ Report is 132 commits behind head on main.

Files with missing lines Patch % Lines
cf_xarray/coding.py 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #680      +/-   ##
==========================================
+ Coverage   85.78%   87.10%   +1.31%     
==========================================
  Files          13       16       +3     
  Lines        2364     3357     +993     
  Branches      183      313     +130     
==========================================
+ Hits         2028     2924     +896     
- Misses        303      387      +84     
- Partials       33       46      +13     
Flag Coverage Δ
mypy 45.99% <0.00%> (+7.46%) ⬆️
unittests 92.85% <100.00%> (-1.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert no variable with spaces in name is used for compression by gathering

2 participants