Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ruff/flake8-implicit-str-concat rules (ISC) and fix issues #1868

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ extend-exclude = [
extend-select = [
"B", # flake8-bugbear
"I", # isort
"ISC",
"UP", # pyupgrade
"RSE",
"RUF",
Expand Down
3 changes: 1 addition & 2 deletions src/zarr/codecs/crc32c_.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ async def decode_single(
stored_checksum = bytes(crc32_bytes)
if computed_checksum != stored_checksum:
raise ValueError(
"Stored and computed checksum do not match. "
+ f"Stored: {stored_checksum!r}. Computed: {computed_checksum!r}."
f"Stored and computed checksum do not match. Stored: {stored_checksum!r}. Computed: {computed_checksum!r}."
)
return Buffer.from_array_like(inner_bytes)

Expand Down
15 changes: 5 additions & 10 deletions src/zarr/codecs/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,26 @@ def codecs_from_list(
if prev_codec is not None:
if isinstance(codec, ArrayBytesCodec) and isinstance(prev_codec, ArrayBytesCodec):
raise ValueError(
f"ArrayBytesCodec '{type(codec)}' cannot follow after "
+ f"ArrayBytesCodec '{type(prev_codec)}' because exactly "
+ "1 ArrayBytesCodec is allowed."
f"ArrayBytesCodec '{type(codec)}' cannot follow after ArrayBytesCodec '{type(prev_codec)}' because exactly 1 ArrayBytesCodec is allowed."
)
if isinstance(codec, ArrayBytesCodec) and isinstance(prev_codec, BytesBytesCodec):
raise ValueError(
f"ArrayBytesCodec '{type(codec)}' cannot follow after "
+ f"BytesBytesCodec '{type(prev_codec)}'."
f"ArrayBytesCodec '{type(codec)}' cannot follow after BytesBytesCodec '{type(prev_codec)}'."
)
if isinstance(codec, ArrayArrayCodec) and isinstance(prev_codec, ArrayBytesCodec):
raise ValueError(
f"ArrayArrayCodec '{type(codec)}' cannot follow after "
+ f"ArrayBytesCodec '{type(prev_codec)}'."
f"ArrayArrayCodec '{type(codec)}' cannot follow after ArrayBytesCodec '{type(prev_codec)}'."
)
if isinstance(codec, ArrayArrayCodec) and isinstance(prev_codec, BytesBytesCodec):
raise ValueError(
f"ArrayArrayCodec '{type(codec)}' cannot follow after "
+ f"BytesBytesCodec '{type(prev_codec)}'."
f"ArrayArrayCodec '{type(codec)}' cannot follow after BytesBytesCodec '{type(prev_codec)}'."
)
prev_codec = codec

if any(isinstance(codec, ShardingCodec) for codec in codecs) and len(codecs) > 1:
warn(
"Combining a `sharding_indexed` codec disables partial reads and "
+ "writes, which may lead to inefficient performance.",
"writes, which may lead to inefficient performance.",
stacklevel=3,
)

Expand Down
6 changes: 2 additions & 4 deletions src/zarr/codecs/sharding.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ def evolve(self, array_spec: ArraySpec) -> Self:
def validate(self, array_metadata: ArrayMetadata) -> None:
if len(self.chunk_shape) != array_metadata.ndim:
raise ValueError(
"The shard's `chunk_shape` and array's `shape` need to have the "
+ "same number of dimensions."
"The shard's `chunk_shape` and array's `shape` need to have the same number of dimensions."
)
if not isinstance(array_metadata.chunk_grid, RegularChunkGrid):
raise ValueError("Sharding is only compatible with regular chunk grids.")
Expand All @@ -375,8 +374,7 @@ def validate(self, array_metadata: ArrayMetadata) -> None:
)
):
raise ValueError(
"The array's `chunk_shape` needs to be divisible by the "
+ "shard's inner `chunk_shape`."
"The array's `chunk_shape` needs to be divisible by the shard's inner `chunk_shape`."
)

async def decode_single(
Expand Down
6 changes: 2 additions & 4 deletions src/zarr/codecs/transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,15 @@ def to_dict(self) -> dict[str, JSON]:
def evolve(self, array_spec: ArraySpec) -> Self:
if len(self.order) != array_spec.ndim:
raise ValueError(
"The `order` tuple needs have as many entries as "
+ f"there are dimensions in the array. Got {self.order}."
f"The `order` tuple needs have as many entries as there are dimensions in the array. Got {self.order}."
)
if len(self.order) != len(set(self.order)):
raise ValueError(
f"There must not be duplicates in the `order` tuple. Got {self.order}."
)
if not all(0 <= x < array_spec.ndim for x in self.order):
raise ValueError(
"All entries in the `order` tuple must be between 0 and "
+ f"the number of dimensions in the array. Got {self.order}."
f"All entries in the `order` tuple must be between 0 and the number of dimensions in the array. Got {self.order}."
)
order = tuple(self.order)

Expand Down
7 changes: 3 additions & 4 deletions src/zarr/store/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ def __init__(self, url: UPath | str, **storage_options: dict[str, Any]):
if isinstance(url, str):
self.root = UPath(url, **storage_options)
else:
assert len(storage_options) == 0, (
"If constructed with a UPath object, no additional "
+ "storage_options are allowed."
)
assert (
len(storage_options) == 0
), "If constructed with a UPath object, no additional storage_options are allowed."
self.root = url.rstrip("/")
# test instantiate file system
fs, _ = fsspec.core.url_to_fs(str(self.root), asynchronous=True, **self.root._kwargs)
Expand Down
6 changes: 3 additions & 3 deletions src/zarr/v2/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def __init__(self, log):
self.log_file = log
else:
raise TypeError(
"log must be a callable function, file path or " "file-like object, found %r" % log
"log must be a callable function, file path or file-like object, found %r" % log
)

def __enter__(self):
Expand Down Expand Up @@ -898,7 +898,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
if exists:
if if_exists == "raise":
raise CopyError(
"an object {!r} already exists in destination " "{!r}".format(name, dest.name)
"an object {!r} already exists in destination {!r}".format(name, dest.name)
)
elif if_exists == "skip":
do_copy = False
Expand Down Expand Up @@ -990,7 +990,7 @@ def _copy(log, source, dest, name, root, shallow, without_attrs, if_exists, dry_
if exists_array:
if if_exists == "raise":
raise CopyError(
"an array {!r} already exists in destination " "{!r}".format(name, dest.name)
"an array {!r} already exists in destination {!r}".format(name, dest.name)
)
elif if_exists == "skip":
do_copy = False
Expand Down
14 changes: 4 additions & 10 deletions src/zarr/v2/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,12 @@ class BoolArrayDimIndexer:
def __init__(self, dim_sel, dim_len, dim_chunk_len):
# check number of dimensions
if not is_bool_array(dim_sel, 1):
raise IndexError(
"Boolean arrays in an orthogonal selection must " "be 1-dimensional only"
)
raise IndexError("Boolean arrays in an orthogonal selection must be 1-dimensional only")

# check shape
if dim_sel.shape[0] != dim_len:
raise IndexError(
"Boolean array has the wrong length for dimension; " "expected {}, got {}".format(
"Boolean array has the wrong length for dimension; expected {}, got {}".format(
dim_len, dim_sel.shape[0]
)
)
Expand Down Expand Up @@ -464,9 +462,7 @@ def __init__(
# ensure 1d array
dim_sel = np.asanyarray(dim_sel)
if not is_integer_array(dim_sel, 1):
raise IndexError(
"integer arrays in an orthogonal selection must be " "1-dimensional only"
)
raise IndexError("integer arrays in an orthogonal selection must be 1-dimensional only")

# handle wraparound
if wraparound:
Expand Down Expand Up @@ -920,9 +916,7 @@ def check_fields(fields, dtype):
# check type
if not isinstance(fields, (str, list, tuple)):
raise IndexError(
"'fields' argument must be a string or list of strings; found " "{!r}".format(
type(fields)
)
"'fields' argument must be a string or list of strings; found {!r}".format(type(fields))
)
if fields:
if dtype.names is None:
Expand Down
4 changes: 2 additions & 2 deletions src/zarr/v2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def normalize_fill_value(fill_value, dtype: np.dtype[Any]):

if not isinstance(fill_value, str):
raise ValueError(
"fill_value {!r} is not valid for dtype {}; must be a " "unicode string".format(
"fill_value {!r} is not valid for dtype {}; must be a unicode string".format(
fill_value, dtype
)
)
Expand All @@ -323,7 +323,7 @@ def normalize_fill_value(fill_value, dtype: np.dtype[Any]):
except Exception as e:
# re-raise with our own error message to be helpful
raise ValueError(
"fill_value {!r} is not valid for dtype {}; nested " "exception: {}".format(
"fill_value {!r} is not valid for dtype {}; nested exception: {}".format(
fill_value, dtype, e
)
)
Expand Down
Loading