Skip to content

Fix custom criteria membership checks - #659

Merged
dcherian merged 2 commits into
xarray-contrib:mainfrom
Kkkakania:fix/custom-criteria-membership
Jul 29, 2026
Merged

Fix custom criteria membership checks#659
dcherian merged 2 commits into
xarray-contrib:mainfrom
Kkkakania:fix/custom-criteria-membership

Conversation

@Kkkakania

Copy link
Copy Markdown
Contributor

Summary

Make custom criteria that match variables in the current object appear in obj.cf.keys(). Because CFAccessor.__contains__ delegates to keys(), membership checks such as "salt" in ds.cf now agree with successful ds.cf["salt"] lookups.

Custom vocabulary entries with no match are intentionally omitted, preserving the documented meaning of keys() as the set of valid keys for the current object.

Closes #375.
Closes #531.

Tests

  • Added a regression test covering matched and unmatched custom criteria through both keys() and in.
  • PYTHONPATH=. ../cf-xarray-127/.venv/bin/python -m pytest cf_xarray/tests -q (284 passed, 1 skipped)
  • uvx pre-commit run --files cf_xarray/accessor.py cf_xarray/tests/test_accessor.py

AI disclosure: this change was AI-assisted. I reproduced the failure before the implementation, reviewed the final diff, and ran the full local test suite and pre-commit hooks.

@dcherian
dcherian enabled auto-merge (squash) July 29, 2026 18:45
@dcherian
dcherian merged commit 4b5dc74 into xarray-contrib:main Jul 29, 2026
11 checks passed
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
cf_xarray/accessor.py 40.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #659      +/-   ##
==========================================
+ Coverage   85.78%   87.03%   +1.25%     
==========================================
  Files          13       16       +3     
  Lines        2364     3325     +961     
  Branches      183      309     +126     
==========================================
+ Hits         2028     2894     +866     
- Misses        303      384      +81     
- Partials       33       47      +14     
Flag Coverage Δ
mypy 46.18% <20.00%> (+7.65%) ⬆️
unittests 92.62% <100.00%> (-1.37%) ⬇️

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.

custom criteria keys should be listed in keys() checking membership does not account for custom criteria

2 participants