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

Check that template dims and zarr_chunks match. #97

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions xarray_beam/_src/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ def _infer_zarr_chunks(dataset: xarray.Dataset) -> Dict[str, int]:
def _setup_zarr(template, store, zarr_chunks):
"""Setup a Zarr store."""
if zarr_chunks is not None:
if zarr_chunks.keys() != template.dims.keys():
raise ValueError(
'template dimensions do not match keys in zarr_chunks: '
f'{template.dims.keys()} vs. {zarr_chunks.keys()}'
)
template = _override_chunks(template, zarr_chunks)
_verify_template_is_lazy(template)
# inconsistent chunks in encoding can lead to spurious failures in xarray:
Expand Down
7 changes: 7 additions & 0 deletions xarray_beam/_src/zarr_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ def test_chunks_to_zarr(self):
):
inputs2 | xbeam.ChunksToZarr(temp_dir, template)

temp_dir = self.create_tempdir().full_path
with self.assertRaisesRegex(
ValueError,
'template dimensions do not match keys in zarr_chunks',
):
xbeam.ChunksToZarr(temp_dir, chunked, zarr_chunks={})

def test_multiple_vars_chunks_to_zarr(self):
dataset = xarray.Dataset(
{
Expand Down
Loading