Skip to content

Fix custom criteria membership checks#659

Open
Kkkakania wants to merge 1 commit into
xarray-contrib:mainfrom
Kkkakania:fix/custom-criteria-membership
Open

Fix custom criteria membership checks#659
Kkkakania wants to merge 1 commit into
xarray-contrib:mainfrom
Kkkakania:fix/custom-criteria-membership

Conversation

@Kkkakania

Copy link
Copy Markdown

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.

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

1 participant