Skip to content

Commit 05d11ac

Browse files
authored
Merge branch 'v3' into use_map_str_tst_accessed
2 parents f75fc16 + 9f825e1 commit 05d11ac

34 files changed

+200
-167
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ fixture/
8484
.DS_Store
8585
tests/.hypothesis
8686
.hypothesis/
87+
88+
zarr/version.py

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,26 @@ extend-exclude = [
208208
[tool.ruff.lint]
209209
extend-select = [
210210
"B", # flake8-bugbear
211+
"FLY", # flynt
211212
"I", # isort
212213
"ISC", # flake8-implicit-str-concat
213214
"PGH", # pygrep-hooks
215+
"PT", # flake8-pytest-style
214216
"PYI", # flake8-pyi
215217
"RSE", # flake8-raise
218+
"RET", # flake8-return
216219
"RUF",
217220
"TCH", # flake8-type-checking
218221
"TRY", # tryceratops
219222
"UP", # pyupgrade
220223
]
221224
ignore = [
225+
"PT004", # deprecated
226+
"PT011", # TODO: apply this rule
227+
"PT012", # TODO: apply this rule
222228
"PYI013",
229+
"RET505",
230+
"RET506",
223231
"RUF005",
224232
"TRY003",
225233
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules

src/zarr/abc/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async def _set_many(self, values: Iterable[tuple[str, Buffer]]) -> None:
170170
Insert multiple (key, value) pairs into storage.
171171
"""
172172
await gather(*(self.set(key, value) for key, value in values))
173-
return None
173+
return
174174

175175
@property
176176
@abstractmethod

src/zarr/codecs/_v2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88

99
from zarr.abc.codec import ArrayArrayCodec, ArrayBytesCodec
1010
from zarr.core.buffer import Buffer, NDBuffer, default_buffer_prototype
11-
from zarr.core.common import JSON, to_thread
11+
from zarr.core.common import to_thread
1212
from zarr.registry import get_ndbuffer_class
1313

1414
if TYPE_CHECKING:
15+
import numcodecs.abc
16+
1517
from zarr.core.array_spec import ArraySpec
1618

1719

1820
@dataclass(frozen=True)
1921
class V2Compressor(ArrayBytesCodec):
20-
compressor: dict[str, JSON] | None
22+
compressor: numcodecs.abc.Codec | None
2123

2224
is_fixed_size = False
2325

@@ -27,9 +29,8 @@ async def _decode_single(
2729
chunk_spec: ArraySpec,
2830
) -> NDBuffer:
2931
if self.compressor is not None:
30-
compressor = numcodecs.get_codec(self.compressor)
3132
chunk_numpy_array = ensure_ndarray(
32-
await to_thread(compressor.decode, chunk_bytes.as_array_like())
33+
await to_thread(self.compressor.decode, chunk_bytes.as_array_like())
3334
)
3435
else:
3536
chunk_numpy_array = ensure_ndarray(chunk_bytes.as_array_like())
@@ -47,14 +48,13 @@ async def _encode_single(
4748
) -> Buffer | None:
4849
chunk_numpy_array = chunk_array.as_numpy_array()
4950
if self.compressor is not None:
50-
compressor = numcodecs.get_codec(self.compressor)
5151
if (
5252
not chunk_numpy_array.flags.c_contiguous
5353
and not chunk_numpy_array.flags.f_contiguous
5454
):
5555
chunk_numpy_array = chunk_numpy_array.copy(order="A")
5656
encoded_chunk_bytes = ensure_bytes(
57-
await to_thread(compressor.encode, chunk_numpy_array)
57+
await to_thread(self.compressor.encode, chunk_numpy_array)
5858
)
5959
else:
6060
encoded_chunk_bytes = ensure_bytes(chunk_numpy_array)

src/zarr/core/array.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import numpy.typing as npt
1010

1111
from zarr._compat import _deprecate_positional_args
12-
from zarr.abc.codec import Codec, CodecPipeline
1312
from zarr.abc.store import set_or_delete
1413
from zarr.codecs import BytesCodec
1514
from zarr.codecs._v2 import V2Compressor, V2Filters
@@ -252,12 +251,6 @@ async def _create_v3(
252251
shape = parse_shapelike(shape)
253252
codecs = list(codecs) if codecs is not None else [BytesCodec()]
254253

255-
if fill_value is None:
256-
if dtype == np.dtype("bool"):
257-
fill_value = False
258-
else:
259-
fill_value = 0
260-
261254
if chunk_key_encoding is None:
262255
chunk_key_encoding = ("default", "/")
263256
assert chunk_key_encoding is not None
@@ -281,7 +274,6 @@ async def _create_v3(
281274
)
282275

283276
array = cls(metadata=metadata, store_path=store_path)
284-
285277
await array._save_metadata(metadata)
286278
return array
287279

src/zarr/core/buffer/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,14 @@ def __repr__(self) -> str:
464464

465465
def all_equal(self, other: Any, equal_nan: bool = True) -> bool:
466466
"""Compare to `other` using np.array_equal."""
467+
if other is None:
468+
# Handle None fill_value for Zarr V2
469+
return False
467470
# use array_equal to obtain equal_nan=True functionality
468471
data, other = np.broadcast_arrays(self._data, other)
469-
result = np.array_equal(self._data, other, equal_nan=equal_nan)
470-
return result
472+
return np.array_equal(
473+
self._data, other, equal_nan=equal_nan if self._data.dtype.kind not in "US" else False
474+
)
471475

472476
def fill(self, value: Any) -> None:
473477
self._data.fill(value)

src/zarr/core/group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ async def _members(
676676
async for child_key, val in obj._members(
677677
max_depth=max_depth, current_depth=current_depth + 1
678678
):
679-
yield "/".join([key, child_key]), val
679+
yield f"{key}/{child_key}", val
680680
except KeyError:
681681
# keyerror is raised when `key` names an object (in the object storage sense),
682682
# as opposed to a prefix, in the store under the prefix associated with this group

src/zarr/core/metadata/v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ def _json_convert(
100100
return o.str
101101
else:
102102
return o.descr
103+
if isinstance(o, numcodecs.abc.Codec):
104+
return o.get_config()
103105
if np.isscalar(o):
104106
out: Any
105107
if hasattr(o, "dtype") and o.dtype.kind == "M" and hasattr(o, "view"):

src/zarr/core/metadata/v3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def parse_fill_value(
360360
if fill_value is None:
361361
return dtype.type(0)
362362
if isinstance(fill_value, Sequence) and not isinstance(fill_value, str):
363-
if dtype in (np.complex64, np.complex128):
363+
if dtype.type in (np.complex64, np.complex128):
364364
dtype = cast(COMPLEX_DTYPE, dtype)
365365
if len(fill_value) == 2:
366366
# complex datatypes serialize to JSON arrays with two elements
@@ -391,7 +391,7 @@ def parse_fill_value(
391391
pass
392392
elif fill_value in ["Infinity", "-Infinity"] and not np.isfinite(casted_value):
393393
pass
394-
elif dtype.kind == "f":
394+
elif dtype.kind in "cf":
395395
# float comparison is not exact, especially when dtype <float64
396396
# so we us np.isclose for this comparison.
397397
# this also allows us to compare nan fill_values

src/zarr/store/memory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
from collections.abc import AsyncGenerator, MutableMapping
43
from typing import TYPE_CHECKING
54

65
from zarr.abc.store import Store

0 commit comments

Comments
 (0)