From ceee35fe1c8d55fb0f47b8de25e27b69afbc2d6a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:14:40 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/setup-cfg-fmt: v1.20.2 → v2.0.0](https://github.com/asottile/setup-cfg-fmt/compare/v1.20.2...v2.0.0) - [github.com/asottile/pyupgrade: v2.37.2 → v2.37.3](https://github.com/asottile/pyupgrade/compare/v2.37.2...v2.37.3) - [github.com/PyCQA/flake8: 4.0.1 → 5.0.4](https://github.com/PyCQA/flake8/compare/4.0.1...5.0.4) --- .pre-commit-config.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4b814a12e7..df15df8a38 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,12 +16,12 @@ repos: - id: trailing-whitespace - repo: https://github.com/asottile/setup-cfg-fmt - rev: v1.20.2 + rev: v2.0.0 hooks: - id: setup-cfg-fmt - repo: https://github.com/asottile/pyupgrade - rev: "v2.37.2" + rev: "v2.37.3" hooks: - id: pyupgrade args: ["--py36-plus"] @@ -38,7 +38,7 @@ repos: additional_dependencies: [pyyaml] - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 5.0.4 hooks: - id: flake8 additional_dependencies: [flake8-bugbear, flake8-print>=5] From 09a5bf3a9fe67c6a6296972ffe5e50e26ebe5452 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Aug 2022 21:16:41 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.cfg | 5 ----- 1 file changed, 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7dacd86580..70b9d34fd7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,11 +24,6 @@ classifiers = Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 Topic :: Scientific/Engineering Topic :: Scientific/Engineering :: Information Analysis Topic :: Scientific/Engineering :: Mathematics From 981bb2d9853d08d27894ed2a00a65e3bfd6ad83f Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 9 Aug 2022 17:12:04 -0500 Subject: [PATCH 3/3] Satisfy the new, stricter rules. --- setup.cfg | 8 ++++---- setup.py | 4 ++-- src/awkward/_connect/_numexpr.py | 8 ++++---- src/awkward/_v2/_connect/cuda/__init__.py | 12 ++++++++++-- src/awkward/_v2/_connect/numexpr.py | 8 ++++---- src/awkward/_v2/_connect/pyarrow.py | 4 ++-- src/awkward/_v2/contents/bytemaskedarray.py | 2 +- src/awkward/_v2/contents/indexedarray.py | 2 +- src/awkward/_v2/contents/indexedoptionarray.py | 2 +- src/awkward/_v2/contents/listarray.py | 2 +- src/awkward/_v2/contents/listoffsetarray.py | 2 +- src/awkward/_v2/contents/numpyarray.py | 14 +++++++------- src/awkward/_v2/contents/unionarray.py | 10 +++++----- src/awkward/_v2/highlevel.py | 4 ++-- src/awkward/_v2/numba.py | 4 ++-- src/awkward/_v2/operations/ak_from_avro_file.py | 4 ++-- src/awkward/_v2/operations/ak_to_json.py | 2 +- src/awkward/_v2/operations/ak_to_pandas.py | 4 ++-- src/awkward/_v2/operations/ak_type.py | 4 ++-- src/awkward/highlevel.py | 4 ++-- src/awkward/operations/convert.py | 8 ++++---- src/awkward/operations/describe.py | 4 ++-- ...est_1300-awkward-to-cpp-converter-with-cling.py | 2 +- 23 files changed, 63 insertions(+), 55 deletions(-) diff --git a/setup.cfg b/setup.cfg index 70b9d34fd7..7f7f82887e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -57,14 +57,14 @@ numba_extensions = [flake8] extend-select = C,B,B9,T,AK1 -extend-ignore = E203,E501,E266 +extend-ignore = E203,E501,B950,E266 max-complexity = 100 exclude = studies, pybind11, rapidjson, dlpack, docs-*, src/awkward/_typeparser/generated_parser.py, awkward/_typeparser/generated_parser.py per-file-ignores = tests/*: T, AK1 - dev/*: T, AK1 - setup.py: T, AK1 - localbuild.py: T, AK1 + dev/*: T, T201, AK1 + setup.py: T, T201, AK1 + localbuild.py: T, T201, AK1 src/awkward/__init__.py: E402, F401, F403, AK1 awkward/__init__.py: E402, F401, F403, AK1 src/awkward/_v2/__init__.py: F401, F403 diff --git a/setup.py b/setup.py index f512e11a6c..7b9c6a3704 100644 --- a/setup.py +++ b/setup.py @@ -65,11 +65,11 @@ class CMakeBuild(setuptools.command.build_ext.build_ext): def build_extensions(self): try: subprocess.check_output([CMAKE, "--version"]) - except OSError: + except OSError as err: raise RuntimeError( "CMake must be installed to build the following extensions: " + ", ".join(x.name for x in self.extensions) - ) + ) from err setuptools.command.build_ext.build_ext.build_extensions(self) diff --git a/src/awkward/_connect/_numexpr.py b/src/awkward/_connect/_numexpr.py index 0d6249c4ba..5322ec85d1 100644 --- a/src/awkward/_connect/_numexpr.py +++ b/src/awkward/_connect/_numexpr.py @@ -15,7 +15,7 @@ def import_numexpr(): global checked_version try: import numexpr - except ModuleNotFoundError: + except ModuleNotFoundError as err: raise ModuleNotFoundError( """install the 'numexpr' package with: @@ -24,7 +24,7 @@ def import_numexpr(): or conda install numexpr""" - ) from None + ) from err else: if not checked_version and ak._v2._util.parse_version( numexpr.__version__ @@ -121,11 +121,11 @@ def re_evaluate(local_dict=None): try: compiled_ex = numexpr.necompiler._numexpr_last["ex"] # noqa: F841 - except KeyError: + except KeyError as err: raise RuntimeError( "not a previous evaluate() execution found" + ak._util.exception_suffix(__file__) - ) + ) from err names = numexpr.necompiler._numexpr_last["argnames"] arguments = getArguments(names, local_dict) diff --git a/src/awkward/_v2/_connect/cuda/__init__.py b/src/awkward/_v2/_connect/cuda/__init__.py index 2917028d91..a129dac56e 100644 --- a/src/awkward/_v2/_connect/cuda/__init__.py +++ b/src/awkward/_v2/_connect/cuda/__init__.py @@ -135,8 +135,16 @@ def populate_kernel_errors(kernel_name, cu_file): class Invocation: def __init__(self, name, error_context): - self.name = name - self.error_context = error_context + self._name = name + self._error_context = error_context + + @property + def name(self): + return self._name + + @property + def error_context(self): + return self._error_context def import_cupy(name="Awkward Arrays with CUDA"): diff --git a/src/awkward/_v2/_connect/numexpr.py b/src/awkward/_v2/_connect/numexpr.py index 3dfe2b3778..256e01c79e 100644 --- a/src/awkward/_v2/_connect/numexpr.py +++ b/src/awkward/_v2/_connect/numexpr.py @@ -14,7 +14,7 @@ def import_numexpr(): global checked_version try: import numexpr - except ModuleNotFoundError: + except ModuleNotFoundError as err: raise ak._v2._util.error( ModuleNotFoundError( """install the 'numexpr' package with: @@ -25,7 +25,7 @@ def import_numexpr(): conda install numexpr""" ) - ) from None + ) from err else: if not checked_version and ak._v2._util.parse_version( numexpr.__version__ @@ -123,13 +123,13 @@ def re_evaluate(local_dict=None): try: compiled_ex = numexpr.necompiler._numexpr_last["ex"] # noqa: F841 - except KeyError: + except KeyError as err: raise ak._v2._util.error( RuntimeError( "not a previous evaluate() execution found" + ak._v2._util.exception_suffix(__file__) ) - ) + ) from err names = numexpr.necompiler._numexpr_last["argnames"] arguments = getArguments(names, local_dict) diff --git a/src/awkward/_v2/_connect/pyarrow.py b/src/awkward/_v2/_connect/pyarrow.py index 218903ec9c..585e6bac52 100644 --- a/src/awkward/_v2/_connect/pyarrow.py +++ b/src/awkward/_v2/_connect/pyarrow.py @@ -52,7 +52,7 @@ def import_fsspec(name): try: import fsspec - except ModuleNotFoundError: + except ModuleNotFoundError as err: raise ImportError( f"""to use {name}, you must install fsspec: @@ -62,7 +62,7 @@ def import_fsspec(name): conda install -c conda-forge fsspec """ - ) + ) from err import_pyarrow_parquet(name) diff --git a/src/awkward/_v2/contents/bytemaskedarray.py b/src/awkward/_v2/contents/bytemaskedarray.py index 48b9a2bd8f..7fd453f34d 100644 --- a/src/awkward/_v2/contents/bytemaskedarray.py +++ b/src/awkward/_v2/contents/bytemaskedarray.py @@ -237,7 +237,7 @@ def _carry(self, carry, allow_lazy): try: nextmask = self._mask[carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return ByteMaskedArray( nextmask, diff --git a/src/awkward/_v2/contents/indexedarray.py b/src/awkward/_v2/contents/indexedarray.py index 175ec11aad..00aff905c1 100644 --- a/src/awkward/_v2/contents/indexedarray.py +++ b/src/awkward/_v2/contents/indexedarray.py @@ -184,7 +184,7 @@ def _carry(self, carry, allow_lazy): try: nextindex = self._index[carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return IndexedArray( nextindex, diff --git a/src/awkward/_v2/contents/indexedoptionarray.py b/src/awkward/_v2/contents/indexedoptionarray.py index 336d50d8ec..2cbeb60a83 100644 --- a/src/awkward/_v2/contents/indexedoptionarray.py +++ b/src/awkward/_v2/contents/indexedoptionarray.py @@ -197,7 +197,7 @@ def _carry(self, carry, allow_lazy): try: nextindex = self._index[carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return IndexedOptionArray( nextindex, diff --git a/src/awkward/_v2/contents/listarray.py b/src/awkward/_v2/contents/listarray.py index 39d353ef4e..a449958fc3 100644 --- a/src/awkward/_v2/contents/listarray.py +++ b/src/awkward/_v2/contents/listarray.py @@ -237,7 +237,7 @@ def _carry(self, carry, allow_lazy): nextstarts = self._starts[carry.data] nextstops = self._stops[: self._starts.length][carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return ListArray( nextstarts, diff --git a/src/awkward/_v2/contents/listoffsetarray.py b/src/awkward/_v2/contents/listoffsetarray.py index 66acf729ab..7d0e530396 100644 --- a/src/awkward/_v2/contents/listoffsetarray.py +++ b/src/awkward/_v2/contents/listoffsetarray.py @@ -244,7 +244,7 @@ def _carry(self, carry, allow_lazy): nextstarts = self.starts[carry.data] nextstops = self.stops[carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return ak._v2.contents.listarray.ListArray( nextstarts, diff --git a/src/awkward/_v2/contents/numpyarray.py b/src/awkward/_v2/contents/numpyarray.py index f07f61472c..d713e52909 100644 --- a/src/awkward/_v2/contents/numpyarray.py +++ b/src/awkward/_v2/contents/numpyarray.py @@ -240,7 +240,7 @@ def _getitem_at(self, where): try: out = self._data[where] except IndexError as err: - raise ak._v2._util.indexerror(self, where, str(err)) + raise ak._v2._util.indexerror(self, where, str(err)) from err if hasattr(out, "shape") and len(out.shape) != 0: return NumpyArray(out, None, None, self._nplike) @@ -257,7 +257,7 @@ def _getitem_range(self, where): try: out = self._data[where] except IndexError as err: - raise ak._v2._util.indexerror(self, where, str(err)) + raise ak._v2._util.indexerror(self, where, str(err)) from err return NumpyArray( out, @@ -279,7 +279,7 @@ def _carry(self, carry, allow_lazy): try: nextdata = self._data[carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return NumpyArray( nextdata, self._carry_identifier(carry), @@ -312,7 +312,7 @@ def _getitem_next(self, head, tail, advanced): try: out = self._data[where] except IndexError as err: - raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) + raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) from err if hasattr(out, "shape") and len(out.shape) != 0: return NumpyArray(out, None, None, self._nplike) @@ -324,7 +324,7 @@ def _getitem_next(self, head, tail, advanced): try: out = self._data[where] except IndexError as err: - raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) + raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) from err out2 = NumpyArray(out, None, self._parameters, self._nplike) return out2 @@ -346,7 +346,7 @@ def _getitem_next(self, head, tail, advanced): try: out = self._data[where] except IndexError as err: - raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) + raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) from err return NumpyArray(out, None, self._parameters, self._nplike) @@ -355,7 +355,7 @@ def _getitem_next(self, head, tail, advanced): try: out = self._data[where] except IndexError as err: - raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) + raise ak._v2._util.indexerror(self, (head,) + tail, str(err)) from err out2 = NumpyArray(out, None, self._parameters, self._nplike) return out2 diff --git a/src/awkward/_v2/contents/unionarray.py b/src/awkward/_v2/contents/unionarray.py index 4dd313f6aa..556d0c74f0 100644 --- a/src/awkward/_v2/contents/unionarray.py +++ b/src/awkward/_v2/contents/unionarray.py @@ -253,7 +253,7 @@ def _carry(self, carry, allow_lazy): nexttags = self._tags[carry.data] nextindex = self._index[: self._tags.length][carry.data] except IndexError as err: - raise ak._v2._util.indexerror(self, carry.data, str(err)) + raise ak._v2._util.indexerror(self, carry.data, str(err)) from err return UnionArray( nexttags, @@ -1288,17 +1288,17 @@ def _to_numpy(self, allow_missing): if any(isinstance(x, self._nplike.ma.MaskedArray) for x in contents): try: out = self._nplike.ma.concatenate(contents) - except Exception: + except Exception as err: raise ak._v2._util.error( ValueError(f"cannot convert {self} into numpy.ma.MaskedArray") - ) + ) from err else: try: out = numpy.concatenate(contents) - except Exception: + except Exception as err: raise ak._v2._util.error( ValueError(f"cannot convert {self} into np.ndarray") - ) + ) from err tags = numpy.asarray(self.tags) for tag, content in enumerate(contents): diff --git a/src/awkward/_v2/highlevel.py b/src/awkward/_v2/highlevel.py index 4c1654efd8..98a3df4ce4 100644 --- a/src/awkward/_v2/highlevel.py +++ b/src/awkward/_v2/highlevel.py @@ -1111,7 +1111,7 @@ def __getattr__(self, where): "while trying to get field {}, an exception " "occurred:\n{}: {}".format(repr(where), type(err), str(err)) ) - ) + ) from err else: raise ak._v2._util.error(AttributeError(f"no field named {where!r}")) @@ -1791,7 +1791,7 @@ def __getattr__(self, where): "while trying to get field {}, an exception " "occurred:\n{}: {}".format(repr(where), type(err), str(err)) ) - ) + ) from err else: raise ak._v2._util.error(AttributeError(f"no field named {where!r}")) diff --git a/src/awkward/_v2/numba.py b/src/awkward/_v2/numba.py index 329afb7ac7..a197e59036 100644 --- a/src/awkward/_v2/numba.py +++ b/src/awkward/_v2/numba.py @@ -11,7 +11,7 @@ def register_and_check(): if not checked_version: try: import numba - except ImportError: + except ImportError as err: raise ImportError( """install the 'numba' package with: @@ -20,7 +20,7 @@ def register_and_check(): or conda install numba""" - ) + ) from err checked_version = True if ak._v2._util.parse_version(numba.__version__) < ak._v2._util.parse_version( diff --git a/src/awkward/_v2/operations/ak_from_avro_file.py b/src/awkward/_v2/operations/ak_from_avro_file.py index f13169b292..008709dffe 100644 --- a/src/awkward/_v2/operations/ak_from_avro_file.py +++ b/src/awkward/_v2/operations/ak_from_avro_file.py @@ -47,10 +47,10 @@ def from_avro_file( opened_file, limit_entries, debug_forth ).outcontents return _impl(form, length, container, highlevel, behavior) - except ImportError: + except ImportError as err: raise ak._v2._util.error( "the filename is incorrect or the file does not exist" - ) + ) from err else: if not hasattr(file, "read"): diff --git a/src/awkward/_v2/operations/ak_to_json.py b/src/awkward/_v2/operations/ak_to_json.py index e119a0b9a3..2333a827d0 100644 --- a/src/awkward/_v2/operations/ak_to_json.py +++ b/src/awkward/_v2/operations/ak_to_json.py @@ -288,7 +288,7 @@ def opener(): ) except Exception as err: - raise ak._v2._util.error(err) + raise ak._v2._util.error(err) from err class _NoContextManager: diff --git a/src/awkward/_v2/operations/ak_to_pandas.py b/src/awkward/_v2/operations/ak_to_pandas.py index 0e611f639a..83e0ed04ce 100644 --- a/src/awkward/_v2/operations/ak_to_pandas.py +++ b/src/awkward/_v2/operations/ak_to_pandas.py @@ -135,7 +135,7 @@ def to_pandas( def _impl(array, how, levelname, anonymous): try: import pandas - except ImportError: + except ImportError as err: raise ak._v2._util.error( ImportError( """install the 'pandas' package with: @@ -146,7 +146,7 @@ def _impl(array, how, levelname, anonymous): conda install pandas""" ) - ) + ) from err if how is not None: out = None diff --git a/src/awkward/_v2/operations/ak_type.py b/src/awkward/_v2/operations/ak_type.py index 14893d5ea7..bbaa63ef51 100644 --- a/src/awkward/_v2/operations/ak_type.py +++ b/src/awkward/_v2/operations/ak_type.py @@ -97,13 +97,13 @@ def _impl(array): else: try: out = ak._v2.types.numpytype._dtype_to_primitive_dict[array.dtype.type] - except KeyError: + except KeyError as err: raise ak._v2._util.error( TypeError( "numpy array type is unrecognized by awkward: %r" % array.dtype.type ) - ) + ) from err out = ak._v2.types.NumpyType(out) for x in array.shape[-1:0:-1]: out = ak._v2.types.RegularType(out, x) diff --git a/src/awkward/highlevel.py b/src/awkward/highlevel.py index 004bd98072..9f26fe33ab 100644 --- a/src/awkward/highlevel.py +++ b/src/awkward/highlevel.py @@ -1118,7 +1118,7 @@ def __getattr__(self, where): "while trying to get field {}, an exception " "occurred:\n{}: {}".format(repr(where), type(err), str(err)) + ak._util.exception_suffix(__file__) - ) + ) from err else: raise AttributeError( f"no field named {where!r}" + ak._util.exception_suffix(__file__) @@ -1840,7 +1840,7 @@ def __getattr__(self, where): "while trying to get field {}, an exception " "occurred:\n{}: {}".format(repr(where), type(err), str(err)) + ak._util.exception_suffix(__file__) - ) + ) from err else: raise AttributeError( f"no field named {where!r}" + ak._util.exception_suffix(__file__) diff --git a/src/awkward/operations/convert.py b/src/awkward/operations/convert.py index 9e3dd5bb1e..653d987eb5 100644 --- a/src/awkward/operations/convert.py +++ b/src/awkward/operations/convert.py @@ -252,19 +252,19 @@ def to_numpy(array, allow_missing=True): if any(isinstance(x, numpy.ma.MaskedArray) for x in contents): try: out = numpy.ma.concatenate(contents) - except Exception: + except Exception as err: raise ValueError( f"cannot convert {array} into numpy.ma.MaskedArray" + ak._util.exception_suffix(__file__) - ) + ) from err else: try: out = numpy.concatenate(contents) - except Exception: + except Exception as err: raise ValueError( f"cannot convert {array} into np.ndarray" + ak._util.exception_suffix(__file__) - ) + ) from err tags = numpy.asarray(array.tags) for tag, content in enumerate(contents): diff --git a/src/awkward/operations/describe.py b/src/awkward/operations/describe.py index 2b4fd3ad43..f2c2a42851 100644 --- a/src/awkward/operations/describe.py +++ b/src/awkward/operations/describe.py @@ -171,10 +171,10 @@ def type(array): else: try: out = type.dtype2primitive[array.dtype.type] - except KeyError: + except KeyError as err: raise TypeError( "numpy array type is unrecognized by awkward: %r" % array.dtype.type - ) + ) from err out = ak.types.PrimitiveType(out) for x in array.shape[-1:0:-1]: out = ak.types.RegularType(out, x) diff --git a/tests/v2/test_1300-awkward-to-cpp-converter-with-cling.py b/tests/v2/test_1300-awkward-to-cpp-converter-with-cling.py index 1059a33ee8..e3aa8ab358 100644 --- a/tests/v2/test_1300-awkward-to-cpp-converter-with-cling.py +++ b/tests/v2/test_1300-awkward-to-cpp-converter-with-cling.py @@ -15,7 +15,7 @@ def debug_compiler(code): - print(code) + print(code) # noqa: T201 ROOT.gInterpreter.Declare(code)