diff --git a/src/zarr/codecs/sharding.py b/src/zarr/codecs/sharding.py index cd8676b4d1..37a428791e 100644 --- a/src/zarr/codecs/sharding.py +++ b/src/zarr/codecs/sharding.py @@ -421,8 +421,8 @@ def validate( ) if not isinstance(chunk_grid, RegularChunkGrid): raise TypeError("Sharding is only compatible with regular chunk grids.") - if not all( - s % c == 0 + if any( + s % c != 0 for s, c in zip( chunk_grid.chunk_shape, self.chunk_shape, diff --git a/src/zarr/core/array.py b/src/zarr/core/array.py index a4f7fc086a..5b201dc331 100644 --- a/src/zarr/core/array.py +++ b/src/zarr/core/array.py @@ -688,7 +688,7 @@ async def _create( overwrite=overwrite, ) else: - raise ValueError(f"Insupported zarr_format. Got: {zarr_format}") + raise ValueError(f"Unsupported zarr_format. Got: {zarr_format}") if data is not None: # insert user-provided data diff --git a/src/zarr/core/common.py b/src/zarr/core/common.py index e86347d808..d748b4d331 100644 --- a/src/zarr/core/common.py +++ b/src/zarr/core/common.py @@ -167,7 +167,7 @@ def parse_shapelike(data: int | Iterable[int]) -> tuple[int, ...]: if not all(isinstance(v, int) for v in data_tuple): msg = f"Expected an iterable of integers. Got {data} instead." raise TypeError(msg) - if not all(v > -1 for v in data_tuple): + if any(v < 0 for v in data_tuple): msg = f"Expected all values to be non-negative. Got {data} instead." raise ValueError(msg) return data_tuple diff --git a/src/zarr/core/metadata/v2.py b/src/zarr/core/metadata/v2.py index 7bdad204b8..5ebe54ab95 100644 --- a/src/zarr/core/metadata/v2.py +++ b/src/zarr/core/metadata/v2.py @@ -266,11 +266,11 @@ def parse_filters(data: object) -> tuple[numcodecs.abc.Codec, ...] | None: """ Parse a potential tuple of filters """ - out: list[numcodecs.abc.Codec] = [] if data is None: return data if isinstance(data, Iterable): + out: list[numcodecs.abc.Codec] = [] for idx, val in enumerate(data): if isinstance(val, numcodecs.abc.Codec): out.append(val) diff --git a/src/zarr/core/metadata/v3.py b/src/zarr/core/metadata/v3.py index 84872d3dbd..114646683c 100644 --- a/src/zarr/core/metadata/v3.py +++ b/src/zarr/core/metadata/v3.py @@ -94,7 +94,7 @@ def validate_codecs(codecs: tuple[Codec, ...], dtype: ZDType[TBaseDType, TBaseSc # TODO: use codec ID instead of class name codec_class_name = abc.__class__.__name__ # TODO: Fix typing here - if isinstance(dtype, VariableLengthUTF8) and not codec_class_name == "VLenUTF8Codec": # type: ignore[unreachable] + if isinstance(dtype, VariableLengthUTF8) and codec_class_name != "VLenUTF8Codec": # type: ignore[unreachable] raise ValueError( f"For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `{codec_class_name}`." ) diff --git a/src/zarr/registry.py b/src/zarr/registry.py index 189d42abed..ea623f4c97 100644 --- a/src/zarr/registry.py +++ b/src/zarr/registry.py @@ -190,9 +190,9 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec: if not isinstance(result, BytesBytesCodec): msg = f"Expected a dict representation of a BytesBytesCodec; got a dict representation of a {type(result)} instead." raise TypeError(msg) + elif not isinstance(data, BytesBytesCodec): + raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.") else: - if not isinstance(data, BytesBytesCodec): - raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.") result = data return result @@ -210,9 +210,9 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec: if not isinstance(result, ArrayBytesCodec): msg = f"Expected a dict representation of a ArrayBytesCodec; got a dict representation of a {type(result)} instead." raise TypeError(msg) + elif not isinstance(data, ArrayBytesCodec): + raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.") else: - if not isinstance(data, ArrayBytesCodec): - raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.") result = data return result @@ -230,9 +230,9 @@ def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec: if not isinstance(result, ArrayArrayCodec): msg = f"Expected a dict representation of a ArrayArrayCodec; got a dict representation of a {type(result)} instead." raise TypeError(msg) + elif not isinstance(data, ArrayArrayCodec): + raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.") else: - if not isinstance(data, ArrayArrayCodec): - raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.") result = data return result diff --git a/src/zarr/testing/stateful.py b/src/zarr/testing/stateful.py index 6faf5dc6d3..963a128fa9 100644 --- a/src/zarr/testing/stateful.py +++ b/src/zarr/testing/stateful.py @@ -301,7 +301,7 @@ def delete_dir(self, data: DataObject) -> None: # array_path = data.draw(st.sampled_from(self.all_arrays), label="Array move source") # to_group = data.draw(st.sampled_from(self.all_groups), label="Array move destination") - # # fixme renaiming to self? + # # fixme renaming to self? # array_name = os.path.basename(array_path) # assume(self.model.can_add(to_group, array_name)) # new_path = f"{to_group}/{array_name}".lstrip("/") @@ -318,7 +318,7 @@ def delete_dir(self, data: DataObject) -> None: # from_group_name = os.path.basename(from_group) # assume(self.model.can_add(to_group, from_group_name)) - # # fixme renaiming to self? + # # fixme renaming to self? # new_path = f"{to_group}/{from_group_name}".lstrip("/") # note(f"moving group '{from_group}' -> '{new_path}'") # self.model.rename(from_group, new_path) diff --git a/tests/conftest.py b/tests/conftest.py index 4d300a1fd4..9f9b0fe75c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -107,7 +107,7 @@ async def store2(request: pytest.FixtureRequest, tmpdir: LEGACY_PATH) -> Store: def sync_store(request: pytest.FixtureRequest, tmp_path: LEGACY_PATH) -> Store: result = sync(parse_store(request.param, str(tmp_path))) if not isinstance(result, Store): - raise TypeError("Wrong store class returned by test fixture! got " + result + " instead") + raise TypeError(f"Wrong store class returned by test fixture! got {result} instead") return result diff --git a/tests/test_api.py b/tests/test_api.py index b4f25a375e..9ee2cb3a9b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1177,7 +1177,7 @@ async def test_open_falls_back_to_open_group_async(zarr_format: ZarrFormat) -> N def test_open_modes_creates_group(tmp_path: pathlib.Path, mode: str) -> None: # https://github.com/zarr-developers/zarr-python/issues/2490 zarr_dir = tmp_path / f"mode-{mode}-test.zarr" - if mode in ["r", "r+"]: + if mode in {"r", "r+"}: # Expect FileNotFoundError to be raised if 'r' or 'r+' mode with pytest.raises(FileNotFoundError): zarr.open(store=zarr_dir, mode=mode) diff --git a/tests/test_codec_entrypoints.py b/tests/test_codec_entrypoints.py index e1ef027dd4..f894597148 100644 --- a/tests/test_codec_entrypoints.py +++ b/tests/test_codec_entrypoints.py @@ -25,7 +25,7 @@ def set_path() -> Generator[None, None, None]: @pytest.mark.usefixtures("set_path") @pytest.mark.parametrize("codec_name", ["TestEntrypointCodec", "TestEntrypointGroup.Codec"]) def test_entrypoint_codec(codec_name: str) -> None: - config.set({"codecs.test": "package_with_entrypoint." + codec_name}) + config.set({"codecs.test": f"package_with_entrypoint.{codec_name}"}) cls_test = zarr.registry.get_codec_class("test") assert cls_test.__qualname__ == codec_name @@ -42,7 +42,7 @@ def test_entrypoint_pipeline() -> None: def test_entrypoint_buffer(buffer_name: str) -> None: config.set( { - "buffer": "package_with_entrypoint." + buffer_name, + "buffer": f"package_with_entrypoint.{buffer_name}", "ndbuffer": "package_with_entrypoint.TestEntrypointNDBuffer", } )