Skip to content

Add type annotations to open_zarr#11226

Open
wavebyrd wants to merge 1 commit intopydata:mainfrom
wavebyrd:fix-open-zarr-typing
Open

Add type annotations to open_zarr#11226
wavebyrd wants to merge 1 commit intopydata:mainfrom
wavebyrd:fix-open-zarr-typing

Conversation

@wavebyrd
Copy link

Adds type annotations to all parameters of open_zarr and its return type.

Previously the function was essentially untyped, which caused type checkers like pyright to reject valid arguments such as chunks="auto" because the default value _default (of type Default) was the only inferred type.

  • chunks is now typed as T_Chunks | Default
  • All other parameters annotated to match their documented types
  • Return type annotated as Dataset

Fixes #11221

@github-actions github-actions bot added topic-backends topic-zarr Related to zarr storage library io labels Mar 13, 2026
@wavebyrd wavebyrd force-pushed the fix-open-zarr-typing branch from 7889687 to 8d80b04 Compare March 13, 2026 21:39
@github-actions github-actions bot added topic-indexing topic-CF conventions topic-groupby topic-dask topic-plotting topic-testing topic-performance topic-cftime topic-arrays related to flexible array support CI Continuous Integration tools topic-html-repr topic-rolling dependencies Pull requests that update a dependency file Automation Github bots, testing workflows, release automation topic-DataTree Related to the implementation of a DataTree class topic-typing topic-hypothesis Strategies or tests using the hypothesis library topic-NamedArray Lightweight version of Variable labels Mar 13, 2026
@wavebyrd
Copy link
Author

Friendly ping on this type annotation PR for open_zarr. Let me know if any changes needed!

@headtr1ck
Copy link
Collaborator

Can you rebase that on main? I'm not looking through 200k LOC changes, haha.

All parameters in open_zarr were untyped, which caused type checkers
like pyright to reject valid arguments (e.g. passing "auto" for chunks).

Adds annotations to every parameter and the return type, using T_Chunks
for the chunks parameter and matching types from the docstrings for the
rest.

Fixes pydata#11221
@wavebyrd wavebyrd force-pushed the fix-open-zarr-typing branch from 8d80b04 to 2b191dd Compare March 19, 2026 01:16
@wavebyrd
Copy link
Author

Rebased onto main - now shows only the single commit for this fix. Thanks for the review!

mask_and_scale=True,
decode_times=True,
concat_characters=True,
store: str | os.PathLike[Any] | MutableMapping | None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add the generic types of MutableMapping?
I don't actually know what it should be, probably MutableMapping[str, str]?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually mypy complains here. Maybe you can simply use xarray.backends.common.T_PathFileOrDataStore?

@headtr1ck
Copy link
Collaborator

Feel free to add this change to what's new!

group: str | None = None,
synchronizer: object | None = None,
chunks: T_Chunks | Default = _default,
decode_cf: bool = True,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Mypy says that this can also take a CFTimeCoder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Automation Github bots, testing workflows, release automation CI Continuous Integration tools dependencies Pull requests that update a dependency file io topic-arrays related to flexible array support topic-backends topic-CF conventions topic-cftime topic-dask topic-DataTree Related to the implementation of a DataTree class topic-groupby topic-html-repr topic-hypothesis Strategies or tests using the hypothesis library topic-indexing topic-NamedArray Lightweight version of Variable topic-performance topic-plotting topic-rolling topic-testing topic-typing topic-zarr Related to zarr storage library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chunks argument is typed incorrected in open_zarr

2 participants