diff --git a/pyproject.toml b/pyproject.toml index bb9fa4df85..dc0e4730eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -269,19 +269,25 @@ extend-exclude = [ extend-select = [ "ANN", # flake8-annotations "B", # flake8-bugbear + "EXE", # flake8-executable "C4", # flake8-comprehensions + "FA", # flake8-future-annotations "FLY", # flynt "FURB", # refurb "G", # flake8-logging-format "I", # isort "ISC", # flake8-implicit-str-concat + "LOG", # flake8-logging "PERF", # Perflint + "PIE", # flake8-pie "PGH", # pygrep-hooks "PT", # flake8-pytest-style "PYI", # flake8-pyi - "RSE", # flake8-raise "RET", # flake8-return + "RSE", # flake8-raise "RUF", + "SIM", # flake8-simplify + "SLOT", # flake8-slots "TCH", # flake8-type-checking "TRY", # tryceratops "UP", # pyupgrade @@ -298,6 +304,7 @@ ignore = [ "RET505", "RET506", "RUF005", + "SIM108", "TRY003", "UP027", # deprecated "UP038", # https://github.com/astral-sh/ruff/issues/7871 @@ -319,7 +326,7 @@ ignore = [ ] [tool.ruff.lint.extend-per-file-ignores] -"tests/**" = ["ANN001", "ANN201"] +"tests/**" = ["ANN001", "ANN201", "RUF029", "SIM117", "SIM300"] [tool.mypy] python_version = "3.11" diff --git a/src/zarr/abc/codec.py b/src/zarr/abc/codec.py index f27152e84c..fabd042dbe 100644 --- a/src/zarr/abc/codec.py +++ b/src/zarr/abc/codec.py @@ -106,7 +106,6 @@ def validate(self, *, shape: ChunkCoords, dtype: np.dtype[Any], chunk_grid: Chun chunk_grid : ChunkGrid The array chunk grid """ - ... async def _decode_single(self, chunk_data: CodecOutput, chunk_spec: ArraySpec) -> CodecInput: raise NotImplementedError diff --git a/src/zarr/abc/metadata.py b/src/zarr/abc/metadata.py index 291ceb459c..a56f986645 100644 --- a/src/zarr/abc/metadata.py +++ b/src/zarr/abc/metadata.py @@ -42,6 +42,5 @@ def from_dict(cls, data: dict[str, JSON]) -> Self: """ Create an instance of the model from a dictionary """ - ... return cls(**data) diff --git a/src/zarr/api/asynchronous.py b/src/zarr/api/asynchronous.py index 434e9fdc2c..40f9b8d5f4 100644 --- a/src/zarr/api/asynchronous.py +++ b/src/zarr/api/asynchronous.py @@ -878,9 +878,8 @@ async def create( warnings.warn("meta_array is not yet implemented", RuntimeWarning, stacklevel=2) mode = kwargs.pop("mode", None) - if mode is None: - if not isinstance(store, Store | StorePath): - mode = "a" + if mode is None and not isinstance(store, Store | StorePath): + mode = "a" store_path = await make_store_path(store, path=path, mode=mode, storage_options=storage_options) diff --git a/src/zarr/codecs/gzip.py b/src/zarr/codecs/gzip.py index c0ad5e1385..b6e693148e 100644 --- a/src/zarr/codecs/gzip.py +++ b/src/zarr/codecs/gzip.py @@ -21,7 +21,7 @@ def parse_gzip_level(data: JSON) -> int: if not isinstance(data, (int)): raise TypeError(f"Expected int, got {type(data)}") - if data not in range(0, 10): + if data not in range(10): raise ValueError( f"Expected an integer from the inclusive range (0, 9). Got {data} instead." ) diff --git a/src/zarr/core/chunk_grids.py b/src/zarr/core/chunk_grids.py index ed7f8a1f45..afecc6824f 100644 --- a/src/zarr/core/chunk_grids.py +++ b/src/zarr/core/chunk_grids.py @@ -182,7 +182,7 @@ def to_dict(self) -> dict[str, JSON]: def all_chunk_coords(self, array_shape: ChunkCoords) -> Iterator[ChunkCoords]: return itertools.product( - *(range(0, ceildiv(s, c)) for s, c in zip(array_shape, self.chunk_shape, strict=False)) + *(range(ceildiv(s, c)) for s, c in zip(array_shape, self.chunk_shape, strict=False)) ) def get_nchunks(self, array_shape: ChunkCoords) -> int: diff --git a/src/zarr/core/group.py b/src/zarr/core/group.py index 86cf191ca2..1054ba980b 100644 --- a/src/zarr/core/group.py +++ b/src/zarr/core/group.py @@ -1225,7 +1225,7 @@ def _members_consolidated( # we kind of just want the top-level keys. if consolidated_metadata is not None: - for key in consolidated_metadata.metadata.keys(): + for key in consolidated_metadata.metadata: obj = self._getitem_consolidated( self.store_path, key, prefix=self.name ) # Metadata -> Group/Array diff --git a/src/zarr/core/indexing.py b/src/zarr/core/indexing.py index eda2444302..723dadfb48 100644 --- a/src/zarr/core/indexing.py +++ b/src/zarr/core/indexing.py @@ -241,12 +241,13 @@ def is_pure_fancy_indexing(selection: Any, ndim: int) -> bool: # is mask selection return True - if ndim == 1: - if is_integer_list(selection) or is_integer_array(selection) or is_bool_list(selection): - return True + if ndim == 1 and ( + is_integer_list(selection) or is_integer_array(selection) or is_bool_list(selection) + ): + return True - # if not, we go through the normal path below, because a 1-tuple - # of integers is also allowed. + # if not, we go through the normal path below, because a 1-tuple + # of integers is also allowed. no_slicing = ( isinstance(selection, tuple) and len(selection) == ndim diff --git a/src/zarr/core/metadata/__init__.py b/src/zarr/core/metadata/__init__.py index f4374d9aba..43b5ec98fe 100644 --- a/src/zarr/core/metadata/__init__.py +++ b/src/zarr/core/metadata/__init__.py @@ -8,10 +8,10 @@ T_ArrayMetadata = TypeVar("T_ArrayMetadata", ArrayV2Metadata, ArrayV3Metadata) __all__ = [ - "ArrayV2Metadata", - "ArrayV3Metadata", "ArrayMetadata", "ArrayMetadataDict", - "ArrayV3MetadataDict", + "ArrayV2Metadata", "ArrayV2MetadataDict", + "ArrayV3Metadata", + "ArrayV3MetadataDict", ] diff --git a/src/zarr/core/metadata/v3.py b/src/zarr/core/metadata/v3.py index 7a38e9fd70..6ea9ed69f1 100644 --- a/src/zarr/core/metadata/v3.py +++ b/src/zarr/core/metadata/v3.py @@ -481,9 +481,9 @@ def parse_fill_value( except (ValueError, OverflowError, TypeError) as e: raise ValueError(f"fill value {fill_value!r} is not valid for dtype {data_type}") from e # Check if the value is still representable by the dtype - if fill_value == "NaN" and np.isnan(casted_value): - pass - elif fill_value in ["Infinity", "-Infinity"] and not np.isfinite(casted_value): + if (fill_value == "NaN" and np.isnan(casted_value)) or ( + fill_value in ["Infinity", "-Infinity"] and not np.isfinite(casted_value) + ): pass elif np_dtype.kind == "f": # float comparison is not exact, especially when dtype None: assert isinstance(group, Group) for array in group.array_values(): assert_array_equal(array[:], data) - for k in kwargs.keys(): + for k in kwargs: assert k in group assert group.nmembers() == n_args + n_kwargs diff --git a/tests/test_codecs/test_codecs.py b/tests/test_codecs/test_codecs.py index 0f2f892915..dfb8e1c595 100644 --- a/tests/test_codecs/test_codecs.py +++ b/tests/test_codecs/test_codecs.py @@ -56,7 +56,6 @@ def test_sharding_pickle() -> None: """ Test that sharding codecs can be pickled """ - pass @pytest.mark.parametrize("store", ["local", "memory"], indirect=["store"]) diff --git a/tests/test_metadata/test_consolidated.py b/tests/test_metadata/test_consolidated.py index c0218602f6..d9143d09d6 100644 --- a/tests/test_metadata/test_consolidated.py +++ b/tests/test_metadata/test_consolidated.py @@ -87,31 +87,27 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None: metadata={ "air": ArrayV3Metadata.from_dict( { - **{ - "shape": (1, 2, 3), - "chunk_grid": { - "configuration": {"chunk_shape": (1, 2, 3)}, - "name": "regular", - }, + "shape": (1, 2, 3), + "chunk_grid": { + "configuration": {"chunk_shape": (1, 2, 3)}, + "name": "regular", }, **array_metadata, } ), "lat": ArrayV3Metadata.from_dict( { - **{ - "shape": (1,), - "chunk_grid": { - "configuration": {"chunk_shape": (1,)}, - "name": "regular", - }, + "shape": (1,), + "chunk_grid": { + "configuration": {"chunk_shape": (1,)}, + "name": "regular", }, **array_metadata, } ), "lon": ArrayV3Metadata.from_dict( { - **{"shape": (2,)}, + "shape": (2,), "chunk_grid": { "configuration": {"chunk_shape": (2,)}, "name": "regular", @@ -121,12 +117,10 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None: ), "time": ArrayV3Metadata.from_dict( { - **{ - "shape": (3,), - "chunk_grid": { - "configuration": {"chunk_shape": (3,)}, - "name": "regular", - }, + "shape": (3,), + "chunk_grid": { + "configuration": {"chunk_shape": (3,)}, + "name": "regular", }, **array_metadata, } @@ -138,13 +132,11 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None: "array": ArrayV3Metadata.from_dict( { **array_metadata, - **{ - "attributes": {"key": "child"}, - "shape": (4, 4), - "chunk_grid": { - "configuration": {"chunk_shape": (4, 4)}, - "name": "regular", - }, + "attributes": {"key": "child"}, + "shape": (4, 4), + "chunk_grid": { + "configuration": {"chunk_shape": (4, 4)}, + "name": "regular", }, } ), @@ -162,15 +154,11 @@ async def test_consolidated(self, memory_store_with_hierarchy: Store) -> None: "array": ArrayV3Metadata.from_dict( { **array_metadata, - **{ - "attributes": {"key": "grandchild"}, - "shape": (4, 4), - "chunk_grid": { - "configuration": { - "chunk_shape": (4, 4) - }, - "name": "regular", - }, + "attributes": {"key": "grandchild"}, + "shape": (4, 4), + "chunk_grid": { + "configuration": {"chunk_shape": (4, 4)}, + "name": "regular", }, } ), @@ -243,31 +231,27 @@ def test_consolidated_sync(self, memory_store): metadata={ "air": ArrayV3Metadata.from_dict( { - **{ - "shape": (1, 2, 3), - "chunk_grid": { - "configuration": {"chunk_shape": (1, 2, 3)}, - "name": "regular", - }, + "shape": (1, 2, 3), + "chunk_grid": { + "configuration": {"chunk_shape": (1, 2, 3)}, + "name": "regular", }, **array_metadata, } ), "lat": ArrayV3Metadata.from_dict( { - **{ - "shape": (1,), - "chunk_grid": { - "configuration": {"chunk_shape": (1,)}, - "name": "regular", - }, + "shape": (1,), + "chunk_grid": { + "configuration": {"chunk_shape": (1,)}, + "name": "regular", }, **array_metadata, } ), "lon": ArrayV3Metadata.from_dict( { - **{"shape": (2,)}, + "shape": (2,), "chunk_grid": { "configuration": {"chunk_shape": (2,)}, "name": "regular", @@ -277,12 +261,10 @@ def test_consolidated_sync(self, memory_store): ), "time": ArrayV3Metadata.from_dict( { - **{ - "shape": (3,), - "chunk_grid": { - "configuration": {"chunk_shape": (3,)}, - "name": "regular", - }, + "shape": (3,), + "chunk_grid": { + "configuration": {"chunk_shape": (3,)}, + "name": "regular", }, **array_metadata, } @@ -357,24 +339,20 @@ def test_flatten(self): metadata={ "air": ArrayV3Metadata.from_dict( { - **{ - "shape": (1, 2, 3), - "chunk_grid": { - "configuration": {"chunk_shape": (1, 2, 3)}, - "name": "regular", - }, + "shape": (1, 2, 3), + "chunk_grid": { + "configuration": {"chunk_shape": (1, 2, 3)}, + "name": "regular", }, **array_metadata, } ), "lat": ArrayV3Metadata.from_dict( { - **{ - "shape": (1,), - "chunk_grid": { - "configuration": {"chunk_shape": (1,)}, - "name": "regular", - }, + "shape": (1,), + "chunk_grid": { + "configuration": {"chunk_shape": (1,)}, + "name": "regular", }, **array_metadata, } @@ -386,13 +364,11 @@ def test_flatten(self): "array": ArrayV3Metadata.from_dict( { **array_metadata, - **{ - "attributes": {"key": "child"}, - "shape": (4, 4), - "chunk_grid": { - "configuration": {"chunk_shape": (4, 4)}, - "name": "regular", - }, + "attributes": {"key": "child"}, + "shape": (4, 4), + "chunk_grid": { + "configuration": {"chunk_shape": (4, 4)}, + "name": "regular", }, } ), @@ -403,13 +379,11 @@ def test_flatten(self): "array": ArrayV3Metadata.from_dict( { **array_metadata, - **{ - "attributes": {"key": "grandchild"}, - "shape": (4, 4), - "chunk_grid": { - "configuration": {"chunk_shape": (4, 4)}, - "name": "regular", - }, + "attributes": {"key": "grandchild"}, + "shape": (4, 4), + "chunk_grid": { + "configuration": {"chunk_shape": (4, 4)}, + "name": "regular", }, } )