Skip to content

Commit faec389

Browse files
chore: update ruff and fix new ruff issues (#3739)
* Apply ruff/pyupgrade rule UP042 Class inherits from both `str` and `enum.Enum` * Apply ruff/refurb rule FURB110 Replace ternary `if` expression with `or` operator * Apply ruff/refurb rule FURB171 Membership test against single-item container * Apply ruff preview rule RUF068 `__all__` contains duplicate entries * Apply ruff/refurb preview rule FURB140 Use `itertools.starmap` instead of the generator * Bump ruff: 0.14.14 → 0.15.4 * Update tests/test_examples.py Co-authored-by: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> --------- Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
1 parent b8094d8 commit faec389

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ default_language_version:
1111

1212
repos:
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.14.14
14+
rev: v0.15.4
1515
hooks:
1616
- id: ruff-check
1717
args: ["--fix", "--show-fixes"]

src/zarr/_cli/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from enum import Enum
2+
from enum import StrEnum
33
from typing import Annotated, Literal, cast
44

55
import typer
@@ -24,12 +24,12 @@ def _set_logging_level(*, verbose: bool) -> None:
2424
zarr.set_format("%(message)s")
2525

2626

27-
class CLIZarrFormat(str, Enum):
27+
class CLIZarrFormat(StrEnum):
2828
v2 = "v2"
2929
v3 = "v3"
3030

3131

32-
class CLIZarrFormatV3(str, Enum):
32+
class CLIZarrFormatV3(StrEnum):
3333
"""Limit CLI choice to only v3"""
3434

3535
v3 = "v3"

src/zarr/core/chunk_key_encodings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ChunkKeyEncoding(ABC, Metadata):
4242
@classmethod
4343
def from_dict(cls, data: dict[str, JSON]) -> Self:
4444
_, config_parsed = parse_named_configuration(data, require_configuration=False)
45-
return cls(**config_parsed if config_parsed else {})
45+
return cls(**config_parsed or {})
4646

4747
def to_dict(self) -> dict[str, JSON]:
4848
return {"name": self.name, "configuration": super().to_dict()}

src/zarr/core/dtype/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
"TBaseDType",
8282
"TBaseScalar",
8383
"TimeDelta64",
84-
"TimeDelta64",
8584
"TimeDelta64JSON_V2",
8685
"TimeDelta64JSON_V3",
8786
"UInt8",

src/zarr/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _iter_regions(
209209
# ((slice(0, 1, 1), slice(0, 2, 1)), (slice(1, 2, 1), slice(0, 2, 1)))
210210
```
211211
"""
212-
grid_shape = tuple(ceildiv(d, s) for d, s in zip(domain_shape, region_shape, strict=True))
212+
grid_shape = tuple(itertools.starmap(ceildiv, zip(domain_shape, region_shape, strict=True)))
213213
for grid_position in _iter_grid(
214214
grid_shape=grid_shape, origin=origin, selection_shape=selection_shape, order=order
215215
):

src/zarr/dtype.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
"StructuredJSON_V2",
7373
"StructuredJSON_V3",
7474
"TimeDelta64",
75-
"TimeDelta64",
7675
"TimeDelta64JSON_V2",
7776
"TimeDelta64JSON_V3",
7877
"UInt8",
@@ -85,6 +84,5 @@
8584
"VariableLengthUTF8JSON_V2",
8685
"ZDType",
8786
"data_type_registry",
88-
"data_type_registry",
8987
"parse_dtype",
9088
]

tests/test_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,7 @@ def test_auto_chunks(f: Callable[..., AnyArray]) -> None:
15291529
array = np.zeros(shape, dtype=dtype)
15301530
store = zarr.storage.MemoryStore()
15311531

1532+
# ruff: disable[FURB171]
15321533
if f in [zarr.full, zarr.full_like]:
15331534
kwargs["fill_value"] = 0
15341535
if f in [zarr.array]:
@@ -1537,6 +1538,7 @@ def test_auto_chunks(f: Callable[..., AnyArray]) -> None:
15371538
kwargs["a"] = array
15381539
if f in [zarr.create_array]:
15391540
kwargs["store"] = store
1541+
# ruff: enable[FURB171]
15401542

15411543
a = f(**kwargs)
15421544
assert a.chunks == (500, 500)

tests/test_array.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pickle
77
import re
88
import sys
9-
from itertools import accumulate
9+
from itertools import accumulate, starmap
1010
from typing import TYPE_CHECKING, Any, Literal
1111
from unittest import mock
1212

@@ -2064,12 +2064,12 @@ def test_chunk_grid_shape(
20642064
zarr_format=zarr_format,
20652065
)
20662066

2067-
chunk_grid_shape = tuple(ceildiv(a, b) for a, b in zip(array_shape, chunk_shape, strict=True))
2067+
chunk_grid_shape = tuple(starmap(ceildiv, zip(array_shape, chunk_shape, strict=True)))
20682068
if shard_shape is None:
20692069
_shard_shape = chunk_shape
20702070
else:
20712071
_shard_shape = shard_shape
2072-
shard_grid_shape = tuple(ceildiv(a, b) for a, b in zip(array_shape, _shard_shape, strict=True))
2072+
shard_grid_shape = tuple(starmap(ceildiv, zip(array_shape, _shard_shape, strict=True)))
20732073
assert arr._chunk_grid_shape == chunk_grid_shape
20742074
assert arr.cdata_shape == chunk_grid_shape
20752075
assert arr.async_array.cdata_shape == chunk_grid_shape

tests/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def test_script_paths() -> None:
7070

7171

7272
@pytest.mark.skipif(
73-
sys.platform in ("win32",), reason="This test fails due for unknown reasons on Windows in CI."
73+
sys.platform == "win32", reason="This test fails for unknown reasons on Windows in CI."
7474
)
7575
@pytest.mark.parametrize("script_path", script_paths)
7676
def test_scripts_can_run(script_path: Path, tmp_path: Path) -> None:

tests/test_properties.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import itertools
12
import json
23
import numbers
34
from typing import Any
@@ -60,7 +61,7 @@ def deep_equal(a: Any, b: Any) -> bool:
6061
if isinstance(a, np.ndarray) and isinstance(b, np.ndarray):
6162
if a.shape != b.shape:
6263
return False
63-
return all(deep_equal(x, y) for x, y in zip(a.flat, b.flat, strict=False))
64+
return all(itertools.starmap(deep_equal, zip(a.flat, b.flat, strict=False)))
6465

6566
if isinstance(a, dict) and isinstance(b, dict):
6667
if set(a.keys()) != set(b.keys()):
@@ -70,7 +71,7 @@ def deep_equal(a: Any, b: Any) -> bool:
7071
if isinstance(a, (list, tuple)) and isinstance(b, (list, tuple)):
7172
if len(a) != len(b):
7273
return False
73-
return all(deep_equal(x, y) for x, y in zip(a, b, strict=False))
74+
return all(itertools.starmap(deep_equal, zip(a, b, strict=False)))
7475

7576
return a == b
7677

0 commit comments

Comments
 (0)