Skip to content
Merged
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
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Bug fixes
- Allow ``combine_attrs="drop_conflicts"`` to handle objects with ``__eq__`` methods that return
non-bool values (e.g., numpy arrays) without raising ``ValueError`` (:pull:`10726`).
By `Maximilian Roos <https://github.com/max-sixty>`_.
- Fix error raised when writing scalar variables to Zarr with ``region={}``
(:pull:`10796`).
By `Stephan Hoyer <https://github.com/shoyer>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ def _validate_and_autodetect_region(self, ds: Dataset) -> Dataset:
non_matching_vars = [
k for k, v in ds.variables.items() if not set(region).intersection(v.dims)
]
if non_matching_vars:
if region and non_matching_vars:
raise ValueError(
f"when setting `region` explicitly in to_zarr(), all "
f"variables in the dataset to write must have at least "
Expand Down
8 changes: 8 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,14 @@ def test_write_region(self, consolidated, compute, use_dask, write_empty) -> Non
) as actual:
assert_identical(actual, nonzeros)

def test_region_scalar(self) -> None:
ds = Dataset({"x": 0})
with self.create_zarr_target() as store:
ds.to_zarr(store)
ds.to_zarr(store, region={}, mode="r+")
with xr.open_zarr(store) as actual:
assert_identical(actual, ds)

@pytest.mark.parametrize("mode", [None, "r+", "a"])
def test_write_region_mode(self, mode) -> None:
zeros = Dataset({"u": (("x",), np.zeros(10))})
Expand Down
Loading