Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add get(key, default) method to Group APIs #2311

Merged
merged 5 commits into from
Oct 8, 2024

Conversation

jhamman
Copy link
Member

@jhamman jhamman commented Oct 8, 2024

Some downstream applications (xarray.DataTree) were using Group.get. This PR adds that to the Group API for backward compatibility.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@jhamman jhamman requested a review from TomAugspurger October 8, 2024 19:31
@@ -290,6 +292,28 @@ async def delitem(self, key: str) -> None:
else:
raise ValueError(f"unexpected zarr_format: {self.metadata.zarr_format}")

async def get(
self, key: str, default: DefaultT | None = None
Copy link
Contributor

@TomAugspurger TomAugspurger Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know how to type this properly, but IMO as a user I'd appreciate the ability to know that .get(key, default) is still AsyncArray | AsyncGroup (or None I guess). So maybe we have DefaultT also be bound to AsyncArray, AsyncGroup?

That said

from typing import reveal_type

foo : dict[str, int] = {}
reveal_type(foo.get("a", "b"))

gives

src/zarr/core/metadata/v3.py:555: note: Revealed type is "Union[builtins.int, builtins.str]"

so nevermind :/ I guess maybe by providing an AsyncGroup as a default, the DefaultT will be AsyncGroup and I'd get what I want.

@jhamman jhamman merged commit 5a134bf into zarr-developers:v3 Oct 8, 2024
20 checks passed
@jhamman jhamman deleted the fix/group-get-with-default branch October 8, 2024 19:54
@jhamman jhamman added the V3 label Oct 11, 2024
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.

2 participants