Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add mapping-style get method to CF accessors#658

Open
Kkkakania wants to merge 1 commit into
xarray-contrib:mainxarray-contrib/cf-xarray:mainfrom
Kkkakania:agent/accessor-getKkkakania/cf-xarray:agent/accessor-getCopy head branch name to clipboard
Open

Add mapping-style get method to CF accessors#658
Kkkakania wants to merge 1 commit into
xarray-contrib:mainxarray-contrib/cf-xarray:mainfrom
Kkkakania:agent/accessor-getKkkakania/cf-xarray:agent/accessor-getCopy head branch name to clipboard

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.