Skip to content

Support dictionary-style CF indexing - #661

Merged
dcherian merged 3 commits into
xarray-contrib:mainfrom
Kkkakania:feat/dict-loc-indexing
Jul 29, 2026
Merged

Support dictionary-style CF indexing#661
dcherian merged 3 commits into
xarray-contrib:mainfrom
Kkkakania:feat/dict-loc-indexing

Conversation

@Kkkakania

Copy link
Copy Markdown
Contributor

Summary

  • support position-based indexing such as obj.cf[{"T": 0}] for both DataArray and Dataset objects
  • add a .cf.loc wrapper that translates CF names for label-based reads and assignments
  • reuse the existing isel/sel mapper so one CF axis can expand to multiple concrete dimensions consistently

Closes #363.

Tests

  • added coverage for DataArray and Dataset reads, .loc assignment, dask-backed inputs, and one-to-many axis mappings
  • uv run --frozen --group test pytest cf_xarray/tests -q (296 passed, 1 skipped)
  • uvx pre-commit run --all-files

@dcherian
dcherian enabled auto-merge (squash) July 29, 2026 18:44
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.03%. Comparing base (a9cebee) to head (58c4dfd).
⚠️ Report is 127 commits behind head on main.

Files with missing lines Patch % Lines
cf_xarray/accessor.py 87.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #661      +/-   ##
==========================================
+ Coverage   85.78%   87.03%   +1.24%     
==========================================
  Files          13       16       +3     
  Lines        2364     3347     +983     
  Branches      183      313     +130     
==========================================
+ Hits         2028     2913     +885     
- Misses        303      387      +84     
- Partials       33       47      +14     
Flag Coverage Δ
mypy 45.95% <17.39%> (+7.41%) ⬆️
unittests 92.63% <95.23%> (-1.36%) ⬇️

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.

@dcherian
dcherian merged commit d1fbb9c into xarray-contrib:main Jul 29, 2026
13 checks passed
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.

Support dictionary-style indexing with .loc

2 participants