diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a026de6ff3..9147f6e825 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -39,7 +39,7 @@ repos: additional_dependencies: [pyyaml] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.277 + rev: v0.0.281 hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -74,6 +74,6 @@ repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.9.0 + rev: v3.10.1 hooks: - id: pyupgrade diff --git a/dev/generate-kernel-signatures.py b/dev/generate-kernel-signatures.py index 8a7479bd93..47a010452f 100644 --- a/dev/generate-kernel-signatures.py +++ b/dev/generate-kernel-signatures.py @@ -130,7 +130,7 @@ def include_kernels_h(specification): "w", ) as header: header.write( - """// AUTO GENERATED ON {0} + f"""// AUTO GENERATED ON {reproducible_datetime()} // DO NOT EDIT BY HAND! // // To regenerate file, run @@ -146,9 +146,7 @@ def include_kernels_h(specification): extern "C" {{ -""".format( - reproducible_datetime() - ) +""" ) for spec in specification["kernels"]: for childfunc in spec["specializations"]: @@ -217,7 +215,7 @@ def kernel_signatures_py(specification): "w", ) as file: file.write( - """# AUTO GENERATED ON {0} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -272,9 +270,7 @@ class ERROR(Structure): def by_signature(lib): out = {{}} -""".format( - reproducible_datetime() - ) +""" ) for spec in specification["kernels"]: diff --git a/dev/generate-tests.py b/dev/generate-tests.py index dc168c99eb..d4df2bcd19 100644 --- a/dev/generate-tests.py +++ b/dev/generate-tests.py @@ -234,7 +234,7 @@ def genpykernels(): os.mkdir(tests_spec) with open(os.path.join(tests_spec, "__init__.py"), "w") as f: f.write( - """# AUTO GENERATED ON {} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -244,9 +244,7 @@ def genpykernels(): # fmt: off -""".format( - reproducible_datetime() - ) +""" ) with open( @@ -323,7 +321,7 @@ def genspectests(specdict): "w", ) as f: f.write( - """# AUTO GENERATED ON {} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -333,9 +331,7 @@ def genspectests(specdict): # fmt: off -""".format( - reproducible_datetime() - ) +""" ) f.write("import pytest\nimport kernels\n\n") num = 1 @@ -437,7 +433,7 @@ def gencpukerneltests(specdict): os.mkdir(tests_cpu_kernels) with open(os.path.join(tests_cpu_kernels, "__init__.py"), "w") as f: f.write( - """# AUTO GENERATED ON {} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -447,9 +443,7 @@ def gencpukerneltests(specdict): # fmt: off -""".format( - reproducible_datetime() - ) +""" ) for spec in specdict.values(): @@ -457,7 +451,7 @@ def gencpukerneltests(specdict): os.path.join(tests_cpu_kernels, "test_cpu" + spec.name + ".py"), "w" ) as f: f.write( - """# AUTO GENERATED ON {} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -467,9 +461,7 @@ def gencpukerneltests(specdict): # fmt: off -""".format( - reproducible_datetime() - ) +""" ) f.write( @@ -637,7 +629,7 @@ def gencudakerneltests(specdict): os.mkdir(tests_cuda_kernels) with open(os.path.join(tests_cuda_kernels, "__init__.py"), "w") as f: f.write( - """# AUTO GENERATED ON {} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -647,9 +639,7 @@ def gencudakerneltests(specdict): # fmt: off -""".format( - reproducible_datetime() - ) +""" ) for spec in specdict.values(): @@ -658,7 +648,7 @@ def gencudakerneltests(specdict): os.path.join(tests_cuda_kernels, "test_cuda" + spec.name + ".py"), "w" ) as f: f.write( - """# AUTO GENERATED ON {} + f"""# AUTO GENERATED ON {reproducible_datetime()} # DO NOT EDIT BY HAND! # # To regenerate file, run @@ -668,9 +658,7 @@ def gencudakerneltests(specdict): # fmt: off -""".format( - reproducible_datetime() - ) +""" ) f.write( diff --git a/src/awkward/_backends/backend.py b/src/awkward/_backends/backend.py index b7079e8288..9350a1beae 100644 --- a/src/awkward/_backends/backend.py +++ b/src/awkward/_backends/backend.py @@ -14,7 +14,7 @@ numpy = Numpy.instance() -T = TypeVar("T", covariant=True) +T_co = TypeVar("T_co", covariant=True) KernelKeyType: TypeAlias = Tuple[str, Unpack[Tuple[np.dtype, ...]]] KernelType: TypeAlias = "Callable[..., KernelError | None]" diff --git a/src/awkward/_connect/numba/arrayview.py b/src/awkward/_connect/numba/arrayview.py index 7311815007..59812ac7c4 100644 --- a/src/awkward/_connect/numba/arrayview.py +++ b/src/awkward/_connect/numba/arrayview.py @@ -239,9 +239,7 @@ def repr_behavior(behavior): class ArrayViewType(numba.types.IterableType, numba.types.Sized): def __init__(self, type, behavior, fields): super().__init__( - name="ak.ArrayView({}, {}, {})".format( - type.name, repr_behavior(behavior), repr(fields) - ) + name=f"ak.ArrayView({type.name}, {repr_behavior(behavior)}, {fields!r})" ) self.type = type self.behavior = behavior diff --git a/src/awkward/_do.py b/src/awkward/_do.py index 54f7e0c9f0..aa4b645fa4 100644 --- a/src/awkward/_do.py +++ b/src/awkward/_do.py @@ -172,9 +172,7 @@ def unique(layout: Content, axis=None): negaxis = negaxis + depth if not (0 < negaxis and negaxis <= depth): raise AxisError( - "axis={} exceeds the depth of this array ({})".format( - axis, depth - ) + f"axis={axis} exceeds the depth of this array ({depth})" ) starts = ak.index.Index64.zeros(1, nplike=layout._backend.index_nplike) @@ -185,9 +183,7 @@ def unique(layout: Content, axis=None): return layout._unique(negaxis, starts, parents, 1) raise AxisError( - "unique expects axis 'None' or '-1', got axis={} that is not supported yet".format( - axis - ) + f"unique expects axis 'None' or '-1', got axis={axis} that is not supported yet" ) diff --git a/src/awkward/contents/content.py b/src/awkward/contents/content.py index de558fe176..e6211f3e6c 100644 --- a/src/awkward/contents/content.py +++ b/src/awkward/contents/content.py @@ -218,9 +218,7 @@ def getkey(layout): else: raise TypeError( - "form_key must be None, a string, or a callable, not {}".format( - type(form_key) - ) + f"form_key must be None, a string, or a callable, not {type(form_key)}" ) return self._form_with_key(getkey) @@ -268,11 +266,7 @@ def _repr_extra(self, indent: str) -> list[str]: out = [] if self._parameters is not None: for k, v in self._parameters.items(): - out.append( - "\n{}{}".format( - indent, repr(k), repr(v) - ) - ) + out.append(f"\n{indent}{v!r}") return out def maybe_to_NumpyArray(self): diff --git a/src/awkward/contents/indexedarray.py b/src/awkward/contents/indexedarray.py index 4918a0c838..e1a47c4840 100644 --- a/src/awkward/contents/indexedarray.py +++ b/src/awkward/contents/indexedarray.py @@ -965,9 +965,7 @@ def _validity_error(self, path): errors="surrogateescape" ).lstrip("\n").lstrip("(") message = error.str.decode(errors="surrogateescape") - return 'at {} ("{}"): {} at i={}{}'.format( - path, type(self), message, error.id, filename - ) + return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}' else: return self._content._validity_error(path + ".content") diff --git a/src/awkward/contents/indexedoptionarray.py b/src/awkward/contents/indexedoptionarray.py index 5b7e7b3df3..b1a0783001 100644 --- a/src/awkward/contents/indexedoptionarray.py +++ b/src/awkward/contents/indexedoptionarray.py @@ -1480,9 +1480,7 @@ def _validity_error(self, path): errors="surrogateescape" ).lstrip("\n").lstrip("(") message = error.str.decode(errors="surrogateescape") - return 'at {} ("{}"): {} at i={}{}'.format( - path, type(self), message, error.id, filename - ) + return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}' else: return self._content._validity_error(path + ".content") diff --git a/src/awkward/contents/listarray.py b/src/awkward/contents/listarray.py index 595f463730..814112a8fa 100644 --- a/src/awkward/contents/listarray.py +++ b/src/awkward/contents/listarray.py @@ -1357,9 +1357,7 @@ def _validity_error(self, path): errors="surrogateescape" ).lstrip("\n").lstrip("(") message = error.str.decode(errors="surrogateescape") - return 'at {} ("{}"): {} at i={}{}'.format( - path, type(self), message, error.id, filename - ) + return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}' else: return self._content._validity_error(path + ".content") diff --git a/src/awkward/contents/listoffsetarray.py b/src/awkward/contents/listoffsetarray.py index 4a2ab99358..cdaf7ab9a4 100644 --- a/src/awkward/contents/listoffsetarray.py +++ b/src/awkward/contents/listoffsetarray.py @@ -116,9 +116,7 @@ def __init__(self, offsets, content, *, parameters=None): ) if offsets.length is not unknown_length and offsets.length == 0: raise ValueError( - "{} len(offsets) ({}) must be >= 1".format( - type(self).__name__, offsets.length - ) + f"{type(self).__name__} len(offsets) ({offsets.length}) must be >= 1" ) if parameters is not None and parameters.get("__array__") == "string": @@ -1758,9 +1756,7 @@ def _validity_error(self, path): errors="surrogateescape" ).lstrip("\n").lstrip("(") message = error.str.decode(errors="surrogateescape") - return 'at {} ("{}"): {} at i={}{}'.format( - path, type(self), message, error.id, filename - ) + return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}' else: return self._content._validity_error(path + ".content") diff --git a/src/awkward/contents/unionarray.py b/src/awkward/contents/unionarray.py index a8add73bd1..e8237d1c2d 100644 --- a/src/awkward/contents/unionarray.py +++ b/src/awkward/contents/unionarray.py @@ -1400,9 +1400,7 @@ def _validity_error(self, path): errors="surrogateescape" ).lstrip("\n").lstrip("(") message = error.str.decode(errors="surrogateescape") - return 'at {} ("{}"): {} at i={}{}'.format( - path, type(self), message, error.id, filename - ) + return f'at {path} ("{type(self)}"): {message} at i={error.id}{filename}' # Check triangular pairs (i, j) are not mergeable for i, content_i in enumerate(self._contents): diff --git a/src/awkward/forms/bitmaskedform.py b/src/awkward/forms/bitmaskedform.py index 72ac02b372..9c2ed21875 100644 --- a/src/awkward/forms/bitmaskedform.py +++ b/src/awkward/forms/bitmaskedform.py @@ -22,9 +22,7 @@ def __init__( ): if not isinstance(mask, str): raise TypeError( - "{} 'mask' must be of type str, not {}".format( - type(self).__name__, repr(mask) - ) + f"{type(self).__name__} 'mask' must be of type str, not {mask!r}" ) if not isinstance(content, Form): raise TypeError( @@ -40,9 +38,7 @@ def __init__( ) if not isinstance(lsb_order, bool): raise TypeError( - "{} 'lsb_order' must be bool, not {}".format( - type(self).__name__, repr(lsb_order) - ) + f"{type(self).__name__} 'lsb_order' must be bool, not {lsb_order!r}" ) self._mask = mask diff --git a/src/awkward/forms/bytemaskedform.py b/src/awkward/forms/bytemaskedform.py index 511c04762f..28a7f25f49 100644 --- a/src/awkward/forms/bytemaskedform.py +++ b/src/awkward/forms/bytemaskedform.py @@ -21,9 +21,7 @@ def __init__( ): if not isinstance(mask, str): raise TypeError( - "{} 'mask' must be of type str, not {}".format( - type(self).__name__, repr(mask) - ) + f"{type(self).__name__} 'mask' must be of type str, not {mask!r}" ) if not isinstance(content, Form): raise TypeError( diff --git a/src/awkward/forms/indexedform.py b/src/awkward/forms/indexedform.py index a972606a81..4903dbb5f7 100644 --- a/src/awkward/forms/indexedform.py +++ b/src/awkward/forms/indexedform.py @@ -21,9 +21,7 @@ def __init__( ): if not isinstance(index, str): raise TypeError( - "{} 'index' must be of type str, not {}".format( - type(self).__name__, repr(index) - ) + f"{type(self).__name__} 'index' must be of type str, not {index!r}" ) if not isinstance(content, Form): raise TypeError( diff --git a/src/awkward/forms/indexedoptionform.py b/src/awkward/forms/indexedoptionform.py index dc68beb139..80a791c78e 100644 --- a/src/awkward/forms/indexedoptionform.py +++ b/src/awkward/forms/indexedoptionform.py @@ -21,9 +21,7 @@ def __init__( ): if not isinstance(index, str): raise TypeError( - "{} 'index' must be of type str, not {}".format( - type(self).__name__, repr(index) - ) + f"{type(self).__name__} 'index' must be of type str, not {index!r}" ) if not isinstance(content, Form): raise TypeError( diff --git a/src/awkward/forms/recordform.py b/src/awkward/forms/recordform.py index 7032a45f0e..0878464bb2 100644 --- a/src/awkward/forms/recordform.py +++ b/src/awkward/forms/recordform.py @@ -37,9 +37,7 @@ def __init__( ) if fields is not None and not isinstance(fields, Iterable): raise TypeError( - "{} 'fields' must be iterable, not {}".format( - type(self).__name__, repr(contents) - ) + f"{type(self).__name__} 'fields' must be iterable, not {contents!r}" ) self._fields = None if fields is None else list(fields) @@ -99,9 +97,7 @@ def index_to_field(self, index): return self._fields[index] else: raise IndexError( - "no index {} in record with {} fields".format( - index, len(self._contents) - ) + f"no index {index} in record with {len(self._contents)} fields" ) def field_to_index(self, field): @@ -121,9 +117,7 @@ def field_to_index(self, field): else: return i raise FieldNotFoundError( - "no field {} in record with {} fields".format( - repr(field), len(self._contents) - ) + f"no field {field!r} in record with {len(self._contents)} fields" ) def has_field(self, field): diff --git a/src/awkward/forms/unionform.py b/src/awkward/forms/unionform.py index 5a1f35c42d..3d7e080b53 100644 --- a/src/awkward/forms/unionform.py +++ b/src/awkward/forms/unionform.py @@ -24,15 +24,11 @@ def __init__( ): if not isinstance(tags, str): raise TypeError( - "{} 'tags' must be of type str, not {}".format( - type(self).__name__, repr(tags) - ) + f"{type(self).__name__} 'tags' must be of type str, not {tags!r}" ) if not isinstance(index, str): raise TypeError( - "{} 'index' must be of type str, not {}".format( - type(self).__name__, repr(index) - ) + f"{type(self).__name__} 'index' must be of type str, not {index!r}" ) if not isinstance(contents, Iterable): raise TypeError( diff --git a/src/awkward/operations/ak_from_parquet.py b/src/awkward/operations/ak_from_parquet.py index 23755951b2..298d8576ca 100644 --- a/src/awkward/operations/ak_from_parquet.py +++ b/src/awkward/operations/ak_from_parquet.py @@ -166,7 +166,7 @@ def metadata( actual_paths = [] for select in row_groups: path = rgs_path[select] - path2 = [_ for _ in all_paths if _.endswith(path)][0] + path2 = next(_ for _ in all_paths if _.endswith(path)) if path2 not in actual_paths: actual_paths.append(path2) subrg.append([path_rgs[path].index(select)]) diff --git a/src/awkward/types/recordtype.py b/src/awkward/types/recordtype.py index df42e827ed..c2abe46875 100644 --- a/src/awkward/types/recordtype.py +++ b/src/awkward/types/recordtype.py @@ -50,9 +50,7 @@ def __init__(self, contents, fields, *, parameters=None, typestr=None): ) if fields is not None and not isinstance(fields, Iterable): raise TypeError( - "{} 'fields' must be iterable, not {}".format( - type(self).__name__, repr(contents) - ) + f"{type(self).__name__} 'fields' must be iterable, not {contents!r}" ) if parameters is not None and not isinstance(parameters, dict): raise TypeError( diff --git a/tests/test_0014_finish_up_getitem.py b/tests/test_0014_finish_up_getitem.py index 07a52e674b..1107a2f4c3 100644 --- a/tests/test_0014_finish_up_getitem.py +++ b/tests/test_0014_finish_up_getitem.py @@ -105,7 +105,6 @@ def test_listoffsetarrayA64(): for cuts in itertools.permutations( ([2, 0, 0, 1], [1, -2, 0, -1], slice(1, None), slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -167,7 +166,6 @@ def test_listoffsetarrayA32(): for cuts in itertools.permutations( ([2, 0, 0, 1], [1, -2, 0, -1], slice(1, None), slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -225,7 +223,6 @@ def test_listarrayA64(): for cuts in itertools.permutations( ([2, 0, 0, 1], [1, -2, 0, -1], slice(1, None), slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -282,7 +279,6 @@ def test_listarrayA32(): for cuts in itertools.permutations( ([2, 0, 0, 1], [1, -2, 0, -1], slice(1, None), slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -321,7 +317,6 @@ def test_listoffsetarrayB64(): for cuts in itertools.permutations( (-1, 0, [1, 0, 0, 1], [0, 1, -1, 1], slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -361,7 +356,6 @@ def test_listoffsetarrayB32(): for cuts in itertools.permutations( (-1, 0, [1, 0, 0, 1], [0, 1, -1, 1], slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -399,7 +393,6 @@ def test_listarrayB64(): for cuts in itertools.permutations( (-1, 0, [1, 0, 0, 1], [0, 1, -1, 1], slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -436,7 +429,6 @@ def test_listarrayB32(): for cuts in itertools.permutations( (-1, 0, [1, 0, 0, 1], [0, 1, -1, 1], slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): diff --git a/tests/test_0023_regular_array.py b/tests/test_0023_regular_array.py index 1a6e19647e..4ec8d31e42 100644 --- a/tests/test_0023_regular_array.py +++ b/tests/test_0023_regular_array.py @@ -193,7 +193,6 @@ def test_numpy(): for cuts in itertools.permutations( ([2, 0, 0, 1], [1, -2, 0, -1], slice(1, None), slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice): @@ -228,7 +227,6 @@ def test_numpy(): for cuts in itertools.permutations( (-1, 0, [1, 0, 0, 1], [0, 1, -1, 1], slice(None, -1)), depth ): - cuts = cuts while len(cuts) > 0 and isinstance(cuts[0], slice): cuts = cuts[1:] while len(cuts) > 0 and isinstance(cuts[-1], slice):