Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 30, 2024
1 parent bb2bb6c commit 9f2cb2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
31 changes: 19 additions & 12 deletions xarray/backends/zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from xarray.core.datatree import DataTree



@functools.lru_cache
def _zarr_v3() -> bool:
try:
Expand Down Expand Up @@ -90,8 +89,10 @@ def __init__(self, zarr_array):
self.shape = self._array.shape

# preserve vlen string object dtype (GH 7328)
if not _zarr_v3() and self._array.filters is not None and any(
[filt.codec_id == "vlen-utf8" for filt in self._array.filters]
if (
not _zarr_v3()
and self._array.filters is not None
and any([filt.codec_id == "vlen-utf8" for filt in self._array.filters])
):
dtype = coding.strings.create_vlen_dtype(str)
else:
Expand Down Expand Up @@ -634,17 +635,23 @@ def open_store_variable(self, name, zarr_array=None):
}

if _zarr_v3() and zarr_array.metadata.zarr_format == 3:
encoding["codec_pipeline"] = [x.to_dict() for x in zarr_array.metadata.codecs]
encoding["codec_pipeline"] = [
x.to_dict() for x in zarr_array.metadata.codecs
]
elif _zarr_v3():
encoding.update({
"compressor": zarr_array.metadata.compressor,
"filters": zarr_array.metadata.filters,
})
encoding.update(
{
"compressor": zarr_array.metadata.compressor,
"filters": zarr_array.metadata.filters,
}
)
else:
encoding.update({
"compressor": zarr_array.compressor,
"filters": zarr_array.filters,
})
encoding.update(
{
"compressor": zarr_array.compressor,
"filters": zarr_array.filters,
}
)

# _FillValue needs to be in attributes, not encoding, so it will get
# picked up by decode_cf
Expand Down
12 changes: 10 additions & 2 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,9 @@ def test_roundtrip_consolidated(self, consolidated) -> None:
def test_read_non_consolidated_warning(self) -> None:
expected = create_test_data()
with self.create_zarr_target() as store:
self.save(expected, store_target=store, consolidated=False, **self.version_kwargs)
self.save(
expected, store_target=store, consolidated=False, **self.version_kwargs
)
with pytest.warns(
RuntimeWarning,
match="Failed to open Zarr store with consolidated",
Expand Down Expand Up @@ -3044,7 +3046,12 @@ def test_encoding_chunksizes(self) -> None:
# see also test_encoding_chunksizes_unlimited
nx, ny, nt = 4, 4, 5
original = xr.Dataset(
{}, coords={"x": np.arange(nx) + 1 , "y": np.arange(ny) + 1, "t": np.arange(nt) + 1}
{},
coords={
"x": np.arange(nx) + 1,
"y": np.arange(ny) + 1,
"t": np.arange(nt) + 1,
},
)
original["v"] = xr.Variable(("x", "y", "t"), np.zeros((nx, ny, nt)))
original = original.chunk({"t": 1, "x": 2, "y": 2})
Expand Down Expand Up @@ -3304,6 +3311,7 @@ class TestZarrDictStore(ZarrBase):
def create_zarr_target(self):
if have_zarr_v3:
import zarr.store

yield zarr.store.MemoryStore({}, mode="w")
else:
yield {}
Expand Down

0 comments on commit 9f2cb2f

Please sign in to comment.