Skip to content

Commit 637879c

Browse files
Apply Sourcery suggestions and fix typos
1 parent 27615fd commit 637879c

File tree

18 files changed

+34
-36
lines changed

18 files changed

+34
-36
lines changed

src/zarr/abc/metadata.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ def to_dict(self) -> dict[str, JSON]:
2828
value = getattr(self, key)
2929
if isinstance(value, Metadata):
3030
out_dict[field.name] = getattr(self, field.name).to_dict()
31-
elif isinstance(value, str):
32-
out_dict[key] = value
3331
elif isinstance(value, Sequence):
3432
out_dict[key] = tuple(v.to_dict() if isinstance(v, Metadata) else v for v in value)
3533
else:

src/zarr/codecs/sharding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class _ShardIndex(NamedTuple):
115115

116116
@property
117117
def chunks_per_shard(self) -> ChunkCoords:
118-
result = tuple(self.offsets_and_lengths.shape[0:-1])
118+
result = tuple(self.offsets_and_lengths.shape[:-1])
119119
# The cast is required until https://github.com/numpy/numpy/pull/27211 is merged
120120
return cast("ChunkCoords", result)
121121

@@ -421,8 +421,8 @@ def validate(
421421
)
422422
if not isinstance(chunk_grid, RegularChunkGrid):
423423
raise TypeError("Sharding is only compatible with regular chunk grids.")
424-
if not all(
425-
s % c == 0
424+
if any(
425+
s % c != 0
426426
for s, c in zip(
427427
chunk_grid.chunk_shape,
428428
self.chunk_shape,

src/zarr/core/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ async def _create(
660660
overwrite=overwrite,
661661
)
662662
else:
663-
raise ValueError(f"Insupported zarr_format. Got: {zarr_format}")
663+
raise ValueError(f"Unsupported zarr_format. Got: {zarr_format}")
664664

665665
if data is not None:
666666
# insert user-provided data

src/zarr/core/buffer/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def check_item_key_is_1d_contiguous(key: Any) -> None:
115115
raise TypeError(
116116
f"Item key has incorrect type (expected slice, got {key.__class__.__name__})"
117117
)
118-
if not (key.step is None or key.step == 1):
118+
if key.step is not None and key.step != 1:
119119
raise ValueError("slice must be contiguous")
120120

121121

src/zarr/core/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def parse_shapelike(data: int | Iterable[int]) -> tuple[int, ...]:
154154
if not all(isinstance(v, int) for v in data_tuple):
155155
msg = f"Expected an iterable of integers. Got {data} instead."
156156
raise TypeError(msg)
157-
if not all(v > -1 for v in data_tuple):
157+
if any(v < 0 for v in data_tuple):
158158
msg = f"Expected all values to be non-negative. Got {data} instead."
159159
raise ValueError(msg)
160160
return data_tuple

src/zarr/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def replace_ellipsis(selection: Any, shape: ChunkCoords) -> SelectionNormalized:
436436
selection = ensure_tuple(selection)
437437

438438
# count number of ellipsis present
439-
n_ellipsis = sum(1 for i in selection if i is Ellipsis)
439+
n_ellipsis = selection.count(Ellipsis)
440440

441441
if n_ellipsis > 1:
442442
# more than 1 is an error

src/zarr/core/metadata/v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ def parse_filters(data: object) -> tuple[numcodecs.abc.Codec, ...] | None:
266266
"""
267267
Parse a potential tuple of filters
268268
"""
269-
out: list[numcodecs.abc.Codec] = []
270269

271270
if data is None:
272271
return data
273272
if isinstance(data, Iterable):
273+
out: list[numcodecs.abc.Codec] = []
274274
for idx, val in enumerate(data):
275275
if isinstance(val, numcodecs.abc.Codec):
276276
out.append(val)

src/zarr/core/metadata/v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def validate_codecs(codecs: tuple[Codec, ...], dtype: ZDType[TBaseDType, TBaseSc
9494
# TODO: use codec ID instead of class name
9595
codec_class_name = abc.__class__.__name__
9696
# TODO: Fix typing here
97-
if isinstance(dtype, VariableLengthUTF8) and not codec_class_name == "VLenUTF8Codec": # type: ignore[unreachable]
97+
if isinstance(dtype, VariableLengthUTF8) not codec_class_name != "VLenUTF8Codec": # type: ignore[unreachable]
9898
raise ValueError(
9999
f"For string dtype, ArrayBytesCodec must be `VLenUTF8Codec`, got `{codec_class_name}`."
100100
)

src/zarr/registry.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ def _parse_bytes_bytes_codec(data: dict[str, JSON] | Codec) -> BytesBytesCodec:
190190
if not isinstance(result, BytesBytesCodec):
191191
msg = f"Expected a dict representation of a BytesBytesCodec; got a dict representation of a {type(result)} instead."
192192
raise TypeError(msg)
193+
elif not isinstance(data, BytesBytesCodec):
194+
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
193195
else:
194-
if not isinstance(data, BytesBytesCodec):
195-
raise TypeError(f"Expected a BytesBytesCodec. Got {type(data)} instead.")
196196
result = data
197197
return result
198198

@@ -210,9 +210,9 @@ def _parse_array_bytes_codec(data: dict[str, JSON] | Codec) -> ArrayBytesCodec:
210210
if not isinstance(result, ArrayBytesCodec):
211211
msg = f"Expected a dict representation of a ArrayBytesCodec; got a dict representation of a {type(result)} instead."
212212
raise TypeError(msg)
213+
elif not isinstance(data, ArrayBytesCodec):
214+
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
213215
else:
214-
if not isinstance(data, ArrayBytesCodec):
215-
raise TypeError(f"Expected a ArrayBytesCodec. Got {type(data)} instead.")
216216
result = data
217217
return result
218218

@@ -230,9 +230,9 @@ def _parse_array_array_codec(data: dict[str, JSON] | Codec) -> ArrayArrayCodec:
230230
if not isinstance(result, ArrayArrayCodec):
231231
msg = f"Expected a dict representation of a ArrayArrayCodec; got a dict representation of a {type(result)} instead."
232232
raise TypeError(msg)
233+
elif not isinstance(data, ArrayArrayCodec):
234+
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
233235
else:
234-
if not isinstance(data, ArrayArrayCodec):
235-
raise TypeError(f"Expected a ArrayArrayCodec. Got {type(data)} instead.")
236236
result = data
237237
return result
238238

src/zarr/storage/_fsspec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ async def set_partial_values(
429429
async def list(self) -> AsyncIterator[str]:
430430
# docstring inherited
431431
allfiles = await self.fs._find(self.path, detail=False, withdirs=False)
432-
for onefile in (a.removeprefix(self.path + "/") for a in allfiles):
432+
for onefile in (a.removeprefix(f"{self.path}/") for a in allfiles):
433433
yield onefile
434434

435435
async def list_dir(self, prefix: str) -> AsyncIterator[str]:
@@ -439,7 +439,7 @@ async def list_dir(self, prefix: str) -> AsyncIterator[str]:
439439
allfiles = await self.fs._ls(prefix, detail=False)
440440
except FileNotFoundError:
441441
return
442-
for onefile in (a.replace(prefix + "/", "") for a in allfiles):
442+
for onefile in (a.replace(f"{prefix}/", "") for a in allfiles):
443443
yield onefile.removeprefix(self.path).removeprefix("/")
444444

445445
async def list_prefix(self, prefix: str) -> AsyncIterator[str]:

0 commit comments

Comments
 (0)