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

Allow write_empty_chunks to be set in Zarr encoding #6348

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ def extract_zarr_variable_encoding(
"""
encoding = variable.encoding.copy()

valid_encodings = {"chunks", "compressor", "filters", "cache_metadata"}
valid_encodings = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this check at all? Does Zarr not check for invalid encodings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look @dcherian.

Zarr will issue a UserWarning for invalid encodings (kwargs):

>>> zarr.create((1,), blah=1)
/Users/tom/miniconda/envs/sgkit-3.8/lib/python3.8/site-packages/zarr/creation.py:221: UserWarning: ignoring keyword argument 'blah'
  warn('ignoring keyword argument %r' % k)
<zarr.core.Array (1,) float64>

However, it looks like extract_zarr_variable_encoding is using the list of valid encodings to find the relevant kwargs to pass to Zarr, so this list may well be needed in order to not trigger the warning if a variable has other, non-Zarr encodings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... I'll merge and lets discuss in an issue.

"chunks",
"compressor",
"filters",
"cache_metadata",
"write_empty_chunks",
}

if raise_on_invalid:
invalid = [k for k in encoding if k not in valid_encodings]
Expand Down