Skip to content

Add mapping-style get method to CF accessors#658

Open
Kkkakania wants to merge 1 commit into
xarray-contrib:mainfrom
Kkkakania:agent/accessor-get
Open

Add mapping-style get method to CF accessors#658
Kkkakania wants to merge 1 commit into
xarray-contrib:mainfrom
Kkkakania:agent/accessor-get

Conversation

@Kkkakania

Copy link
Copy Markdown

Summary

  • add a shared CFAccessor.get() that delegates to each accessor's existing __getitem__ implementation
  • return None or a caller-provided default only when CF lookup raises KeyError
  • preserve successful CF-name resolution and Dataset iterable-key behavior
  • avoid masking non-lookup errors

Fixes #127.

Verification

  • uvx ruff check cf_xarray/accessor.py cf_xarray/tests/test_accessor.py
  • uvx ruff format --check cf_xarray/accessor.py cf_xarray/tests/test_accessor.py
  • uv run --group test pytest cf_xarray/tests/test_accessor.py -q (216 passed, 1 skipped)

AI assistance

I used Codex to inspect the shared accessor hierarchy and draft the implementation and tests. I reviewed the behavior against both Dataset and DataArray accessors and can maintain the submitted changes.

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.

Implement .get

1 participant