From 9cd8871710f93e92a2954785813522df0aafc599 Mon Sep 17 00:00:00 2001 From: Saransh Date: Tue, 6 Sep 2022 20:16:07 +0530 Subject: [PATCH] chore: remove Python `3.6` support (#251) * chore: remove Python `3.6` support * Back to the `__future__` * chore: add annotations, minor cleanup * style: pre-commit fixes * chore: fix pre-commit Co-authored-by: Henry Schreiner Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 1 - .pre-commit-config.yaml | 7 +- README.md | 2 +- docs/changelog.md | 8 + docs/conf.py | 6 +- docs/index.rst | 2 +- docs/usage/intro.ipynb | 328 ++++++++++++------ docs/usage/vector_design_prototype.ipynb | 140 ++++++-- noxfile.py | 4 +- pyproject.toml | 3 +- src/vector/__init__.py | 6 +- src/vector/_compute/lorentz/Et.py | 4 +- src/vector/_compute/lorentz/Et2.py | 4 +- src/vector/_compute/lorentz/Mt.py | 4 +- src/vector/_compute/lorentz/Mt2.py | 4 +- src/vector/_compute/lorentz/__init__.py | 2 + src/vector/_compute/lorentz/add.py | 2 + src/vector/_compute/lorentz/beta.py | 4 +- src/vector/_compute/lorentz/boostX_beta.py | 4 +- src/vector/_compute/lorentz/boostX_gamma.py | 4 +- src/vector/_compute/lorentz/boostY_beta.py | 4 +- src/vector/_compute/lorentz/boostY_gamma.py | 4 +- src/vector/_compute/lorentz/boostZ_beta.py | 4 +- src/vector/_compute/lorentz/boostZ_gamma.py | 4 +- src/vector/_compute/lorentz/boost_beta3.py | 2 + src/vector/_compute/lorentz/boost_p4.py | 2 + .../_compute/lorentz/deltaRapidityPhi.py | 2 + .../_compute/lorentz/deltaRapidityPhi2.py | 2 + src/vector/_compute/lorentz/dot.py | 2 + src/vector/_compute/lorentz/equal.py | 2 + src/vector/_compute/lorentz/gamma.py | 4 +- src/vector/_compute/lorentz/is_lightlike.py | 2 + src/vector/_compute/lorentz/is_spacelike.py | 2 + src/vector/_compute/lorentz/is_timelike.py | 2 + src/vector/_compute/lorentz/isclose.py | 2 + src/vector/_compute/lorentz/not_equal.py | 2 + src/vector/_compute/lorentz/rapidity.py | 4 +- src/vector/_compute/lorentz/scale.py | 4 +- src/vector/_compute/lorentz/subtract.py | 2 + src/vector/_compute/lorentz/t.py | 4 +- src/vector/_compute/lorentz/t2.py | 4 +- src/vector/_compute/lorentz/tau.py | 4 +- src/vector/_compute/lorentz/tau2.py | 4 +- src/vector/_compute/lorentz/to_beta3.py | 4 +- src/vector/_compute/lorentz/transform4D.py | 4 +- src/vector/_compute/lorentz/unit.py | 4 +- src/vector/_compute/planar/__init__.py | 2 + src/vector/_compute/planar/add.py | 2 + src/vector/_compute/planar/deltaphi.py | 2 + src/vector/_compute/planar/dot.py | 2 + src/vector/_compute/planar/equal.py | 2 + src/vector/_compute/planar/is_antiparallel.py | 2 + src/vector/_compute/planar/is_parallel.py | 2 + .../_compute/planar/is_perpendicular.py | 2 + src/vector/_compute/planar/isclose.py | 2 + src/vector/_compute/planar/not_equal.py | 2 + src/vector/_compute/planar/phi.py | 2 + src/vector/_compute/planar/rho.py | 2 + src/vector/_compute/planar/rho2.py | 2 + src/vector/_compute/planar/rotateZ.py | 2 + src/vector/_compute/planar/scale.py | 2 + src/vector/_compute/planar/subtract.py | 2 + src/vector/_compute/planar/transform2D.py | 2 + src/vector/_compute/planar/unit.py | 2 + src/vector/_compute/planar/x.py | 2 + src/vector/_compute/planar/y.py | 2 + src/vector/_compute/spatial/__init__.py | 2 + src/vector/_compute/spatial/add.py | 2 + src/vector/_compute/spatial/costheta.py | 2 + src/vector/_compute/spatial/cottheta.py | 2 + src/vector/_compute/spatial/cross.py | 2 + src/vector/_compute/spatial/deltaR.py | 2 + src/vector/_compute/spatial/deltaR2.py | 2 + src/vector/_compute/spatial/deltaangle.py | 2 + src/vector/_compute/spatial/deltaeta.py | 2 + src/vector/_compute/spatial/dot.py | 2 + src/vector/_compute/spatial/equal.py | 2 + src/vector/_compute/spatial/eta.py | 2 + .../_compute/spatial/is_antiparallel.py | 2 + src/vector/_compute/spatial/is_parallel.py | 2 + .../_compute/spatial/is_perpendicular.py | 2 + src/vector/_compute/spatial/isclose.py | 2 + src/vector/_compute/spatial/mag.py | 2 + src/vector/_compute/spatial/mag2.py | 2 + src/vector/_compute/spatial/not_equal.py | 2 + src/vector/_compute/spatial/rotateX.py | 2 + src/vector/_compute/spatial/rotateY.py | 2 + src/vector/_compute/spatial/rotate_axis.py | 2 + src/vector/_compute/spatial/rotate_euler.py | 2 + .../_compute/spatial/rotate_quaternion.py | 2 + src/vector/_compute/spatial/scale.py | 2 + src/vector/_compute/spatial/subtract.py | 2 + src/vector/_compute/spatial/theta.py | 2 + src/vector/_compute/spatial/transform3D.py | 4 +- src/vector/_compute/spatial/unit.py | 2 + src/vector/_compute/spatial/z.py | 2 + src/vector/_methods.py | 160 ++++----- src/vector/_typeutils.py | 4 +- src/vector/backends/_numba.py | 2 + src/vector/backends/_numba_object.py | 1 + src/vector/backends/awkward.py | 54 ++- src/vector/backends/awkward_constructors.py | 10 +- src/vector/backends/numpy.py | 157 ++++----- src/vector/backends/object.py | 78 ++--- src/vector/version.pyi | 2 + tests/backends/test_awkward.py | 2 + tests/backends/test_awkward_numba.py | 2 + tests/backends/test_numba_numpy.py | 2 + tests/backends/test_numba_object.py | 2 + tests/backends/test_numpy.py | 2 + tests/backends/test_object.py | 2 + tests/backends/test_operators.py | 2 + tests/compute/lorentz/test_Et.py | 2 + tests/compute/lorentz/test_Et2.py | 2 + tests/compute/lorentz/test_Mt.py | 2 + tests/compute/lorentz/test_Mt2.py | 2 + tests/compute/lorentz/test_beta.py | 2 + tests/compute/lorentz/test_boostX_beta.py | 2 + tests/compute/lorentz/test_boostX_gamma.py | 2 + tests/compute/lorentz/test_boostY_beta.py | 2 + tests/compute/lorentz/test_boostY_gamma.py | 2 + tests/compute/lorentz/test_boostZ_beta.py | 2 + tests/compute/lorentz/test_boostZ_gamma.py | 2 + tests/compute/lorentz/test_boost_beta3.py | 2 + tests/compute/lorentz/test_boost_p4.py | 2 + .../compute/lorentz/test_deltaRapidityPhi.py | 2 + .../compute/lorentz/test_deltaRapidityPhi2.py | 2 + tests/compute/lorentz/test_gamma.py | 2 + tests/compute/lorentz/test_rapidity.py | 2 + tests/compute/lorentz/test_t.py | 2 + tests/compute/lorentz/test_t2.py | 2 + tests/compute/lorentz/test_tau.py | 2 + tests/compute/lorentz/test_tau2.py | 2 + tests/compute/lorentz/test_to_beta3.py | 2 + tests/compute/planar/test_deltaphi.py | 2 + tests/compute/planar/test_phi.py | 2 + tests/compute/planar/test_rho.py | 2 + tests/compute/planar/test_rho2.py | 2 + tests/compute/planar/test_rotateZ.py | 2 + tests/compute/planar/test_x.py | 2 + tests/compute/planar/test_y.py | 2 + tests/compute/spatial/test_costheta.py | 2 + tests/compute/spatial/test_cottheta.py | 2 + tests/compute/spatial/test_cross.py | 2 + tests/compute/spatial/test_deltaR.py | 2 + tests/compute/spatial/test_deltaR2.py | 2 + tests/compute/spatial/test_deltaangle.py | 2 + tests/compute/spatial/test_deltaeta.py | 2 + tests/compute/spatial/test_eta.py | 2 + tests/compute/spatial/test_mag.py | 2 + tests/compute/spatial/test_mag2.py | 2 + tests/compute/spatial/test_rotateX.py | 2 + tests/compute/spatial/test_rotateY.py | 2 + tests/compute/spatial/test_rotate_axis.py | 2 + tests/compute/spatial/test_rotate_euler.py | 2 + .../compute/spatial/test_rotate_quaternion.py | 2 + tests/compute/spatial/test_theta.py | 2 + tests/compute/spatial/test_z.py | 2 + tests/compute/test_add.py | 2 + tests/compute/test_conversions.py | 2 + tests/compute/test_dot.py | 2 + tests/compute/test_equal.py | 2 + tests/compute/test_isclose.py | 2 + tests/compute/test_not_equal.py | 2 + tests/compute/test_scale.py | 2 + tests/compute/test_subtract.py | 2 + tests/compute/test_unit.py | 2 + tests/conftest.py | 2 + tests/test_compute_features.py | 2 + tests/test_issues.py | 2 + tests/test_methods.py | 2 + 171 files changed, 911 insertions(+), 410 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8326289..9f06e3a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,6 @@ jobs: fail-fast: false matrix: python-version: - - "3.6" - "3.7" - "3.8" - "3.9" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 87d34aa2..24ee34bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,12 +7,12 @@ repos: rev: v2.37.3 hooks: - id: pyupgrade - args: [--py36-plus] + args: [--py37-plus] - repo: https://github.com/psf/black rev: 22.8.0 hooks: - - id: black + - id: black-jupyter - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 @@ -33,6 +33,7 @@ repos: rev: 5.10.1 hooks: - id: isort + args: ["-a", "from __future__ import annotations"] - repo: https://github.com/tox-dev/pyproject-fmt rev: "0.3.5" @@ -77,7 +78,7 @@ repos: hooks: - id: blacken-docs args: ["-E"] - additional_dependencies: [black==22.3.0] + additional_dependencies: [black==22.8.0] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.9.0 diff --git a/README.md b/README.md index e70da428..cc0c0f67 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ [![LICENSE][license-badge]][license-link] [![Scikit-HEP][sk-badge]][sk-link] -Vector is a Python 3.6+ library for 2D, 3D, and [Lorentz vectors](https://en.wikipedia.org/wiki/Special_relativity#Physics_in_spacetime), especially _arrays of vectors_, to solve common physics problems in a NumPy-like way. +Vector is a Python 3.7+ library for 2D, 3D, and [Lorentz vectors](https://en.wikipedia.org/wiki/Special_relativity#Physics_in_spacetime), especially _arrays of vectors_, to solve common physics problems in a NumPy-like way. Main features of Vector: diff --git a/docs/changelog.md b/docs/changelog.md index 83d515ae..ee6dec2a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,13 @@ # Changelog +## Version 0.10 + +### Version 0.10.0 + +- Remove Python `3.6` support [#251][] + +[#251]: https://github.com/scikit-hep/vector/pull/251 + ## Version 0.9 ### Version 0.9.0 diff --git a/docs/conf.py b/docs/conf.py index 877e2b37..07a69737 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,8 +4,11 @@ # list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html -# -- Path setup -------------------------------------------------------------- +from __future__ import annotations + +from pkg_resources import get_distribution +# -- Path setup -------------------------------------------------------------- # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -14,7 +17,6 @@ # import sys # sys.path.insert(0, os.path.abspath('.')) -from pkg_resources import get_distribution # -- Project information ----------------------------------------------------- diff --git a/docs/index.rst b/docs/index.rst index 8f031eb5..a52bb63a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -11,7 +11,7 @@ Overview -------- -Vector is a Python 3.6+ library for 2D, 3D, and `Lorentz vectors `_, especially _arrays of vectors\_, to solve common physics problems in a NumPy-like way. +Vector is a Python 3.7+ library for 2D, 3D, and `Lorentz vectors `_, especially _arrays of vectors\_, to solve common physics problems in a NumPy-like way. Main features of Vector: diff --git a/docs/usage/intro.ipynb b/docs/usage/intro.ipynb index 3bc78157..89ada71a 100644 --- a/docs/usage/intro.ipynb +++ b/docs/usage/intro.ipynb @@ -34,7 +34,7 @@ "source": [ "import vector\n", "import numpy as np\n", - "import awkward as ak # at least version 1.2.0rc5\n", + "import awkward as ak # at least version 1.2.0rc5\n", "import numba as nb" ] }, @@ -78,7 +78,7 @@ } ], "source": [ - "vector.obj(x=3, y=4) # Cartesian 2D vector" + "vector.obj(x=3, y=4) # Cartesian 2D vector" ] }, { @@ -99,7 +99,7 @@ } ], "source": [ - "vector.obj(rho=5, phi=0.9273) # same in polar coordinates" + "vector.obj(rho=5, phi=0.9273) # same in polar coordinates" ] }, { @@ -120,7 +120,9 @@ } ], "source": [ - "vector.obj(x=3, y=4).isclose(vector.obj(rho=5, phi=0.9273)) # use \"isclose\" unless they are exactly equal" + "vector.obj(x=3, y=4).isclose(\n", + " vector.obj(rho=5, phi=0.9273)\n", + ") # use \"isclose\" unless they are exactly equal" ] }, { @@ -141,7 +143,7 @@ } ], "source": [ - "vector.obj(x=3, y=4, z=-2) # Cartesian 3D vector" + "vector.obj(x=3, y=4, z=-2) # Cartesian 3D vector" ] }, { @@ -162,7 +164,7 @@ } ], "source": [ - "vector.obj(x=3, y=4, z=-2, t=10) # Cartesian 4D vector" + "vector.obj(x=3, y=4, z=-2, t=10) # Cartesian 4D vector" ] }, { @@ -183,7 +185,9 @@ } ], "source": [ - "vector.obj(rho=5, phi=0.9273, eta=-0.39, t=10) # in rho-phi-eta-t cylindrical coordinates" + "vector.obj(\n", + " rho=5, phi=0.9273, eta=-0.39, t=10\n", + ") # in rho-phi-eta-t cylindrical coordinates" ] }, { @@ -204,7 +208,9 @@ } ], "source": [ - "vector.obj(pt=5, phi=0.9273, eta=-0.39, E=10) # use momentum-synonyms to get a momentum vector" + "vector.obj(\n", + " pt=5, phi=0.9273, eta=-0.39, E=10\n", + ") # use momentum-synonyms to get a momentum vector" ] }, { @@ -225,7 +231,9 @@ } ], "source": [ - "vector.obj(rho=5, phi=0.9273, eta=-0.39, t=10) == vector.obj(pt=5, phi=0.9273, eta=-0.390035, E=10)" + "vector.obj(rho=5, phi=0.9273, eta=-0.39, t=10) == vector.obj(\n", + " pt=5, phi=0.9273, eta=-0.390035, E=10\n", + ")" ] }, { @@ -246,7 +254,9 @@ } ], "source": [ - "vector.obj(rho=5, phi=0.9273, eta=-0.39, t=10).tau # geometrical vectors have to use geometrical names (\"tau\", not \"mass\")" + "vector.obj(\n", + " rho=5, phi=0.9273, eta=-0.39, t=10\n", + ").tau # geometrical vectors have to use geometrical names (\"tau\", not \"mass\")" ] }, { @@ -267,7 +277,9 @@ } ], "source": [ - "vector.obj(pt=5, phi=0.9273, eta=-0.39, E=10).mass # momentum vectors can use momentum names (as well as geometrical ones)" + "vector.obj(\n", + " pt=5, phi=0.9273, eta=-0.39, E=10\n", + ").mass # momentum vectors can use momentum names (as well as geometrical ones)" ] }, { @@ -288,7 +300,9 @@ } ], "source": [ - "vector.obj(pt=5, phi=0.9273, theta=1.9513, mass=8.4262) # any combination of azimuthal, longitudinal, and temporal coordinates is allowed" + "vector.obj(\n", + " pt=5, phi=0.9273, theta=1.9513, mass=8.4262\n", + ") # any combination of azimuthal, longitudinal, and temporal coordinates is allowed" ] }, { @@ -309,7 +323,9 @@ } ], "source": [ - "vector.obj(x=3, y=4, z=-2, t=10).isclose(vector.obj(pt=5, phi=0.9273, theta=1.9513, mass=8.4262))" + "vector.obj(x=3, y=4, z=-2, t=10).isclose(\n", + " vector.obj(pt=5, phi=0.9273, theta=1.9513, mass=8.4262)\n", + ")" ] }, { @@ -332,16 +348,32 @@ "source": [ "# Test instance type for any level of granularity.\n", "(\n", - " isinstance(vector.obj(x=1.1, y=2.2), vector.Vector), # is a vector or array of vectors\n", - " isinstance(vector.obj(x=1.1, y=2.2), vector.Vector2D), # is 2D (not 3D or 4D)\n", - " isinstance(vector.obj(x=1.1, y=2.2), vector.VectorObject), # is a vector object (not an array)\n", - " isinstance(vector.obj(px=1.1, py=2.2), vector.Momentum), # has momentum synonyms\n", - " isinstance(vector.obj(x=1.1, y=2.2, z=3.3, t=4.4), vector.Planar), # has transverse plane (2D, 3D, or 4D)\n", - " isinstance(vector.obj(x=1.1, y=2.2, z=3.3, t=4.4), vector.Spatial), # has all spatial coordinates (3D or 4D)\n", - " isinstance(vector.obj(x=1.1, y=2.2, z=3.3, t=4.4), vector.Lorentz), # has temporal coordinates (4D)\n", - " isinstance(vector.obj(x=1.1, y=2.2, z=3.3, t=4.4).azimuthal, vector.AzimuthalXY), # azimuthal coordinate type\n", - " isinstance(vector.obj(x=1.1, y=2.2, z=3.3, t=4.4).longitudinal, vector.LongitudinalZ), # longitudinal coordinate type\n", - " isinstance(vector.obj(x=1.1, y=2.2, z=3.3, t=4.4).temporal, vector.TemporalT), # temporal coordinate type\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2), vector.Vector\n", + " ), # is a vector or array of vectors\n", + " isinstance(vector.obj(x=1.1, y=2.2), vector.Vector2D), # is 2D (not 3D or 4D)\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2), vector.VectorObject\n", + " ), # is a vector object (not an array)\n", + " isinstance(vector.obj(px=1.1, py=2.2), vector.Momentum), # has momentum synonyms\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2, z=3.3, t=4.4), vector.Planar\n", + " ), # has transverse plane (2D, 3D, or 4D)\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2, z=3.3, t=4.4), vector.Spatial\n", + " ), # has all spatial coordinates (3D or 4D)\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2, z=3.3, t=4.4), vector.Lorentz\n", + " ), # has temporal coordinates (4D)\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2, z=3.3, t=4.4).azimuthal, vector.AzimuthalXY\n", + " ), # azimuthal coordinate type\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2, z=3.3, t=4.4).longitudinal, vector.LongitudinalZ\n", + " ), # longitudinal coordinate type\n", + " isinstance(\n", + " vector.obj(x=1.1, y=2.2, z=3.3, t=4.4).temporal, vector.TemporalT\n", + " ), # temporal coordinate type\n", ")" ] }, @@ -481,9 +513,10 @@ ], "source": [ "# NumPy-like arguments (literally passed through to NumPy)\n", - "vector.array([\n", - " (1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), (1.5, 2.5)\n", - "], dtype=[(\"x\", float), (\"y\", float)])" + "vector.array(\n", + " [(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), (1.5, 2.5)],\n", + " dtype=[(\"x\", float), (\"y\", float)],\n", + ")" ] }, { @@ -530,12 +563,14 @@ ], "source": [ "# As with objects, the coordinate system and dimension is taken from the names of the fields.\n", - "vector.array({\n", - " \"x\": [1.1, 1.2, 1.3, 1.4, 1.5],\n", - " \"y\": [2.1, 2.2, 2.3, 2.4, 2.5],\n", - " \"z\": [3.1, 3.2, 3.3, 3.4, 3.5],\n", - " \"t\": [4.1, 4.2, 4.3, 4.4, 4.5],\n", - "})" + "vector.array(\n", + " {\n", + " \"x\": [1.1, 1.2, 1.3, 1.4, 1.5],\n", + " \"y\": [2.1, 2.2, 2.3, 2.4, 2.5],\n", + " \"z\": [3.1, 3.2, 3.3, 3.4, 3.5],\n", + " \"t\": [4.1, 4.2, 4.3, 4.4, 4.5],\n", + " }\n", + ")" ] }, { @@ -558,12 +593,14 @@ } ], "source": [ - "vector.array({\n", - " \"pt\": [1.1, 1.2, 1.3, 1.4, 1.5],\n", - " \"phi\": [2.1, 2.2, 2.3, 2.4, 2.5],\n", - " \"eta\": [3.1, 3.2, 3.3, 3.4, 3.5],\n", - " \"M\": [4.1, 4.2, 4.3, 4.4, 4.5],\n", - "})" + "vector.array(\n", + " {\n", + " \"pt\": [1.1, 1.2, 1.3, 1.4, 1.5],\n", + " \"phi\": [2.1, 2.2, 2.3, 2.4, 2.5],\n", + " \"eta\": [3.1, 3.2, 3.3, 3.4, 3.5],\n", + " \"M\": [4.1, 4.2, 4.3, 4.4, 4.5],\n", + " }\n", + ")" ] }, { @@ -623,7 +660,9 @@ ], "source": [ "# NumPy array # interpret groups of four values as named fields # give it vector properties and methods\n", - "np.arange(0, 24, 0.1).view([(\"x\", float), (\"y\", float), (\"z\", float), (\"t\", float)]).view(vector.VectorNumpy4D)" + "np.arange(0, 24, 0.1).view(\n", + " [(\"x\", float), (\"y\", float), (\"z\", float), (\"t\", float)]\n", + ").view(vector.VectorNumpy4D)" ] }, { @@ -687,7 +726,9 @@ } ], "source": [ - "np.arange(0, 24, 0.1).view([(\"x\", float), (\"y\", float), (\"z\", float), (\"t\", float)]).view(vector.VectorNumpy4D).reshape(6, 5, 2)" + "np.arange(0, 24, 0.1).view(\n", + " [(\"x\", float), (\"y\", float), (\"z\", float), (\"t\", float)]\n", + ").view(vector.VectorNumpy4D).reshape(6, 5, 2)" ] }, { @@ -719,7 +760,9 @@ } ], "source": [ - "vector.array({\"px\": [1, 2, 3, 4], \"py\": [1.1, 2.2, 3.3, 4.4], \"pz\": [0.1, 0.2, 0.3, 0.4]})" + "vector.array(\n", + " {\"px\": [1, 2, 3, 4], \"py\": [1.1, 2.2, 3.3, 4.4], \"pz\": [0.1, 0.2, 0.3, 0.4]}\n", + ")" ] }, { @@ -752,12 +795,18 @@ } ], "source": [ - "vector.Array([\n", - " [{\"x\": 1, \"y\": 1.1, \"z\": 0.1}, {\"x\": 2, \"y\": 2.2, \"z\": 0.2}],\n", - " [],\n", - " [{\"x\": 3, \"y\": 3.3, \"z\": 0.3}],\n", - " [{\"x\": 4, \"y\": 4.4, \"z\": 0.4}, {\"x\": 5, \"y\": 5.5, \"z\": 0.5}, {\"x\": 6, \"y\": 6.6, \"z\": 0.6}],\n", - "])" + "vector.Array(\n", + " [\n", + " [{\"x\": 1, \"y\": 1.1, \"z\": 0.1}, {\"x\": 2, \"y\": 2.2, \"z\": 0.2}],\n", + " [],\n", + " [{\"x\": 3, \"y\": 3.3, \"z\": 0.3}],\n", + " [\n", + " {\"x\": 4, \"y\": 4.4, \"z\": 0.4},\n", + " {\"x\": 5, \"y\": 5.5, \"z\": 0.5},\n", + " {\"x\": 6, \"y\": 6.6, \"z\": 0.6},\n", + " ],\n", + " ]\n", + ")" ] }, { @@ -796,13 +845,18 @@ } ], "source": [ - "ak.Array([\n", - " [{\"x\": 1, \"y\": 1.1, \"z\": 0.1}, {\"x\": 2, \"y\": 2.2, \"z\": 0.2}],\n", - " [],\n", - " [{\"x\": 3, \"y\": 3.3, \"z\": 0.3}],\n", - " [{\"x\": 4, \"y\": 4.4, \"z\": 0.4}, {\"x\": 5, \"y\": 5.5, \"z\": 0.5}, {\"x\": 6, \"y\": 6.6, \"z\": 0.6}],\n", - "],\n", - " with_name=\"Vector3D\"\n", + "ak.Array(\n", + " [\n", + " [{\"x\": 1, \"y\": 1.1, \"z\": 0.1}, {\"x\": 2, \"y\": 2.2, \"z\": 0.2}],\n", + " [],\n", + " [{\"x\": 3, \"y\": 3.3, \"z\": 0.3}],\n", + " [\n", + " {\"x\": 4, \"y\": 4.4, \"z\": 0.4},\n", + " {\"x\": 5, \"y\": 5.5, \"z\": 0.5},\n", + " {\"x\": 6, \"y\": 6.6, \"z\": 0.6},\n", + " ],\n", + " ],\n", + " with_name=\"Vector3D\",\n", ")" ] }, @@ -976,7 +1030,7 @@ } ], "source": [ - "vector.obj(x=1, y=2, z=3).mag # spatial magnitude" + "vector.obj(x=1, y=2, z=3).mag # spatial magnitude" ] }, { @@ -997,7 +1051,7 @@ } ], "source": [ - "vector.obj(x=1, y=2, z=3).mag2 # spatial magnitude squared" + "vector.obj(x=1, y=2, z=3).mag2 # spatial magnitude squared" ] }, { @@ -1147,11 +1201,13 @@ } ], "source": [ - "vector.array({\n", - " \"x\": [1.0, 2.0, 3.0, 4.0, 5.0],\n", - " \"y\": [1.1, 2.2, 3.3, 4.4, 5.5],\n", - " \"z\": [0.1, 0.2, 0.3, 0.4, 0.5],\n", - "}).theta" + "vector.array(\n", + " {\n", + " \"x\": [1.0, 2.0, 3.0, 4.0, 5.0],\n", + " \"y\": [1.1, 2.2, 3.3, 4.4, 5.5],\n", + " \"z\": [0.1, 0.2, 0.3, 0.4, 0.5],\n", + " }\n", + ").theta" ] }, { @@ -1172,12 +1228,14 @@ } ], "source": [ - "vector.Array([\n", - " [{\"x\": 1, \"y\": 1.1, \"z\": 0.1}, {\"x\": 2, \"y\": 2.2, \"z\": 0.2}],\n", - " [],\n", - " [{\"x\": 3, \"y\": 3.3, \"z\": 0.3}],\n", - " [{\"x\": 4, \"y\": 4.4, \"z\": 0.4}, {\"x\": 5, \"y\": 5.5, \"z\": 0.5}],\n", - "]).theta" + "vector.Array(\n", + " [\n", + " [{\"x\": 1, \"y\": 1.1, \"z\": 0.1}, {\"x\": 2, \"y\": 2.2, \"z\": 0.2}],\n", + " [],\n", + " [{\"x\": 3, \"y\": 3.3, \"z\": 0.3}],\n", + " [{\"x\": 4, \"y\": 4.4, \"z\": 0.4}, {\"x\": 5, \"y\": 5.5, \"z\": 0.5}],\n", + " ]\n", + ").theta" ] }, { @@ -1253,7 +1311,12 @@ ], "source": [ "# Make a large, random NumPy array of 3D momentum vectors.\n", - "array = np.random.normal(0, 1, 150).view([(x, float) for x in (\"x\", \"y\", \"z\")]).view(vector.MomentumNumpy3D).reshape(5, 5, 2)\n", + "array = (\n", + " np.random.normal(0, 1, 150)\n", + " .view([(x, float) for x in (\"x\", \"y\", \"z\")])\n", + " .view(vector.MomentumNumpy3D)\n", + " .reshape(5, 5, 2)\n", + ")\n", "array" ] }, @@ -1369,7 +1432,15 @@ ], "source": [ "# Make a large, random Awkward Array of 3D momentum vectors.\n", - "array = vector.Array([[{x: np.random.normal(0, 1) for x in (\"px\", \"py\", \"pz\")} for inner in range(np.random.poisson(1.5))] for outer in range(50)])\n", + "array = vector.Array(\n", + " [\n", + " [\n", + " {x: np.random.normal(0, 1) for x in (\"px\", \"py\", \"pz\")}\n", + " for inner in range(np.random.poisson(1.5))\n", + " ]\n", + " for outer in range(50)\n", + " ]\n", + ")\n", "array" ] }, @@ -1506,7 +1577,11 @@ ], "source": [ "# Broadcasts a scalar rotation angle of 0.5 to all elements of the NumPy array.\n", - "print(vector.array({\"rho\": [1, 2, 3, 4, 5], \"phi\": [0.1, 0.2, 0.3, 0.4, 0.5]}).rotateZ(0.5))" + "print(\n", + " vector.array({\"rho\": [1, 2, 3, 4, 5], \"phi\": [0.1, 0.2, 0.3, 0.4, 0.5]}).rotateZ(\n", + " 0.5\n", + " )\n", + ")" ] }, { @@ -1525,7 +1600,11 @@ ], "source": [ "# Matches each rotation angle to an element of the NumPy array.\n", - "print(vector.array({\"rho\": [1, 2, 3, 4, 5], \"phi\": [0.1, 0.2, 0.3, 0.4, 0.5]}).rotateZ(np.array([0.1, 0.2, 0.3, 0.4, 0.5])))" + "print(\n", + " vector.array({\"rho\": [1, 2, 3, 4, 5], \"phi\": [0.1, 0.2, 0.3, 0.4, 0.5]}).rotateZ(\n", + " np.array([0.1, 0.2, 0.3, 0.4, 0.5])\n", + " )\n", + ")" ] }, { @@ -1544,7 +1623,11 @@ ], "source": [ "# Broadcasts a scalar rotation angle of 0.5 to all elements of the Awkward Array.\n", - "print(vector.Array([[{\"rho\": 1, \"phi\": 0.1}, {\"rho\": 2, \"phi\": 0.2}], [], [{\"rho\": 3, \"phi\": 0.3}]]).rotateZ(0.5))" + "print(\n", + " vector.Array(\n", + " [[{\"rho\": 1, \"phi\": 0.1}, {\"rho\": 2, \"phi\": 0.2}], [], [{\"rho\": 3, \"phi\": 0.3}]]\n", + " ).rotateZ(0.5)\n", + ")" ] }, { @@ -1563,7 +1646,11 @@ ], "source": [ "# Broadcasts a rotation angle of 0.1 to both elements of the first list, 0.2 to the empty list, and 0.3 to the only element of the last list.\n", - "print(vector.Array([[{\"rho\": 1, \"phi\": 0.1}, {\"rho\": 2, \"phi\": 0.2}], [], [{\"rho\": 3, \"phi\": 0.3}]]).rotateZ([0.1, 0.2, 0.3]))" + "print(\n", + " vector.Array(\n", + " [[{\"rho\": 1, \"phi\": 0.1}, {\"rho\": 2, \"phi\": 0.2}], [], [{\"rho\": 3, \"phi\": 0.3}]]\n", + " ).rotateZ([0.1, 0.2, 0.3])\n", + ")" ] }, { @@ -1582,7 +1669,11 @@ ], "source": [ "# Matches each rotation angle to an element of the Awkward Array.\n", - "print(vector.Array([[{\"rho\": 1, \"phi\": 0.1}, {\"rho\": 2, \"phi\": 0.2}], [], [{\"rho\": 3, \"phi\": 0.3}]]).rotateZ([[0.1, 0.2], [], [0.3]]))" + "print(\n", + " vector.Array(\n", + " [[{\"rho\": 1, \"phi\": 0.1}, {\"rho\": 2, \"phi\": 0.2}], [], [{\"rho\": 3, \"phi\": 0.3}]]\n", + " ).rotateZ([[0.1, 0.2], [], [0.3]])\n", + ")" ] }, { @@ -1795,7 +1886,7 @@ } ], "source": [ - "vector.obj(x=3, y=4) @ vector.obj(x=6, y=8) # both are Cartesian, dot product is exact" + "vector.obj(x=3, y=4) @ vector.obj(x=6, y=8) # both are Cartesian, dot product is exact" ] }, { @@ -1816,7 +1907,9 @@ } ], "source": [ - "vector.obj(rho=5, phi=0.9273) @ vector.obj(x=6, y=8) # one is polar, dot product is approximate" + "vector.obj(rho=5, phi=0.9273) @ vector.obj(\n", + " x=6, y=8\n", + ") # one is polar, dot product is approximate" ] }, { @@ -1837,7 +1930,9 @@ } ], "source": [ - "vector.obj(x=3, y=4) @ vector.obj(rho=10, phi=0.9273) # one is polar, dot product is approximate" + "vector.obj(x=3, y=4) @ vector.obj(\n", + " rho=10, phi=0.9273\n", + ") # one is polar, dot product is approximate" ] }, { @@ -1858,7 +1953,9 @@ } ], "source": [ - "vector.obj(rho=5, phi=0.9273) @ vector.obj(rho=10, phi=0.9273) # both are polar, a formula that depends on phi differences is used" + "vector.obj(rho=5, phi=0.9273) @ vector.obj(\n", + " rho=10, phi=0.9273\n", + ") # both are polar, a formula that depends on phi differences is used" ] }, { @@ -1931,7 +2028,9 @@ } ], "source": [ - "vector.array({\"x\": [1, 2, 3, 4, 5], \"y\": [0.1, 0.2, 0.3, 0.4, 0.5]}) + vector.obj(x=10, y=5)" + "vector.array({\"x\": [1, 2, 3, 4, 5], \"y\": [0.1, 0.2, 0.3, 0.4, 0.5]}) + vector.obj(\n", + " x=10, y=5\n", + ")" ] }, { @@ -1953,13 +2052,15 @@ ], "source": [ "(\n", - " vector.Array([ # an Awkward Array of vectors\n", - " [{\"x\": 1, \"y\": 1.1}, {\"x\": 2, \"y\": 2.2}],\n", - " [],\n", - " [{\"x\": 3, \"y\": 3.3}],\n", - " [{\"x\": 4, \"y\": 4.4}, {\"x\": 5, \"y\": 5.5}],\n", - " ])\n", - " + vector.obj(x=10, y=5) # and a single vector object\n", + " vector.Array(\n", + " [ # an Awkward Array of vectors\n", + " [{\"x\": 1, \"y\": 1.1}, {\"x\": 2, \"y\": 2.2}],\n", + " [],\n", + " [{\"x\": 3, \"y\": 3.3}],\n", + " [{\"x\": 4, \"y\": 4.4}, {\"x\": 5, \"y\": 5.5}],\n", + " ]\n", + " )\n", + " + vector.obj(x=10, y=5) # and a single vector object\n", ")" ] }, @@ -1982,13 +2083,17 @@ ], "source": [ "(\n", - " vector.Array([ # an Awkward Array of vectors\n", - " [{\"x\": 1, \"y\": 1.1}, {\"x\": 2, \"y\": 2.2}],\n", - " [],\n", - " [{\"x\": 3, \"y\": 3.3}],\n", - " [{\"x\": 4, \"y\": 4.4}, {\"x\": 5, \"y\": 5.5}],\n", - " ])\n", - " + vector.array({\"x\": [4, 3, 2, 1], \"y\": [0.1, 0.1, 0.1, 0.1]}) # and a NumPy array of vectors\n", + " vector.Array(\n", + " [ # an Awkward Array of vectors\n", + " [{\"x\": 1, \"y\": 1.1}, {\"x\": 2, \"y\": 2.2}],\n", + " [],\n", + " [{\"x\": 3, \"y\": 3.3}],\n", + " [{\"x\": 4, \"y\": 4.4}, {\"x\": 5, \"y\": 5.5}],\n", + " ]\n", + " )\n", + " + vector.array(\n", + " {\"x\": [4, 3, 2, 1], \"y\": [0.1, 0.1, 0.1, 0.1]}\n", + " ) # and a NumPy array of vectors\n", ")" ] }, @@ -2018,7 +2123,9 @@ } ], "source": [ - "vector.obj(rho=1, phi=0.5).deltaphi(vector.obj(rho=2, phi=0.3)) # deltaphi is a planar operation (defined on the transverse plane)" + "vector.obj(rho=1, phi=0.5).deltaphi(\n", + " vector.obj(rho=2, phi=0.3)\n", + ") # deltaphi is a planar operation (defined on the transverse plane)" ] }, { @@ -2039,7 +2146,9 @@ } ], "source": [ - "vector.obj(rho=1, phi=0.5, z=10).deltaphi(vector.obj(rho=2, phi=0.3, theta=1.4)) # but we can use it on 3D vectors" + "vector.obj(rho=1, phi=0.5, z=10).deltaphi(\n", + " vector.obj(rho=2, phi=0.3, theta=1.4)\n", + ") # but we can use it on 3D vectors" ] }, { @@ -2060,7 +2169,9 @@ } ], "source": [ - "vector.obj(rho=1, phi=0.5, z=10, t=100).deltaphi(vector.obj(rho=2, phi=0.3, theta=1.4, tau=1000)) # and 4D vectors" + "vector.obj(rho=1, phi=0.5, z=10, t=100).deltaphi(\n", + " vector.obj(rho=2, phi=0.3, theta=1.4, tau=1000)\n", + ") # and 4D vectors" ] }, { @@ -2081,7 +2192,9 @@ } ], "source": [ - "vector.obj(rho=1, phi=0.5).deltaphi(vector.obj(rho=2, phi=0.3, theta=1.4, tau=1000)) # and mixed dimensionality" + "vector.obj(rho=1, phi=0.5).deltaphi(\n", + " vector.obj(rho=2, phi=0.3, theta=1.4, tau=1000)\n", + ") # and mixed dimensionality" ] }, { @@ -2110,7 +2223,7 @@ } ], "source": [ - "vector.obj(x=1, y=2, z=3).rotateX(np.pi/4)" + "vector.obj(x=1, y=2, z=3).rotateX(np.pi / 4)" ] }, { @@ -2131,7 +2244,7 @@ } ], "source": [ - "vector.obj(x=1, y=2, z=3, tau=10).rotateX(np.pi/4)" + "vector.obj(x=1, y=2, z=3, tau=10).rotateX(np.pi / 4)" ] }, { @@ -2173,7 +2286,9 @@ } ], "source": [ - "vector.obj(pt=1, phi=1.3, eta=2, mass=5).deltaR(vector.obj(pt=2, phi=0.3, eta=1, mass=10))" + "vector.obj(pt=1, phi=1.3, eta=2, mass=5).deltaR(\n", + " vector.obj(pt=2, phi=0.3, eta=1, mass=10)\n", + ")" ] }, { @@ -2414,7 +2529,18 @@ ], "source": [ "# This is still not a large number. You want millions.\n", - "array = vector.Array([[dict({x: np.random.normal(0, 1) for x in (\"px\", \"py\", \"pz\")}, E=np.random.normal(10, 1)) for inner in range(np.random.poisson(1.5))] for outer in range(50)])\n", + "array = vector.Array(\n", + " [\n", + " [\n", + " dict(\n", + " {x: np.random.normal(0, 1) for x in (\"px\", \"py\", \"pz\")},\n", + " E=np.random.normal(10, 1),\n", + " )\n", + " for inner in range(np.random.poisson(1.5))\n", + " ]\n", + " for outer in range(50)\n", + " ]\n", + ")\n", "array" ] }, diff --git a/docs/usage/vector_design_prototype.ipynb b/docs/usage/vector_design_prototype.ipynb index 8b8f6b14..b25f79ff 100644 --- a/docs/usage/vector_design_prototype.ipynb +++ b/docs/usage/vector_design_prototype.ipynb @@ -57,12 +57,15 @@ "source": [ "x, y, z, t = tree.arrays([\"Muon_Px\", \"Muon_Py\", \"Muon_Pz\", \"Muon_E\"], outputtype=tuple)\n", "offsets = ak.layout.Index64(x.offsets)\n", - "content = ak.layout.RecordArray({\n", - " \"x\": ak.layout.NumpyArray(x.content.astype(np.float64)),\n", - " \"y\": ak.layout.NumpyArray(y.content.astype(np.float64)), \n", - " \"z\": ak.layout.NumpyArray(z.content.astype(np.float64)),\n", - " \"t\": ak.layout.NumpyArray(t.content.astype(np.float64))},\n", - " parameters={\"__record__\": \"LorentzXYZT\"})" + "content = ak.layout.RecordArray(\n", + " {\n", + " \"x\": ak.layout.NumpyArray(x.content.astype(np.float64)),\n", + " \"y\": ak.layout.NumpyArray(y.content.astype(np.float64)),\n", + " \"z\": ak.layout.NumpyArray(z.content.astype(np.float64)),\n", + " \"t\": ak.layout.NumpyArray(t.content.astype(np.float64)),\n", + " },\n", + " parameters={\"__record__\": \"LorentzXYZT\"},\n", + ")" ] }, { @@ -115,12 +118,15 @@ "def lorentz_xyz_pt(rec):\n", " return np.sqrt(rec.x**2 + rec.y**2)\n", "\n", + "\n", "def lorentz_xyz_eta(rec):\n", " return np.arcsinh(rec.z / np.sqrt(rec.x**2 + rec.y**2))\n", "\n", + "\n", "def lorentz_xyz_phi(rec):\n", " return np.arctan2(rec.y, rec.x)\n", "\n", + "\n", "def lorentz_xyz_mass(rec):\n", " return np.sqrt(rec.t**2 - rec.x**2 - rec.y**2 - rec.z**2)" ] @@ -144,8 +150,7 @@ " z = left.z + right.z\n", " t = left.t + right.t\n", "\n", - " return ak.zip({\"x\": x, \"y\": y, \"z\": z, \"t\": t},\n", - " with_name=\"LorentzXYZT\")" + " return ak.zip({\"x\": x, \"y\": y, \"z\": z, \"t\": t}, with_name=\"LorentzXYZT\")" ] }, { @@ -202,7 +207,10 @@ "source": [ "class LorentzXYZT(ak.Record, LorentzXYZTCommon):\n", " def __repr__(self):\n", - " return \"Lxyz({0:.3g} {1:.3g} {2:.3g} {3:.3g})\".format(self.x, self.y, self.z, self.t)\n", + " return \"Lxyz({0:.3g} {1:.3g} {2:.3g} {3:.3g})\".format(\n", + " self.x, self.y, self.z, self.t\n", + " )\n", + "\n", "\n", "class LorentzXYZTArray(ak.Array, LorentzXYZTCommon):\n", " pass" @@ -331,6 +339,7 @@ "def typer_lorentz_xyz_pt(viewtype):\n", " return nb.float64\n", "\n", + "\n", "def lower_lorentz_xyz_pt(context, builder, sig, args):\n", " return context.compile_internal(builder, lorentz_xyz_pt, sig, args)" ] @@ -388,6 +397,7 @@ "source": [ "example3 = ak.Array(example, behavior=lorentzbehavior)\n", "\n", + "\n", "@nb.njit\n", "def do_it_in_numba(input, output):\n", " for event in input:\n", @@ -403,6 +413,7 @@ "\n", " output.end_list()\n", "\n", + "\n", "output = ak.ArrayBuilder(behavior=lorentzbehavior)\n", "do_it_in_numba(example3, output)\n", "\n", @@ -427,13 +438,26 @@ "def typer_lorentz_xyz_eq(binop, left, right):\n", " return nb.boolean(left, right)\n", "\n", + "\n", "def lower_lorentz_xyz_eq(context, builder, sig, args):\n", " def compute(left, right):\n", - " return abs(left.x - right.x) + abs(left.y - right.y) + abs(left.z - right.z) + abs(left.t - right.t) < 0.001\n", + " return (\n", + " abs(left.x - right.x)\n", + " + abs(left.y - right.y)\n", + " + abs(left.z - right.z)\n", + " + abs(left.t - right.t)\n", + " < 0.001\n", + " )\n", + "\n", " return context.compile_internal(builder, compute, sig, args)\n", "\n", - "lorentzbehavior[\"__numba_typer__\", \"LorentzXYZT\", operator.eq, \"LorentzXYZT\"] = typer_lorentz_xyz_eq\n", - "lorentzbehavior[\"__numba_lower__\", \"LorentzXYZT\", operator.eq, \"LorentzXYZT\"] = lower_lorentz_xyz_eq" + "\n", + "lorentzbehavior[\n", + " \"__numba_typer__\", \"LorentzXYZT\", operator.eq, \"LorentzXYZT\"\n", + "] = typer_lorentz_xyz_eq\n", + "lorentzbehavior[\n", + " \"__numba_lower__\", \"LorentzXYZT\", operator.eq, \"LorentzXYZT\"\n", + "] = lower_lorentz_xyz_eq" ] }, { @@ -459,6 +483,7 @@ "source": [ "example4 = ak.Array(example, behavior=lorentzbehavior)\n", "\n", + "\n", "@nb.njit\n", "def check_equality(input, output):\n", " for muons in input:\n", @@ -472,6 +497,7 @@ "\n", " output.end_list()\n", "\n", + "\n", "output = ak.ArrayBuilder(behavior=lorentzbehavior)\n", "check_equality(example4, output)\n", "\n", @@ -508,14 +534,18 @@ " self.t = t\n", "\n", " def __repr__(self):\n", - " return \"Lxyz({0:.3g} {1:.3g} {2:.3g} {3:.3g})\".format(self.x, self.y, self.z, self.t)\n", + " return \"Lxyz({0:.3g} {1:.3g} {2:.3g} {3:.3g})\".format(\n", + " self.x, self.y, self.z, self.t\n", + " )\n", "\n", " def __getitem__(self, attr):\n", " # It has to behave the same way as the bound objects or users will get confused.\n", " if attr in (\"x\", \"y\", \"z\", \"t\"):\n", " return getattr(self, attr)\n", " else:\n", - " raise ValueError(\"key {0} does not exist (not in record)\".format(json.dumps(attr)))" + " raise ValueError(\n", + " \"key {0} does not exist (not in record)\".format(json.dumps(attr))\n", + " )" ] }, { @@ -535,20 +565,24 @@ "def typeof_LorentzXYZTFree(obj, c):\n", " return LorentzXYZTType()\n", "\n", + "\n", "class LorentzXYZTType(nb.types.Type):\n", " def __init__(self):\n", " # Type names have to be unique identifiers; they determine whether Numba\n", " # will recompile a function with new types.\n", " super(LorentzXYZTType, self).__init__(name=\"LorentzXYZTType()\")\n", "\n", + "\n", "@nb.extending.register_model(LorentzXYZTType)\n", "class LorentzXYZTModel(nb.extending.models.StructModel):\n", " def __init__(self, dmm, fe_type):\n", " # This is the C-style struct that will be used wherever LorentzXYZT are needed.\n", - " members = [(\"x\", nb.float64),\n", - " (\"y\", nb.float64),\n", - " (\"z\", nb.float64),\n", - " (\"t\", nb.float64)]\n", + " members = [\n", + " (\"x\", nb.float64),\n", + " (\"y\", nb.float64),\n", + " (\"z\", nb.float64),\n", + " (\"t\", nb.float64),\n", + " ]\n", " super(LorentzXYZTModel, self).__init__(dmm, fe_type, members)" ] }, @@ -591,6 +625,7 @@ " is_error = nb.core.cgutils.is_not_null(c.builder, c.pyapi.err_occurred())\n", " return nb.extending.NativeValue(outproxy._getvalue(), is_error)\n", "\n", + "\n", "@nb.extending.box(LorentzXYZTType)\n", "def box_LorentzXYZT(lxyztype, lxyzval, c):\n", " # This proxy is initialized with a value, used for getattr, rather than setattr.\n", @@ -603,7 +638,9 @@ " # The way we get Python objects into this lowered world is by pickling them.\n", " LorentzXYZTFree_obj = c.pyapi.unserialize(c.pyapi.serialize_object(LorentzXYZTFree))\n", "\n", - " out = c.pyapi.call_function_objargs(LorentzXYZTFree_obj, (x_obj, y_obj, z_obj, t_obj))\n", + " out = c.pyapi.call_function_objargs(\n", + " LorentzXYZTFree_obj, (x_obj, y_obj, z_obj, t_obj)\n", + " )\n", "\n", " c.pyapi.decref(LorentzXYZTFree_obj)\n", " c.pyapi.decref(x_obj)\n", @@ -641,10 +678,12 @@ "testit = LorentzXYZTFree(1, 2, 3, 4)\n", "print(testit)\n", "\n", + "\n", "@nb.njit\n", "def pass_through(obj):\n", " return obj\n", "\n", + "\n", "print(testit, pass_through(testit))" ] }, @@ -690,11 +729,24 @@ "@nb.extending.type_callable(LorentzXYZTFree)\n", "def typer_LorentzXYZTFree_constructor(context):\n", " def typer(x, y, z, t):\n", - " if x == nb.types.float64 and y == nb.types.float64 and z == nb.types.float64 and t == nb.types.float64:\n", + " if (\n", + " x == nb.types.float64\n", + " and y == nb.types.float64\n", + " and z == nb.types.float64\n", + " and t == nb.types.float64\n", + " ):\n", " return LorentzXYZTType()\n", + "\n", " return typer\n", "\n", - "@nb.extending.lower_builtin(LorentzXYZTFree, nb.types.float64, nb.types.float64, nb.types.float64, nb.types.float64)\n", + "\n", + "@nb.extending.lower_builtin(\n", + " LorentzXYZTFree,\n", + " nb.types.float64,\n", + " nb.types.float64,\n", + " nb.types.float64,\n", + " nb.types.float64,\n", + ")\n", "def lower_LorentzXYZTFree_constructor(context, builder, sig, args):\n", " rettype, (xtype, ytype, ztype, ttype) = sig.return_type, sig.args\n", " xval, yval, zval, tval = args\n", @@ -735,6 +787,7 @@ "def test_constructor():\n", " return LorentzXYZTFree(1.1, 2.2, 3.3, 4.4)\n", "\n", + "\n", "print(test_constructor())" ] }, @@ -828,19 +881,30 @@ "source": [ "@nb.extending.lower_getattr(LorentzXYZTType, \"pt\")\n", "def lower_LorentzXYZT_pt(context, builder, lxyztype, lxyzval):\n", - " return context.compile_internal(builder, lorentz_xyz_pt, nb.float64(lxyztype), (lxyzval,))\n", + " return context.compile_internal(\n", + " builder, lorentz_xyz_pt, nb.float64(lxyztype), (lxyzval,)\n", + " )\n", + "\n", "\n", "@nb.extending.lower_getattr(LorentzXYZTType, \"eta\")\n", "def lower_LorentzXYZT_eta(context, builder, lxyztype, lxyzval):\n", - " return context.compile_internal(builder, lorentz_xyz_eta, nb.float64(lxyztype), (lxyzval,))\n", + " return context.compile_internal(\n", + " builder, lorentz_xyz_eta, nb.float64(lxyztype), (lxyzval,)\n", + " )\n", + "\n", "\n", "@nb.extending.lower_getattr(LorentzXYZTType, \"phi\")\n", "def lower_LorentzXYZT_phi(context, builder, lxyztype, lxyzval):\n", - " return context.compile_internal(builder, lorentz_xyz_phi, nb.float64(lxyztype), (lxyzval,))\n", + " return context.compile_internal(\n", + " builder, lorentz_xyz_phi, nb.float64(lxyztype), (lxyzval,)\n", + " )\n", + "\n", "\n", "@nb.extending.lower_getattr(LorentzXYZTType, \"mass\")\n", "def lower_LorentzXYZT_mass(context, builder, lxyztype, lxyzval):\n", - " return context.compile_internal(builder, lorentz_xyz_mass, nb.float64(lxyztype), (lxyzval,))" + " return context.compile_internal(\n", + " builder, lorentz_xyz_mass, nb.float64(lxyztype), (lxyzval,)\n", + " )" ] }, { @@ -917,6 +981,7 @@ "def try_it_out(testit):\n", " return testit.x, testit[\"x\"], testit.pt, testit.eta, testit.phi, testit.mass\n", "\n", + "\n", "print(try_it_out(testit))" ] }, @@ -948,9 +1013,13 @@ " output.field(\"t\")\n", " output.real(lxyz.t)\n", " output.end_record()\n", + "\n", " return context.compile_internal(builder, doit, sig, args)\n", "\n", - "lorentzbehavior[\"__numba_lower__\", ak.ArrayBuilder.append, LorentzXYZTType] = lower_ArrayBuilder_append_LorentzXYZT" + "\n", + "lorentzbehavior[\n", + " \"__numba_lower__\", ak.ArrayBuilder.append, LorentzXYZTType\n", + "] = lower_ArrayBuilder_append_LorentzXYZT" ] }, { @@ -980,7 +1049,8 @@ "def fill_it(testit, output):\n", " output.append(testit)\n", " output.append(testit)\n", - " \n", + "\n", + "\n", "output = ak.ArrayBuilder(behavior=lorentzbehavior)\n", "fill_it(testit, output)\n", "\n", @@ -1005,9 +1075,13 @@ "def typer_lorentz_xyz_add(binop, left, right):\n", " return LorentzXYZTType()(left, right)\n", "\n", + "\n", "def lower_lorentz_xyz_add(context, builder, sig, args):\n", " def compute(left, right):\n", - " return LorentzXYZTFree(left.x + right.x, left.y + right.y, left.z + right.z, left.t + right.t)\n", + " return LorentzXYZTFree(\n", + " left.x + right.x, left.y + right.y, left.z + right.z, left.t + right.t\n", + " )\n", + "\n", " return context.compile_internal(builder, compute, sig, args)" ] }, @@ -1017,8 +1091,12 @@ "metadata": {}, "outputs": [], "source": [ - "lorentzbehavior[\"__numba_typer__\", \"LorentzXYZT\", operator.add, \"LorentzXYZT\"] = typer_lorentz_xyz_add\n", - "lorentzbehavior[\"__numba_lower__\", \"LorentzXYZT\", operator.add, \"LorentzXYZT\"] = lower_lorentz_xyz_add" + "lorentzbehavior[\n", + " \"__numba_typer__\", \"LorentzXYZT\", operator.add, \"LorentzXYZT\"\n", + "] = typer_lorentz_xyz_add\n", + "lorentzbehavior[\n", + " \"__numba_lower__\", \"LorentzXYZT\", operator.add, \"LorentzXYZT\"\n", + "] = lower_lorentz_xyz_add" ] }, { @@ -1051,6 +1129,7 @@ " for j in range(i + 1, len(muons)):\n", " return muons[i] + muons[j]\n", "\n", + "\n", "example5 = ak.Array(example, behavior=lorentzbehavior)\n", "\n", "print(test_add(example5))" @@ -1101,6 +1180,7 @@ "\n", " output.end_list()\n", "\n", + "\n", "output = ak.ArrayBuilder(behavior=lorentzbehavior)\n", "do_cool_stuff(example5, output)\n", "\n", diff --git a/noxfile.py b/noxfile.py index fde987e5..978d0afd 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,8 +1,10 @@ +from __future__ import annotations + from pathlib import Path import nox -ALL_PYTHONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] +ALL_PYTHONS = ["3.7", "3.8", "3.9", "3.10", "3.11"] nox.options.sessions = ["lint", "tests", "doctests"] diff --git a/pyproject.toml b/pyproject.toml index e878b9b9..1ea8ca0a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ keywords = [ license = "BSD-3-Clause" maintainers = [ {name = "The Scikit-HEP admins", email = "scikit-hep-admins@googlegroups.com"} ] authors = [ {name = "Jim Pivarski, Henry Schreiner, Eduardo Rodrigues", email = "eduardo.rodrigues@cern.ch"} ] -requires-python = ">=3.6" +requires-python = ">=3.7" dependencies = [ 'importlib-metadata>=0.22; python_version < "3.8"', "numpy>=1.13.3", @@ -34,7 +34,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", diff --git a/src/vector/__init__.py b/src/vector/__init__.py index 7f45773a..3b7ace4f 100644 --- a/src/vector/__init__.py +++ b/src/vector/__init__.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import sys import typing @@ -83,7 +85,7 @@ def _import_awkward() -> None: from vector.backends.awkward import VectorAwkward -__all__: typing.Tuple[str, ...] = ( +__all__: tuple[str, ...] = ( "Array", "Azimuthal", "AzimuthalRhoPhi", @@ -131,7 +133,7 @@ def _import_awkward() -> None: ) -def __dir__() -> typing.Tuple[str, ...]: +def __dir__() -> tuple[str, ...]: return ( tuple(s for s in __all__ if s != "VectorAwkward") if awkward is None diff --git a/src/vector/_compute/lorentz/Et.py b/src/vector/_compute/lorentz/Et.py index e3bfcbbc..a60f0673 100644 --- a/src/vector/_compute/lorentz/Et.py +++ b/src/vector/_compute/lorentz/Et.py @@ -10,6 +10,8 @@ Lorentz.Et(self) """ +from __future__ import annotations + import typing import numpy @@ -116,7 +118,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/Et2.py b/src/vector/_compute/lorentz/Et2.py index 97ef2239..822e348d 100644 --- a/src/vector/_compute/lorentz/Et2.py +++ b/src/vector/_compute/lorentz/Et2.py @@ -9,6 +9,8 @@ @property Lorentz.Et2(self) """ +from __future__ import annotations + import typing import numpy @@ -117,7 +119,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/Mt.py b/src/vector/_compute/lorentz/Mt.py index c9b9c548..754378b8 100644 --- a/src/vector/_compute/lorentz/Mt.py +++ b/src/vector/_compute/lorentz/Mt.py @@ -9,6 +9,8 @@ @property Lorentz.Mt(self) """ +from __future__ import annotations + import typing import numpy @@ -111,7 +113,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/Mt2.py b/src/vector/_compute/lorentz/Mt2.py index 410d369e..4ecad70d 100644 --- a/src/vector/_compute/lorentz/Mt2.py +++ b/src/vector/_compute/lorentz/Mt2.py @@ -9,6 +9,8 @@ @property Lorentz.Mt2(self) """ +from __future__ import annotations + import typing import numpy @@ -112,7 +114,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/__init__.py b/src/vector/_compute/lorentz/__init__.py index 22e96f29..a5bda2e3 100644 --- a/src/vector/_compute/lorentz/__init__.py +++ b/src/vector/_compute/lorentz/__init__.py @@ -21,6 +21,8 @@ of new backends). """ +from __future__ import annotations + import vector._compute.lorentz.add # noqa: F401 import vector._compute.lorentz.beta # noqa: F401 import vector._compute.lorentz.boost_beta3 # noqa: F401 diff --git a/src/vector/_compute/lorentz/add.py b/src/vector/_compute/lorentz/add.py index ce9af6e0..7f2cb03e 100644 --- a/src/vector/_compute/lorentz/add.py +++ b/src/vector/_compute/lorentz/add.py @@ -8,6 +8,8 @@ Lorentz.add(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/beta.py b/src/vector/_compute/lorentz/beta.py index 5faa97ab..7bbb0c58 100644 --- a/src/vector/_compute/lorentz/beta.py +++ b/src/vector/_compute/lorentz/beta.py @@ -9,6 +9,8 @@ @property Lorentz.beta(self) """ +from __future__ import annotations + import typing from math import inf @@ -154,7 +156,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boostX_beta.py b/src/vector/_compute/lorentz/boostX_beta.py index 7fcf4d1b..fe7f87a2 100644 --- a/src/vector/_compute/lorentz/boostX_beta.py +++ b/src/vector/_compute/lorentz/boostX_beta.py @@ -8,6 +8,8 @@ Lorentz.boostX(self, beta=...) """ +from __future__ import annotations + import typing import numpy @@ -245,7 +247,7 @@ def dispatch(beta: typing.Any, v: typing.Any) -> typing.Any: beta, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boostX_gamma.py b/src/vector/_compute/lorentz/boostX_gamma.py index 9f675ec9..ccbf35d1 100644 --- a/src/vector/_compute/lorentz/boostX_gamma.py +++ b/src/vector/_compute/lorentz/boostX_gamma.py @@ -8,6 +8,8 @@ Lorentz.boostX(self, gamma=) """ +from __future__ import annotations + import typing import numpy @@ -245,7 +247,7 @@ def dispatch(gamma: typing.Any, v: typing.Any) -> typing.Any: gamma, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boostY_beta.py b/src/vector/_compute/lorentz/boostY_beta.py index 96a1e285..9cd1f78a 100644 --- a/src/vector/_compute/lorentz/boostY_beta.py +++ b/src/vector/_compute/lorentz/boostY_beta.py @@ -8,6 +8,8 @@ Lorentz.boostY(self, beta=...) """ +from __future__ import annotations + import typing import numpy @@ -245,7 +247,7 @@ def dispatch(beta: typing.Any, v: typing.Any) -> typing.Any: beta, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boostY_gamma.py b/src/vector/_compute/lorentz/boostY_gamma.py index 630f9003..4082b057 100644 --- a/src/vector/_compute/lorentz/boostY_gamma.py +++ b/src/vector/_compute/lorentz/boostY_gamma.py @@ -8,6 +8,8 @@ Lorentz.boostY(self, gamma=...) """ +from __future__ import annotations + import typing import numpy @@ -245,7 +247,7 @@ def dispatch(gamma: typing.Any, v: typing.Any) -> typing.Any: gamma, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boostZ_beta.py b/src/vector/_compute/lorentz/boostZ_beta.py index 12cecf1f..437e8e2f 100644 --- a/src/vector/_compute/lorentz/boostZ_beta.py +++ b/src/vector/_compute/lorentz/boostZ_beta.py @@ -8,6 +8,8 @@ Lorentz.boostZ(self, beta=...) """ +from __future__ import annotations + import typing import numpy @@ -220,7 +222,7 @@ def dispatch(beta: typing.Any, v: typing.Any) -> typing.Any: beta, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boostZ_gamma.py b/src/vector/_compute/lorentz/boostZ_gamma.py index ae0ca64b..950102e3 100644 --- a/src/vector/_compute/lorentz/boostZ_gamma.py +++ b/src/vector/_compute/lorentz/boostZ_gamma.py @@ -8,6 +8,8 @@ Lorentz.boostZ(self, gamma=...) """ +from __future__ import annotations + import typing import numpy @@ -220,7 +222,7 @@ def dispatch(gamma: typing.Any, v: typing.Any) -> typing.Any: gamma, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/boost_beta3.py b/src/vector/_compute/lorentz/boost_beta3.py index b9589d10..306292e6 100644 --- a/src/vector/_compute/lorentz/boost_beta3.py +++ b/src/vector/_compute/lorentz/boost_beta3.py @@ -14,6 +14,8 @@ Lorentz.boost(self, beta3=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/boost_p4.py b/src/vector/_compute/lorentz/boost_p4.py index a8b39f68..d150e840 100644 --- a/src/vector/_compute/lorentz/boost_p4.py +++ b/src/vector/_compute/lorentz/boost_p4.py @@ -14,6 +14,8 @@ Lorentz.boost(self, p4=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/deltaRapidityPhi.py b/src/vector/_compute/lorentz/deltaRapidityPhi.py index 2e40bf6a..3cfbe790 100644 --- a/src/vector/_compute/lorentz/deltaRapidityPhi.py +++ b/src/vector/_compute/lorentz/deltaRapidityPhi.py @@ -8,6 +8,8 @@ Spatial.deltaRapidityPhi(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/deltaRapidityPhi2.py b/src/vector/_compute/lorentz/deltaRapidityPhi2.py index a68ddae3..0cd48454 100644 --- a/src/vector/_compute/lorentz/deltaRapidityPhi2.py +++ b/src/vector/_compute/lorentz/deltaRapidityPhi2.py @@ -8,6 +8,8 @@ Spatial.deltaRapidityPhi2(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/dot.py b/src/vector/_compute/lorentz/dot.py index 6a45aaad..a8809a21 100644 --- a/src/vector/_compute/lorentz/dot.py +++ b/src/vector/_compute/lorentz/dot.py @@ -8,6 +8,8 @@ Lorentz.dot(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/equal.py b/src/vector/_compute/lorentz/equal.py index 648674b0..e09a8131 100644 --- a/src/vector/_compute/lorentz/equal.py +++ b/src/vector/_compute/lorentz/equal.py @@ -8,6 +8,8 @@ Lorentz.equal(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/gamma.py b/src/vector/_compute/lorentz/gamma.py index 3c0c0042..c73fca53 100644 --- a/src/vector/_compute/lorentz/gamma.py +++ b/src/vector/_compute/lorentz/gamma.py @@ -9,6 +9,8 @@ @property Lorentz.gamma(self) """ +from __future__ import annotations + import typing from math import inf @@ -154,7 +156,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/is_lightlike.py b/src/vector/_compute/lorentz/is_lightlike.py index 1f1a1c3f..1f42cd9b 100644 --- a/src/vector/_compute/lorentz/is_lightlike.py +++ b/src/vector/_compute/lorentz/is_lightlike.py @@ -8,6 +8,8 @@ Lorentz.is_lightlike(self, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/is_spacelike.py b/src/vector/_compute/lorentz/is_spacelike.py index df564a5a..19c5cfde 100644 --- a/src/vector/_compute/lorentz/is_spacelike.py +++ b/src/vector/_compute/lorentz/is_spacelike.py @@ -8,6 +8,8 @@ Lorentz.is_spacelike(self, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/is_timelike.py b/src/vector/_compute/lorentz/is_timelike.py index 492a5517..733cdd13 100644 --- a/src/vector/_compute/lorentz/is_timelike.py +++ b/src/vector/_compute/lorentz/is_timelike.py @@ -8,6 +8,8 @@ Lorentz.is_timelike(self, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/isclose.py b/src/vector/_compute/lorentz/isclose.py index 47b88265..e132aaef 100644 --- a/src/vector/_compute/lorentz/isclose.py +++ b/src/vector/_compute/lorentz/isclose.py @@ -8,6 +8,8 @@ Lorentz.isclose(self, rtol=..., atol=..., equal_nan=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/not_equal.py b/src/vector/_compute/lorentz/not_equal.py index 00cfc68e..21475cc3 100644 --- a/src/vector/_compute/lorentz/not_equal.py +++ b/src/vector/_compute/lorentz/not_equal.py @@ -8,6 +8,8 @@ Lorentz.not_equal(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/rapidity.py b/src/vector/_compute/lorentz/rapidity.py index 305a0c8c..15f387cb 100644 --- a/src/vector/_compute/lorentz/rapidity.py +++ b/src/vector/_compute/lorentz/rapidity.py @@ -9,6 +9,8 @@ @property Lorentz.rapidity(self) """ +from __future__ import annotations + import typing import numpy @@ -128,7 +130,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/scale.py b/src/vector/_compute/lorentz/scale.py index 03308983..f2d719df 100644 --- a/src/vector/_compute/lorentz/scale.py +++ b/src/vector/_compute/lorentz/scale.py @@ -8,6 +8,8 @@ Lorentz.scale(self, factor) """ +from __future__ import annotations + import typing import numpy @@ -183,7 +185,7 @@ def dispatch(factor: typing.Any, v: typing.Any) -> typing.Any: factor, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/subtract.py b/src/vector/_compute/lorentz/subtract.py index 75507176..6a6c0775 100644 --- a/src/vector/_compute/lorentz/subtract.py +++ b/src/vector/_compute/lorentz/subtract.py @@ -8,6 +8,8 @@ Lorentz.subtract(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/lorentz/t.py b/src/vector/_compute/lorentz/t.py index c2ee3726..f274572f 100644 --- a/src/vector/_compute/lorentz/t.py +++ b/src/vector/_compute/lorentz/t.py @@ -9,6 +9,8 @@ @property Lorentz.t(self) """ +from __future__ import annotations + import typing import numpy @@ -111,7 +113,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/t2.py b/src/vector/_compute/lorentz/t2.py index 788e58d9..77b65d40 100644 --- a/src/vector/_compute/lorentz/t2.py +++ b/src/vector/_compute/lorentz/t2.py @@ -9,6 +9,8 @@ @property Lorentz.t2(self) """ +from __future__ import annotations + import typing import numpy @@ -126,7 +128,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/tau.py b/src/vector/_compute/lorentz/tau.py index 02bcda04..6bd6e845 100644 --- a/src/vector/_compute/lorentz/tau.py +++ b/src/vector/_compute/lorentz/tau.py @@ -9,6 +9,8 @@ @property Lorentz.tau(self) """ +from __future__ import annotations + import typing import numpy @@ -117,7 +119,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/tau2.py b/src/vector/_compute/lorentz/tau2.py index 2965facd..3588d084 100644 --- a/src/vector/_compute/lorentz/tau2.py +++ b/src/vector/_compute/lorentz/tau2.py @@ -9,6 +9,8 @@ @property Lorentz.tau2(self) """ +from __future__ import annotations + import typing import numpy @@ -111,7 +113,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/to_beta3.py b/src/vector/_compute/lorentz/to_beta3.py index 04d2c6e5..66f35288 100644 --- a/src/vector/_compute/lorentz/to_beta3.py +++ b/src/vector/_compute/lorentz/to_beta3.py @@ -8,6 +8,8 @@ Lorentz.to_beta3(self) """ +from __future__ import annotations + import typing import numpy @@ -167,7 +169,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/transform4D.py b/src/vector/_compute/lorentz/transform4D.py index e4d6b7b1..ff49f66d 100644 --- a/src/vector/_compute/lorentz/transform4D.py +++ b/src/vector/_compute/lorentz/transform4D.py @@ -10,6 +10,8 @@ where ``obj`` has ``obj["xx"]``, ``obj["xy"]``, etc. """ +from __future__ import annotations + import typing import numpy @@ -200,7 +202,7 @@ def dispatch(obj: typing.Any, v: typing.Any) -> typing.Any: obj["tt"], *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/lorentz/unit.py b/src/vector/_compute/lorentz/unit.py index 9c30dadd..3da0c636 100644 --- a/src/vector/_compute/lorentz/unit.py +++ b/src/vector/_compute/lorentz/unit.py @@ -8,6 +8,8 @@ Lorentz.unit(self) """ +from __future__ import annotations + import typing from math import inf @@ -249,7 +251,7 @@ def dispatch(v: typing.Any) -> typing.Any: v.lib, *v.azimuthal.elements, *v.longitudinal.elements, - *v.temporal.elements + *v.temporal.elements, ), returns, 1, diff --git a/src/vector/_compute/planar/__init__.py b/src/vector/_compute/planar/__init__.py index e2bc4978..b888d4ed 100644 --- a/src/vector/_compute/planar/__init__.py +++ b/src/vector/_compute/planar/__init__.py @@ -21,6 +21,8 @@ of new backends). """ +from __future__ import annotations + import vector._compute.planar.add # noqa: F401 import vector._compute.planar.deltaphi # noqa: F401 import vector._compute.planar.dot # noqa: F401 diff --git a/src/vector/_compute/planar/add.py b/src/vector/_compute/planar/add.py index 5dffaf8b..a9b5c151 100644 --- a/src/vector/_compute/planar/add.py +++ b/src/vector/_compute/planar/add.py @@ -8,6 +8,8 @@ Planar.add(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/deltaphi.py b/src/vector/_compute/planar/deltaphi.py index 6b5197a1..850b00de 100644 --- a/src/vector/_compute/planar/deltaphi.py +++ b/src/vector/_compute/planar/deltaphi.py @@ -8,6 +8,8 @@ Planar.deltaphi(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/dot.py b/src/vector/_compute/planar/dot.py index 0c28419b..15322f65 100644 --- a/src/vector/_compute/planar/dot.py +++ b/src/vector/_compute/planar/dot.py @@ -8,6 +8,8 @@ Planar.dot(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/equal.py b/src/vector/_compute/planar/equal.py index 87b346f3..e6ded192 100644 --- a/src/vector/_compute/planar/equal.py +++ b/src/vector/_compute/planar/equal.py @@ -8,6 +8,8 @@ Planar.equal(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/is_antiparallel.py b/src/vector/_compute/planar/is_antiparallel.py index e89c7c01..915b0e28 100644 --- a/src/vector/_compute/planar/is_antiparallel.py +++ b/src/vector/_compute/planar/is_antiparallel.py @@ -8,6 +8,8 @@ Planar.is_antiparallel(self, other, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/is_parallel.py b/src/vector/_compute/planar/is_parallel.py index 33647827..e8a48a02 100644 --- a/src/vector/_compute/planar/is_parallel.py +++ b/src/vector/_compute/planar/is_parallel.py @@ -8,6 +8,8 @@ Planar.is_parallel(self, other, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/is_perpendicular.py b/src/vector/_compute/planar/is_perpendicular.py index 4765f555..ac5fa3ed 100644 --- a/src/vector/_compute/planar/is_perpendicular.py +++ b/src/vector/_compute/planar/is_perpendicular.py @@ -8,6 +8,8 @@ Planar.is_perpendicular(self, other, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/isclose.py b/src/vector/_compute/planar/isclose.py index c5c8a230..cff7ac11 100644 --- a/src/vector/_compute/planar/isclose.py +++ b/src/vector/_compute/planar/isclose.py @@ -8,6 +8,8 @@ Planar.isclose(self, other, rtol=..., atol=..., equal_nan=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/not_equal.py b/src/vector/_compute/planar/not_equal.py index 3a3aa0c6..27f4dc9b 100644 --- a/src/vector/_compute/planar/not_equal.py +++ b/src/vector/_compute/planar/not_equal.py @@ -8,6 +8,8 @@ Planar.not_equal(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/phi.py b/src/vector/_compute/planar/phi.py index 4b11f342..a810ef0d 100644 --- a/src/vector/_compute/planar/phi.py +++ b/src/vector/_compute/planar/phi.py @@ -9,6 +9,8 @@ @property Planar.phi(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/rho.py b/src/vector/_compute/planar/rho.py index 026c9e07..cec796b8 100644 --- a/src/vector/_compute/planar/rho.py +++ b/src/vector/_compute/planar/rho.py @@ -9,6 +9,8 @@ @property Planar.rho(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/rho2.py b/src/vector/_compute/planar/rho2.py index e7320f74..2c4937ad 100644 --- a/src/vector/_compute/planar/rho2.py +++ b/src/vector/_compute/planar/rho2.py @@ -9,6 +9,8 @@ @property Planar.rho2(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/rotateZ.py b/src/vector/_compute/planar/rotateZ.py index df962921..32c7bad0 100644 --- a/src/vector/_compute/planar/rotateZ.py +++ b/src/vector/_compute/planar/rotateZ.py @@ -8,6 +8,8 @@ Planar.rotateZ(self, angle) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/scale.py b/src/vector/_compute/planar/scale.py index a3eafee3..aadb4d7c 100644 --- a/src/vector/_compute/planar/scale.py +++ b/src/vector/_compute/planar/scale.py @@ -8,6 +8,8 @@ Planar.scale(self, factor) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/subtract.py b/src/vector/_compute/planar/subtract.py index 0472d8e7..b4473d40 100644 --- a/src/vector/_compute/planar/subtract.py +++ b/src/vector/_compute/planar/subtract.py @@ -8,6 +8,8 @@ Planar.subtract(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/transform2D.py b/src/vector/_compute/planar/transform2D.py index c929d872..0a92111f 100644 --- a/src/vector/_compute/planar/transform2D.py +++ b/src/vector/_compute/planar/transform2D.py @@ -10,6 +10,8 @@ where ``obj`` has ``obj["xx"]``, ``obj["xy"]``, etc. """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/unit.py b/src/vector/_compute/planar/unit.py index 1c45ec03..769bab10 100644 --- a/src/vector/_compute/planar/unit.py +++ b/src/vector/_compute/planar/unit.py @@ -8,6 +8,8 @@ Planar.unit(self) """ +from __future__ import annotations + import typing from math import inf diff --git a/src/vector/_compute/planar/x.py b/src/vector/_compute/planar/x.py index 92ec3053..20d3f05a 100644 --- a/src/vector/_compute/planar/x.py +++ b/src/vector/_compute/planar/x.py @@ -9,6 +9,8 @@ @property Planar.x(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/planar/y.py b/src/vector/_compute/planar/y.py index 6dca3f40..cf1a4565 100644 --- a/src/vector/_compute/planar/y.py +++ b/src/vector/_compute/planar/y.py @@ -9,6 +9,8 @@ @property Planar.y(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/__init__.py b/src/vector/_compute/spatial/__init__.py index 67162c1e..8cdaa150 100644 --- a/src/vector/_compute/spatial/__init__.py +++ b/src/vector/_compute/spatial/__init__.py @@ -21,6 +21,8 @@ of new backends). """ +from __future__ import annotations + import vector._compute.spatial.add # noqa: F401 import vector._compute.spatial.costheta # noqa: F401 import vector._compute.spatial.cottheta # noqa: F401 diff --git a/src/vector/_compute/spatial/add.py b/src/vector/_compute/spatial/add.py index 8c40e642..22e35e3d 100644 --- a/src/vector/_compute/spatial/add.py +++ b/src/vector/_compute/spatial/add.py @@ -8,6 +8,8 @@ Spatial.add(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/costheta.py b/src/vector/_compute/spatial/costheta.py index 550ad1ee..eceb1898 100644 --- a/src/vector/_compute/spatial/costheta.py +++ b/src/vector/_compute/spatial/costheta.py @@ -9,6 +9,8 @@ @property Spatial.costheta(self) """ +from __future__ import annotations + import typing from math import inf diff --git a/src/vector/_compute/spatial/cottheta.py b/src/vector/_compute/spatial/cottheta.py index 30288759..53810846 100644 --- a/src/vector/_compute/spatial/cottheta.py +++ b/src/vector/_compute/spatial/cottheta.py @@ -9,6 +9,8 @@ @property Spatial.cottheta(self) """ +from __future__ import annotations + import typing from math import inf diff --git a/src/vector/_compute/spatial/cross.py b/src/vector/_compute/spatial/cross.py index a3da5183..1393173c 100644 --- a/src/vector/_compute/spatial/cross.py +++ b/src/vector/_compute/spatial/cross.py @@ -11,6 +11,8 @@ Note that this returns a 3D vector even for 4D inputs. The ``None`` at the end of the return signature indicates termination. """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/deltaR.py b/src/vector/_compute/spatial/deltaR.py index 6f8db3d7..d5292047 100644 --- a/src/vector/_compute/spatial/deltaR.py +++ b/src/vector/_compute/spatial/deltaR.py @@ -8,6 +8,8 @@ Spatial.deltaR(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/deltaR2.py b/src/vector/_compute/spatial/deltaR2.py index c29a8c98..38b843ca 100644 --- a/src/vector/_compute/spatial/deltaR2.py +++ b/src/vector/_compute/spatial/deltaR2.py @@ -8,6 +8,8 @@ Spatial.deltaR2(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/deltaangle.py b/src/vector/_compute/spatial/deltaangle.py index 9bb62adf..32b92d69 100644 --- a/src/vector/_compute/spatial/deltaangle.py +++ b/src/vector/_compute/spatial/deltaangle.py @@ -8,6 +8,8 @@ Spatial.deltaangle(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/deltaeta.py b/src/vector/_compute/spatial/deltaeta.py index 525cded9..99c7b365 100644 --- a/src/vector/_compute/spatial/deltaeta.py +++ b/src/vector/_compute/spatial/deltaeta.py @@ -8,6 +8,8 @@ Spatial.deltaeta(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/dot.py b/src/vector/_compute/spatial/dot.py index 82c5545f..954615ae 100644 --- a/src/vector/_compute/spatial/dot.py +++ b/src/vector/_compute/spatial/dot.py @@ -8,6 +8,8 @@ Spatial.dot(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/equal.py b/src/vector/_compute/spatial/equal.py index 756bc7ef..0278e531 100644 --- a/src/vector/_compute/spatial/equal.py +++ b/src/vector/_compute/spatial/equal.py @@ -8,6 +8,8 @@ Spatial.equal(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/eta.py b/src/vector/_compute/spatial/eta.py index aa49964f..a76cade8 100644 --- a/src/vector/_compute/spatial/eta.py +++ b/src/vector/_compute/spatial/eta.py @@ -9,6 +9,8 @@ @property Spatial.eta(self) """ +from __future__ import annotations + import typing from math import inf, nan diff --git a/src/vector/_compute/spatial/is_antiparallel.py b/src/vector/_compute/spatial/is_antiparallel.py index b9da7dc3..814150d9 100644 --- a/src/vector/_compute/spatial/is_antiparallel.py +++ b/src/vector/_compute/spatial/is_antiparallel.py @@ -8,6 +8,8 @@ Spatial.is_antiparallel(self, other, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/is_parallel.py b/src/vector/_compute/spatial/is_parallel.py index 5db6cb3c..e1a92687 100644 --- a/src/vector/_compute/spatial/is_parallel.py +++ b/src/vector/_compute/spatial/is_parallel.py @@ -8,6 +8,8 @@ Spatial.is_parallel(self, other, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/is_perpendicular.py b/src/vector/_compute/spatial/is_perpendicular.py index f324c197..3da7f431 100644 --- a/src/vector/_compute/spatial/is_perpendicular.py +++ b/src/vector/_compute/spatial/is_perpendicular.py @@ -8,6 +8,8 @@ Spatial.is_perpendicular(self, other, tolerance=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/isclose.py b/src/vector/_compute/spatial/isclose.py index d005f25e..c0a98edf 100644 --- a/src/vector/_compute/spatial/isclose.py +++ b/src/vector/_compute/spatial/isclose.py @@ -8,6 +8,8 @@ Spatial.isclose(self, other, rtol=..., atol=..., equal_nan=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/mag.py b/src/vector/_compute/spatial/mag.py index 031dc66b..ceac00da 100644 --- a/src/vector/_compute/spatial/mag.py +++ b/src/vector/_compute/spatial/mag.py @@ -9,6 +9,8 @@ @property Spatial.mag(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/mag2.py b/src/vector/_compute/spatial/mag2.py index 3eb6ad9d..e7b57f8b 100644 --- a/src/vector/_compute/spatial/mag2.py +++ b/src/vector/_compute/spatial/mag2.py @@ -9,6 +9,8 @@ @property Spatial.mag2(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/not_equal.py b/src/vector/_compute/spatial/not_equal.py index 6f364e24..ea8e7914 100644 --- a/src/vector/_compute/spatial/not_equal.py +++ b/src/vector/_compute/spatial/not_equal.py @@ -8,6 +8,8 @@ Spatial.not_equal(self, other) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/rotateX.py b/src/vector/_compute/spatial/rotateX.py index f43b6b14..6be18c57 100644 --- a/src/vector/_compute/spatial/rotateX.py +++ b/src/vector/_compute/spatial/rotateX.py @@ -8,6 +8,8 @@ Spatial.rotateX(self, angle) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/rotateY.py b/src/vector/_compute/spatial/rotateY.py index 831a5505..88323f23 100644 --- a/src/vector/_compute/spatial/rotateY.py +++ b/src/vector/_compute/spatial/rotateY.py @@ -8,6 +8,8 @@ Spatial.rotateY(self, angle) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/rotate_axis.py b/src/vector/_compute/spatial/rotate_axis.py index 222f7f0f..31615105 100644 --- a/src/vector/_compute/spatial/rotate_axis.py +++ b/src/vector/_compute/spatial/rotate_axis.py @@ -8,6 +8,8 @@ Spatial.rotate_axis(self, axis, angle) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/rotate_euler.py b/src/vector/_compute/spatial/rotate_euler.py index 87bd4545..0c8a364b 100644 --- a/src/vector/_compute/spatial/rotate_euler.py +++ b/src/vector/_compute/spatial/rotate_euler.py @@ -8,6 +8,8 @@ Spatial.rotate_euler(self, phi, theta, psi, order=...) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/rotate_quaternion.py b/src/vector/_compute/spatial/rotate_quaternion.py index c632c691..c1137f29 100644 --- a/src/vector/_compute/spatial/rotate_quaternion.py +++ b/src/vector/_compute/spatial/rotate_quaternion.py @@ -8,6 +8,8 @@ Spatial.rotate_quaternion(self, u, i, j, k) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/scale.py b/src/vector/_compute/spatial/scale.py index e3e33913..52591a87 100644 --- a/src/vector/_compute/spatial/scale.py +++ b/src/vector/_compute/spatial/scale.py @@ -8,6 +8,8 @@ Spatial.scale(self, factor) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/subtract.py b/src/vector/_compute/spatial/subtract.py index 436cf4e1..9bd0d13e 100644 --- a/src/vector/_compute/spatial/subtract.py +++ b/src/vector/_compute/spatial/subtract.py @@ -8,6 +8,8 @@ Spatial.subtract(self, angle) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/theta.py b/src/vector/_compute/spatial/theta.py index 084e36df..c42aeb04 100644 --- a/src/vector/_compute/spatial/theta.py +++ b/src/vector/_compute/spatial/theta.py @@ -9,6 +9,8 @@ @property Spatial.theta(self) """ +from __future__ import annotations + import typing import numpy diff --git a/src/vector/_compute/spatial/transform3D.py b/src/vector/_compute/spatial/transform3D.py index 94b8a786..6764e6f7 100644 --- a/src/vector/_compute/spatial/transform3D.py +++ b/src/vector/_compute/spatial/transform3D.py @@ -10,6 +10,8 @@ where ``obj` has ``obj["xx"]``, ``obj["xy"]``, etc. """ +from __future__ import annotations + import typing import numpy @@ -138,7 +140,7 @@ def dispatch(obj: typing.Any, v: typing.Any) -> typing.Any: obj["zy"], obj["zz"], *v.azimuthal.elements, - *v.longitudinal.elements + *v.longitudinal.elements, ), returns, 1, diff --git a/src/vector/_compute/spatial/unit.py b/src/vector/_compute/spatial/unit.py index d7002381..16bc6226 100644 --- a/src/vector/_compute/spatial/unit.py +++ b/src/vector/_compute/spatial/unit.py @@ -8,6 +8,8 @@ Spatial.unit(self) """ +from __future__ import annotations + import typing from math import inf diff --git a/src/vector/_compute/spatial/z.py b/src/vector/_compute/spatial/z.py index 3d5ed4c0..a8452982 100644 --- a/src/vector/_compute/spatial/z.py +++ b/src/vector/_compute/spatial/z.py @@ -9,6 +9,8 @@ @property Spatial.z(self) """ +from __future__ import annotations + import typing from math import inf diff --git a/src/vector/_methods.py b/src/vector/_methods.py index b07948dc..448efc30 100644 --- a/src/vector/_methods.py +++ b/src/vector/_methods.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import typing from contextlib import suppress @@ -23,7 +25,7 @@ class Coordinates: class Azimuthal(Coordinates): @property - def elements(self) -> typing.Tuple[ScalarCollection, ScalarCollection]: + def elements(self) -> tuple[ScalarCollection, ScalarCollection]: """ Azimuthal coordinates as a tuple. @@ -35,7 +37,7 @@ def elements(self) -> typing.Tuple[ScalarCollection, ScalarCollection]: class Longitudinal(Coordinates): @property - def elements(self) -> typing.Tuple[ScalarCollection]: + def elements(self) -> tuple[ScalarCollection]: """ Longitudinal coordinates as a tuple. @@ -47,7 +49,7 @@ def elements(self) -> typing.Tuple[ScalarCollection]: class Temporal(Coordinates): @property - def elements(self) -> typing.Tuple[ScalarCollection]: + def elements(self) -> tuple[ScalarCollection]: """ Temporal coordinates as a tuple. @@ -165,16 +167,16 @@ def _wrap_result( """ raise AssertionError - ProjectionClass2D: typing.Type["VectorProtocolPlanar"] - ProjectionClass3D: typing.Type["VectorProtocolSpatial"] - ProjectionClass4D: typing.Type["VectorProtocolLorentz"] - GenericClass: typing.Type["VectorProtocol"] + ProjectionClass2D: type[VectorProtocolPlanar] + ProjectionClass3D: type[VectorProtocolSpatial] + ProjectionClass4D: type[VectorProtocolLorentz] + GenericClass: type[VectorProtocol] - def to_Vector2D(self) -> "VectorProtocolPlanar": + def to_Vector2D(self) -> VectorProtocolPlanar: """Projects this vector/these vectors onto azimuthal coordinates only.""" raise AssertionError - def to_Vector3D(self) -> "VectorProtocolSpatial": + def to_Vector3D(self) -> VectorProtocolSpatial: """ Projects this vector/these vectors onto azimuthal and longitudinal coordinates only. @@ -183,7 +185,7 @@ def to_Vector3D(self) -> "VectorProtocolSpatial": """ raise AssertionError - def to_Vector4D(self) -> "VectorProtocolLorentz": + def to_Vector4D(self) -> VectorProtocolLorentz: """ Projects this vector/these vectors onto azimuthal, longitudinal, and temporal coordinates. @@ -194,140 +196,140 @@ def to_Vector4D(self) -> "VectorProtocolLorentz": """ raise AssertionError - def to_xy(self) -> "VectorProtocolPlanar": + def to_xy(self) -> VectorProtocolPlanar: """ Converts to $x$-$y$ coordinates, possibly eliminating dimensions with a projection. """ raise AssertionError - def to_rhophi(self) -> "VectorProtocolPlanar": + def to_rhophi(self) -> VectorProtocolPlanar: r""" Converts to $\rho$-$\phi$ coordinates, possibly eliminating dimensions with a projection. """ raise AssertionError - def to_xyz(self) -> "VectorProtocolSpatial": + def to_xyz(self) -> VectorProtocolSpatial: """ Converts to $x$-$y$-$z$ coordinates, possibly eliminating or imputing dimensions with a projection. """ raise AssertionError - def to_xytheta(self) -> "VectorProtocolSpatial": + def to_xytheta(self) -> VectorProtocolSpatial: r""" Converts to $x$-$y$-$\theta$ coordinates, possibly eliminating or imputing dimensions with a projection. """ raise AssertionError - def to_xyeta(self) -> "VectorProtocolSpatial": + def to_xyeta(self) -> VectorProtocolSpatial: r""" Converts to $x$-$y$-$\eta$ coordinates, possibly eliminating or imputing dimensions with a projection. """ raise AssertionError - def to_rhophiz(self) -> "VectorProtocolSpatial": + def to_rhophiz(self) -> VectorProtocolSpatial: r""" Converts to $\rho$-$\phi$-$z$ coordinates, possibly eliminating or imputing dimensions with a projection. """ raise AssertionError - def to_rhophitheta(self) -> "VectorProtocolSpatial": + def to_rhophitheta(self) -> VectorProtocolSpatial: r""" Converts to $\rho$-$\phi$-$\theta$ coordinates, possibly eliminating or imputing dimensions with a projection. """ raise AssertionError - def to_rhophieta(self) -> "VectorProtocolSpatial": + def to_rhophieta(self) -> VectorProtocolSpatial: r""" Converts to $\rho$-$\phi$-$\eta$ coordinates, possibly eliminating or imputing dimensions with a projection. """ raise AssertionError - def to_xyzt(self) -> "VectorProtocolLorentz": + def to_xyzt(self) -> VectorProtocolLorentz: """ Converts to $x$-$y$-$z$-$t$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_xyztau(self) -> "VectorProtocolLorentz": + def to_xyztau(self) -> VectorProtocolLorentz: r""" Converts to $x$-$y$-$z$-$\tau$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_xythetat(self) -> "VectorProtocolLorentz": + def to_xythetat(self) -> VectorProtocolLorentz: r""" Converts to $x$-$y$-$\theta$-$t$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_xythetatau(self) -> "VectorProtocolLorentz": + def to_xythetatau(self) -> VectorProtocolLorentz: r""" Converts to $x$-$y$-$\theta$-$\tau$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_xyetat(self) -> "VectorProtocolLorentz": + def to_xyetat(self) -> VectorProtocolLorentz: r""" Converts to $x$-$y$-$\eta$-$t$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_xyetatau(self) -> "VectorProtocolLorentz": + def to_xyetatau(self) -> VectorProtocolLorentz: r""" Converts to $x$-$y$-$\eta$-$\tau$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_rhophizt(self) -> "VectorProtocolLorentz": + def to_rhophizt(self) -> VectorProtocolLorentz: r""" Converts to $\rho$-$\phi$-$z$-$t$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_rhophiztau(self) -> "VectorProtocolLorentz": + def to_rhophiztau(self) -> VectorProtocolLorentz: r""" Converts to $\rho$-$\phi$-$z$-$\tau$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_rhophithetat(self) -> "VectorProtocolLorentz": + def to_rhophithetat(self) -> VectorProtocolLorentz: r""" Converts to $\rho$-$\phi$-$\theta$-$t$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_rhophithetatau(self) -> "VectorProtocolLorentz": + def to_rhophithetatau(self) -> VectorProtocolLorentz: r""" Converts to $\rho$-$\phi$-$\theta$-$\tau$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_rhophietat(self) -> "VectorProtocolLorentz": + def to_rhophietat(self) -> VectorProtocolLorentz: r""" Converts to $\rho$-$\phi$-$\eta$-$t$ coordinates, possibly imputing dimensions with a projection. """ raise AssertionError - def to_rhophietatau(self) -> "VectorProtocolLorentz": + def to_rhophietatau(self) -> VectorProtocolLorentz: r""" Converts to $\rho$-$\phi$-$\eta$-$\tau$ coordinates, possibly imputing dimensions with a projection. @@ -341,7 +343,7 @@ def unit(self: SameVectorType) -> SameVectorType: """ raise AssertionError - def dot(self, other: "VectorProtocol") -> ScalarCollection: + def dot(self, other: VectorProtocol) -> ScalarCollection: """ Vector dot product of ``self`` with ``other``. @@ -349,7 +351,7 @@ def dot(self, other: "VectorProtocol") -> ScalarCollection: """ raise AssertionError - def add(self, other: "VectorProtocol") -> "VectorProtocol": + def add(self, other: VectorProtocol) -> VectorProtocol: """ Sum of ``self`` and ``other``. @@ -357,7 +359,7 @@ def add(self, other: "VectorProtocol") -> "VectorProtocol": """ raise AssertionError - def subtract(self, other: "VectorProtocol") -> "VectorProtocol": + def subtract(self, other: VectorProtocol) -> VectorProtocol: """ Difference of ``self`` minus ``other``. @@ -374,7 +376,7 @@ def scale(self: SameVectorType, factor: ScalarCollection) -> SameVectorType: """ raise AssertionError - def equal(self, other: "VectorProtocol") -> BoolCollection: + def equal(self, other: VectorProtocol) -> BoolCollection: """ Returns True if ``self`` is exactly equal to ``other`` (possibly for arrays of vectors), False otherwise. @@ -386,7 +388,7 @@ def equal(self, other: "VectorProtocol") -> BoolCollection: """ raise AssertionError - def not_equal(self, other: "VectorProtocol") -> BoolCollection: + def not_equal(self, other: VectorProtocol) -> BoolCollection: """ Returns False if ``self`` is exactly equal to ``other`` (possibly for arrays of vectors), True otherwise. @@ -400,7 +402,7 @@ def not_equal(self, other: "VectorProtocol") -> BoolCollection: def isclose( self, - other: "VectorProtocol", + other: VectorProtocol, rtol: ScalarCollection = 1e-05, atol: ScalarCollection = 1e-08, equal_nan: BoolCollection = False, @@ -613,7 +615,7 @@ def neg3D(self: SameVectorType) -> SameVectorType: """ raise AssertionError - def cross(self, other: "VectorProtocol") -> "VectorProtocolSpatial": + def cross(self, other: VectorProtocol) -> VectorProtocolSpatial: """ The 3D cross-product of ``self`` with ``other``. @@ -621,18 +623,18 @@ def cross(self, other: "VectorProtocol") -> "VectorProtocolSpatial": """ raise AssertionError - def deltaangle(self, other: "VectorProtocol") -> ScalarCollection: + def deltaangle(self, other: VectorProtocol) -> ScalarCollection: r""" Angle in 3D space between ``self`` and ``other``, which is always positive, between $0$ and $\pi$. """ raise AssertionError - def deltaeta(self, other: "VectorProtocol") -> ScalarCollection: + def deltaeta(self, other: VectorProtocol) -> ScalarCollection: r"""Signed difference in $\eta$ of ``self`` minus ``other``.""" raise AssertionError - def deltaR(self, other: "VectorProtocol") -> ScalarCollection: + def deltaR(self, other: VectorProtocol) -> ScalarCollection: r""" Sum in quadrature of :meth:`vector._methods.VectorProtocolPlanar.deltaphi` and :meth:`vector._methods.VectorProtocolSpatial.deltaeta`: @@ -641,7 +643,7 @@ def deltaR(self, other: "VectorProtocol") -> ScalarCollection: """ raise AssertionError - def deltaR2(self, other: "VectorProtocol") -> ScalarCollection: + def deltaR2(self, other: VectorProtocol) -> ScalarCollection: r""" Square of the sum in quadrature of :meth:`vector._methods.VectorProtocolPlanar.deltaphi` and @@ -672,7 +674,7 @@ def rotateY(self: SameVectorType, angle: ScalarCollection) -> SameVectorType: raise AssertionError def rotate_axis( - self: SameVectorType, axis: "VectorProtocol", angle: ScalarCollection + self: SameVectorType, axis: VectorProtocol, angle: ScalarCollection ) -> SameVectorType: """ Rotates the vector(s) by a given ``angle`` (in radians) around the @@ -773,17 +775,17 @@ def transform3D(self: SameVectorType, obj: TransformProtocol3D) -> SameVectorTyp raise AssertionError def is_parallel( - self, other: "VectorProtocol", tolerance: ScalarCollection = 1e-5 + self, other: VectorProtocol, tolerance: ScalarCollection = 1e-5 ) -> BoolCollection: raise AssertionError def is_antiparallel( - self, other: "VectorProtocol", tolerance: ScalarCollection = 1e-5 + self, other: VectorProtocol, tolerance: ScalarCollection = 1e-5 ) -> BoolCollection: raise AssertionError def is_perpendicular( - self, other: "VectorProtocol", tolerance: ScalarCollection = 1e-5 + self, other: VectorProtocol, tolerance: ScalarCollection = 1e-5 ) -> BoolCollection: raise AssertionError @@ -879,7 +881,7 @@ def rapidity(self) -> ScalarCollection: """ raise AssertionError - def deltaRapidityPhi(self, other: "VectorProtocol") -> ScalarCollection: + def deltaRapidityPhi(self, other: VectorProtocol) -> ScalarCollection: r""" Sum in quadrature of :meth:`vector._methods.VectorProtocolPlanar.deltaphi` and the difference in :attr:`vector._methods.VectorProtocolLorentz.rapidity` @@ -889,7 +891,7 @@ def deltaRapidityPhi(self, other: "VectorProtocol") -> ScalarCollection: """ raise AssertionError - def deltaRapidityPhi2(self, other: "VectorProtocol") -> ScalarCollection: + def deltaRapidityPhi2(self, other: VectorProtocol) -> ScalarCollection: r""" Square of the sum in quadrature of :meth:`vector._methods.VectorProtocolPlanar.deltaphi` and the difference in @@ -908,7 +910,7 @@ def neg4D(self: SameVectorType) -> SameVectorType: """Same as multiplying by -1.""" raise AssertionError - def boost_p4(self: SameVectorType, p4: "VectorProtocolLorentz") -> SameVectorType: + def boost_p4(self: SameVectorType, p4: VectorProtocolLorentz) -> SameVectorType: """ Boosts the vector or array of vectors in a direction and magnitude given by the 4D vector or array of vectors ``p4``. @@ -935,7 +937,7 @@ def boost_p4(self: SameVectorType, p4: "VectorProtocolLorentz") -> SameVectorTyp raise AssertionError def boost_beta3( - self: SameVectorType, beta3: "VectorProtocolSpatial" + self: SameVectorType, beta3: VectorProtocolSpatial ) -> SameVectorType: """ Boosts the vector or array of vectors in a direction and magnitude given @@ -953,7 +955,7 @@ def boost_beta3( """ raise AssertionError - def boost(self: SameVectorType, booster: "VectorProtocol") -> SameVectorType: + def boost(self: SameVectorType, booster: VectorProtocol) -> SameVectorType: """ Boosts the vector or array of vectors using the 3D or 4D ``booster``. @@ -976,7 +978,7 @@ def boost(self: SameVectorType, booster: "VectorProtocol") -> SameVectorType: raise AssertionError def boostCM_of_p4( - self: SameVectorType, p4: "VectorProtocolLorentz" + self: SameVectorType, p4: VectorProtocolLorentz ) -> SameVectorType: """ Boosts the vector or array of vectors to the center-of-mass (CM) frame of @@ -994,7 +996,7 @@ def boostCM_of_p4( raise AssertionError def boostCM_of_beta3( - self: SameVectorType, beta3: "VectorProtocolSpatial" + self: SameVectorType, beta3: VectorProtocolSpatial ) -> SameVectorType: """ Boosts the vector or array of vectors to the center-of-mass (CM) frame of @@ -1005,7 +1007,7 @@ def boostCM_of_beta3( """ raise AssertionError - def boostCM_of(self: SameVectorType, booster: "VectorProtocol") -> SameVectorType: + def boostCM_of(self: SameVectorType, booster: VectorProtocol) -> SameVectorType: """ Boosts the vector or array of vectors to the center-of-mass (CM) frame of the 3D or 4D ``booster``. @@ -1024,8 +1026,8 @@ def boostCM_of(self: SameVectorType, booster: "VectorProtocol") -> SameVectorTyp def boostX( self: SameVectorType, - beta: typing.Optional[ScalarCollection] = None, - gamma: typing.Optional[ScalarCollection] = None, + beta: ScalarCollection | None = None, + gamma: ScalarCollection | None = None, ) -> SameVectorType: """ Boosts the vector or array of vectors in the $x$ direction by a speed @@ -1041,8 +1043,8 @@ def boostX( def boostY( self: SameVectorType, - beta: typing.Optional[ScalarCollection] = None, - gamma: typing.Optional[ScalarCollection] = None, + beta: ScalarCollection | None = None, + gamma: ScalarCollection | None = None, ) -> SameVectorType: """ Boosts the vector or array of vectors in the $y$ direction by a speed @@ -1058,8 +1060,8 @@ def boostY( def boostZ( self: SameVectorType, - beta: typing.Optional[ScalarCollection] = None, - gamma: typing.Optional[ScalarCollection] = None, + beta: ScalarCollection | None = None, + gamma: ScalarCollection | None = None, ) -> SameVectorType: """ Boosts the vector or array of vectors in the $z$ direction by a speed @@ -1089,7 +1091,7 @@ def transform4D(self: SameVectorType, obj: TransformProtocol4D) -> SameVectorTyp """ raise AssertionError - def to_beta3(self) -> "VectorProtocolSpatial": + def to_beta3(self) -> VectorProtocolSpatial: """ Converts the 4D Lorentz vector or array of vectors into a 3D velocity vector or array of vectors, in which lightlike velocities have @@ -2172,20 +2174,20 @@ def boost(self: SameVectorType, booster: VectorProtocol) -> SameVectorType: ) def boostCM_of_p4( - self: SameVectorType, p4: "VectorProtocolLorentz" + self: SameVectorType, p4: VectorProtocolLorentz ) -> SameVectorType: from vector._compute.lorentz import boost_p4 return boost_p4.dispatch(self, p4.neg3D) def boostCM_of_beta3( - self: SameVectorType, beta3: "VectorProtocolSpatial" + self: SameVectorType, beta3: VectorProtocolSpatial ) -> SameVectorType: from vector._compute.lorentz import boost_beta3 return boost_beta3.dispatch(self, beta3.neg3D) - def boostCM_of(self: SameVectorType, booster: "VectorProtocol") -> SameVectorType: + def boostCM_of(self: SameVectorType, booster: VectorProtocol) -> SameVectorType: from vector._compute.lorentz import boost_beta3, boost_p4 if isinstance(booster, Vector3D): @@ -2200,8 +2202,8 @@ def boostCM_of(self: SameVectorType, booster: "VectorProtocol") -> SameVectorTyp def boostX( self: SameVectorType, - beta: typing.Optional[ScalarCollection] = None, - gamma: typing.Optional[ScalarCollection] = None, + beta: ScalarCollection | None = None, + gamma: ScalarCollection | None = None, ) -> SameVectorType: from vector._compute.lorentz import boostX_beta, boostX_gamma @@ -2214,8 +2216,8 @@ def boostX( def boostY( self: SameVectorType, - beta: typing.Optional[ScalarCollection] = None, - gamma: typing.Optional[ScalarCollection] = None, + beta: ScalarCollection | None = None, + gamma: ScalarCollection | None = None, ) -> SameVectorType: from vector._compute.lorentz import boostY_beta, boostY_gamma @@ -2228,8 +2230,8 @@ def boostY( def boostZ( self: SameVectorType, - beta: typing.Optional[ScalarCollection] = None, - gamma: typing.Optional[ScalarCollection] = None, + beta: ScalarCollection | None = None, + gamma: ScalarCollection | None = None, ) -> SameVectorType: from vector._compute.lorentz import boostZ_beta, boostZ_gamma @@ -2624,7 +2626,7 @@ def _compute_module_of( ] -def _aztype(obj: VectorProtocolPlanar) -> typing.Type[Coordinates]: +def _aztype(obj: VectorProtocolPlanar) -> type[Coordinates]: """ Determines the Azimuthal type of a vector for use in looking up a dispatched function. @@ -2636,7 +2638,7 @@ def _aztype(obj: VectorProtocolPlanar) -> typing.Type[Coordinates]: raise AssertionError(repr(obj)) -def _ltype(obj: VectorProtocolSpatial) -> typing.Type[Coordinates]: +def _ltype(obj: VectorProtocolSpatial) -> type[Coordinates]: """ Determines the Longitudinal type of a vector for use in looking up a dispatched function. @@ -2648,7 +2650,7 @@ def _ltype(obj: VectorProtocolSpatial) -> typing.Type[Coordinates]: raise AssertionError(repr(obj)) -def _ttype(obj: VectorProtocolLorentz) -> typing.Type[Coordinates]: +def _ttype(obj: VectorProtocolLorentz) -> type[Coordinates]: """ Determines the Temporal type of a vector for use in looking up a dispatched function. @@ -2665,7 +2667,7 @@ def _lib_of(*objects: VectorProtocol) -> Module: # NumPy-like module Determines the ``lib`` of a vector or set of vectors, complaining if they're incompatible. """ - lib: typing.Optional[typing.Any] = None + lib: typing.Any | None = None for obj in objects: if isinstance(obj, Vector): if lib is None: @@ -2681,9 +2683,9 @@ def _lib_of(*objects: VectorProtocol) -> Module: # NumPy-like module def _from_signature( name: str, - dispatch_map: typing.Dict[typing.Any, typing.Any], - signature: typing.Tuple[typing.Any, ...], -) -> typing.Tuple[typing.Any, ...]: + dispatch_map: dict[typing.Any, typing.Any], + signature: tuple[typing.Any, ...], +) -> tuple[typing.Any, ...]: """ Gets a function and its return type from a ``dispatch_map`` and the ``signature`` to search for (complaining if none is found). @@ -2722,7 +2724,7 @@ def _handler_of(*objects: VectorProtocol) -> VectorProtocol: objects to NumPy arrays to Awkward Arrays whenever two are used in the same formula. """ - handler: typing.Optional[VectorProtocol] = None + handler: VectorProtocol | None = None for obj in objects: if not isinstance(obj, Vector): continue @@ -2735,7 +2737,7 @@ def _handler_of(*objects: VectorProtocol) -> VectorProtocol: return handler -def _flavor_of(*objects: VectorProtocol) -> typing.Type[VectorProtocol]: +def _flavor_of(*objects: VectorProtocol) -> type[VectorProtocol]: """ Determines the flavor of the output of a dispatched function, where "flavor" is generic vs momentum. @@ -2743,7 +2745,7 @@ def _flavor_of(*objects: VectorProtocol) -> typing.Type[VectorProtocol]: from vector.backends.numpy import VectorNumpy from vector.backends.object import VectorObject - handler: typing.Optional[VectorProtocol] = None + handler: VectorProtocol | None = None is_momentum = True for obj in objects: if isinstance(obj, Vector): diff --git a/src/vector/_typeutils.py b/src/vector/_typeutils.py index 74eddb7e..0bd9a4e5 100644 --- a/src/vector/_typeutils.py +++ b/src/vector/_typeutils.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import sys import typing @@ -25,7 +27,7 @@ ] -def __dir__() -> typing.List[str]: +def __dir__() -> list[str]: return __all__ diff --git a/src/vector/backends/_numba.py b/src/vector/backends/_numba.py index 033a2251..79d96a28 100644 --- a/src/vector/backends/_numba.py +++ b/src/vector/backends/_numba.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import types import typing diff --git a/src/vector/backends/_numba_object.py b/src/vector/backends/_numba_object.py index 31e1b286..8d7ef4f9 100644 --- a/src/vector/backends/_numba_object.py +++ b/src/vector/backends/_numba_object.py @@ -4,6 +4,7 @@ # or https://github.com/scikit-hep/vector for details. # type: ignore +from __future__ import annotations """ Implements VectorObjects in Numba. diff --git a/src/vector/backends/awkward.py b/src/vector/backends/awkward.py index 61b22d65..83dad616 100644 --- a/src/vector/backends/awkward.py +++ b/src/vector/backends/awkward.py @@ -28,6 +28,8 @@ manages this non-strictness well. """ +from __future__ import annotations + import numbers import types import typing @@ -104,7 +106,7 @@ def __repr__(self) -> str: return f"{type(self).__name__}{self.elements}" @classmethod - def from_fields(cls, array: ak.Array) -> "AzimuthalAwkward": + def from_fields(cls, array: ak.Array) -> AzimuthalAwkward: """ Create a :class:`vector.backends.awkward.AzimuthalAwkwardXY` or a :class:`vector.backends.awkward.AzimuthalAwkwardRhoPhi`, depending on @@ -133,7 +135,7 @@ def from_fields(cls, array: ak.Array) -> "AzimuthalAwkward": ) @classmethod - def from_momentum_fields(cls, array: ak.Array) -> "AzimuthalAwkward": + def from_momentum_fields(cls, array: ak.Array) -> AzimuthalAwkward: """ Create a :class:`vector.backends.awkward.AzimuthalAwkwardXY` or a :class:`vector.backends.awkward.AzimuthalAwkwardRhoPhi`, depending on @@ -185,7 +187,7 @@ def __repr__(self) -> str: return f"{type(self).__name__}{self.elements}" @classmethod - def from_fields(cls, array: ak.Array) -> "LongitudinalAwkward": + def from_fields(cls, array: ak.Array) -> LongitudinalAwkward: """ Create a :class:`vector.backends.awkward.LongitudinalAwkwardZ`, a :class:`vector.backends.awkward.LongitudinalAwkwardTheta`, or a @@ -216,7 +218,7 @@ def from_fields(cls, array: ak.Array) -> "LongitudinalAwkward": ) @classmethod - def from_momentum_fields(cls, array: ak.Array) -> "LongitudinalAwkward": + def from_momentum_fields(cls, array: ak.Array) -> LongitudinalAwkward: """ Create a :class:`vector.backends.awkward.LongitudinalAwkwardZ`, a :class:`vector.backends.awkward.LongitudinalAwkwardTheta`, or a @@ -264,7 +266,7 @@ def __repr__(self) -> str: return f"{type(self).__name__}{self.elements}" @classmethod - def from_fields(cls, array: ak.Array) -> "TemporalAwkward": + def from_fields(cls, array: ak.Array) -> TemporalAwkward: """ Create a :class:`vector.backends.awkward.TemporalT` or a :class:`vector.backends.awkward.TemporalTau`, depending on @@ -292,7 +294,7 @@ def from_fields(cls, array: ak.Array) -> "TemporalAwkward": ) @classmethod - def from_momentum_fields(cls, array: ak.Array) -> "TemporalAwkward": + def from_momentum_fields(cls, array: ak.Array) -> TemporalAwkward: """ Create a :class:`vector.backends.awkward.TemporalT` or a :class:`vector.backends.awkward.TemporalTau`, depending on @@ -354,7 +356,7 @@ def __init__(self, x: typing.Any, y: typing.Any) -> None: self.y = y @property - def elements(self) -> typing.Tuple[ArrayOrRecord, ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord, ArrayOrRecord]: """ Azimuthal coordinates (``x`` and ``y``) as a tuple. @@ -389,7 +391,7 @@ def __init__(self, rho: typing.Any, phi: typing.Any) -> None: self.phi = phi @property - def elements(self) -> typing.Tuple[ArrayOrRecord, ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord, ArrayOrRecord]: """ Azimuthal coordinates (``rho`` and ``phi``) as a tuple. @@ -423,7 +425,7 @@ def __init__(self, z: typing.Any) -> None: self.z = z @property - def elements(self) -> typing.Tuple[ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord]: """ Longitudinal coordinates (``z``) as a tuple. @@ -457,7 +459,7 @@ def __init__(self, theta: typing.Any) -> None: self.theta = theta @property - def elements(self) -> typing.Tuple[ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord]: """ Longitudinal coordinates (``theta``) as a tuple. @@ -491,7 +493,7 @@ def __init__(self, eta: typing.Any) -> None: self.eta = eta @property - def elements(self) -> typing.Tuple[ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord]: """ Longitudinal coordinates (``eta``) as a tuple. @@ -525,7 +527,7 @@ def __init__(self, t: typing.Any) -> None: self.t = t @property - def elements(self) -> typing.Tuple[ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord]: """ Temporal coordinates (``t``) as a tuple. @@ -559,7 +561,7 @@ def __init__(self, tau: typing.Any) -> None: self.tau = tau @property - def elements(self) -> typing.Tuple[ArrayOrRecord]: + def elements(self) -> tuple[ArrayOrRecord]: """ Temporal coordinates (``tau``) as a tuple. @@ -572,7 +574,7 @@ def elements(self) -> typing.Tuple[ArrayOrRecord]: return (self.tau,) -def _class_to_name(cls: typing.Type[VectorProtocol]) -> str: +def _class_to_name(cls: type[VectorProtocol]) -> str: if issubclass(cls, Momentum): if issubclass(cls, Vector2D): # type: ignore[unreachable] return "Momentum2D" # type: ignore[unreachable] @@ -596,19 +598,17 @@ def _class_to_name(cls: typing.Type[VectorProtocol]) -> str: def _yes_record( x: ak.Array, -) -> typing.Optional[typing.Union[float, ak.Record]]: +) -> float | ak.Record | None: return x[0] -def _no_record(x: ak.Array) -> typing.Optional[ak.Array]: +def _no_record(x: ak.Array) -> ak.Array | None: return x # Type for mixing in Awkward later class AwkwardProtocol(Protocol): - def __getitem__( - self, where: typing.Any - ) -> typing.Optional[typing.Union[float, ak.Array, ak.Record]]: + def __getitem__(self, where: typing.Any) -> float | ak.Array | ak.Record | None: ... @@ -1625,10 +1625,7 @@ def _arraytype_of(awkwardtype: typing.Any, component: str) -> typing.Any: def _aztype_of(recordarraytype: typing.Any, is_momentum: bool) -> typing.Any: import numba - cls: typing.Union[ - typing.Type[AzimuthalObjectXY], - typing.Type[AzimuthalObjectRhoPhi], - ] + cls: type[AzimuthalObjectXY] | type[AzimuthalObjectRhoPhi] x_index = None y_index = None @@ -1696,10 +1693,8 @@ def _aztype_of(recordarraytype: typing.Any, is_momentum: bool) -> typing.Any: def _ltype_of(recordarraytype: typing.Any, is_momentum: bool) -> typing.Any: import numba - cls: typing.Union[ - typing.Type[LongitudinalObjectZ], - typing.Type[LongitudinalObjectTheta], - typing.Type[LongitudinalObjectEta], + cls: type[LongitudinalObjectZ] | type[LongitudinalObjectTheta] | type[ + LongitudinalObjectEta ] z_index = None @@ -1753,10 +1748,7 @@ def _ltype_of(recordarraytype: typing.Any, is_momentum: bool) -> typing.Any: def _ttype_of(recordarraytype: typing.Any, is_momentum: bool) -> typing.Any: import numba - cls: typing.Union[ - typing.Type[TemporalObjectT], - typing.Type[TemporalObjectTau], - ] + cls: type[TemporalObjectT] | type[TemporalObjectTau] t_index = None tau_index = None diff --git a/src/vector/backends/awkward_constructors.py b/src/vector/backends/awkward_constructors.py index 8822715f..8b6044c8 100644 --- a/src/vector/backends/awkward_constructors.py +++ b/src/vector/backends/awkward_constructors.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import typing @@ -12,8 +14,8 @@ def _recname(is_momentum: bool, dimension: int) -> str: def _check_names( - projectable: typing.Any, fieldnames: typing.List[str] -) -> typing.Tuple[bool, int, typing.List[str], typing.Any]: + projectable: typing.Any, fieldnames: list[str] +) -> tuple[bool, int, list[str], typing.Any]: complaint1 = "duplicate coordinates (through momentum-aliases): " + ", ".join( repr(x) for x in fieldnames ) @@ -339,9 +341,7 @@ def Array(*args: typing.Any, **kwargs: typing.Any) -> typing.Any: ) -def zip( - arrays: typing.Dict[str, typing.Any], depth_limit: typing.Optional[int] = None -) -> typing.Any: +def zip(arrays: dict[str, typing.Any], depth_limit: int | None = None) -> typing.Any: """ Constructs an Awkward Array of vectors, whose type is determined by the fields of the record array (which may be nested within lists or other non-record structures). diff --git a/src/vector/backends/numpy.py b/src/vector/backends/numpy.py index c0558c28..769e6966 100644 --- a/src/vector/backends/numpy.py +++ b/src/vector/backends/numpy.py @@ -14,6 +14,8 @@ arrays). """ +from __future__ import annotations + import collections.abc import typing @@ -55,7 +57,7 @@ ArrayLike = ScalarCollection -def _array_from_columns(columns: typing.Dict[str, ArrayLike]) -> ArrayLike: +def _array_from_columns(columns: dict[str, ArrayLike]) -> ArrayLike: """ Converts a dictionary (or columns) of coordinates to an array. @@ -81,7 +83,7 @@ def _array_from_columns(columns: typing.Dict[str, ArrayLike]) -> ArrayLike: ) dtype = [] - shape: typing.Optional[typing.Tuple[int, ...]] = None + shape: tuple[int, ...] | None = None for x in names: if hasattr(columns[x], "dtype"): thisdtype = (x, columns[x].dtype) @@ -109,7 +111,7 @@ def _array_from_columns(columns: typing.Dict[str, ArrayLike]) -> ArrayLike: def _setitem( - array: typing.Union["VectorNumpy2D", "VectorNumpy3D", "VectorNumpy4D"], + array: VectorNumpy2D | VectorNumpy3D | VectorNumpy4D, where: typing.Any, what: typing.Any, is_momentum: bool, @@ -133,10 +135,10 @@ def _setitem( def _getitem( - array: typing.Union["VectorNumpy2D", "VectorNumpy3D", "VectorNumpy4D"], + array: VectorNumpy2D | VectorNumpy3D | VectorNumpy4D, where: typing.Any, is_momentum: bool, -) -> typing.Union[float, FloatArray]: +) -> float | FloatArray: """ Implementation for the ``__getitem__`` method. See :class:`GetItem` for more details. @@ -174,7 +176,7 @@ def _getitem( def _array_repr( - array: typing.Union["VectorNumpy2D", "VectorNumpy3D", "VectorNumpy4D"], + array: VectorNumpy2D | VectorNumpy3D | VectorNumpy4D, is_momentum: bool, ) -> str: """ @@ -187,16 +189,14 @@ def _array_repr( def _has( - array: typing.Union[ - "VectorNumpy2D", - "VectorNumpy3D", - "VectorNumpy4D", - "MomentumNumpy2D", - "MomentumNumpy3D", - "MomentumNumpy4D", - "CoordinatesNumpy", - ], - names: typing.Tuple[str, ...], + array: VectorNumpy2D + | VectorNumpy3D + | VectorNumpy4D + | MomentumNumpy2D + | MomentumNumpy3D + | MomentumNumpy4D + | CoordinatesNumpy, + names: tuple[str, ...], ) -> bool: """ Checks if a NumPy vector has the provided coordinate attributes. @@ -229,8 +229,8 @@ def _has( def _toarrays( - result: typing.Union[typing.Tuple[ScalarCollection, ...], ScalarCollection] -) -> typing.Tuple[FloatArray, ...]: + result: tuple[ScalarCollection, ...] | ScalarCollection +) -> tuple[FloatArray, ...]: """ Converts a tuple of values to a tuple of ``numpy.array``s. @@ -263,9 +263,7 @@ def _toarrays( return result[0] -def _shape_of( - result: typing.Union[typing.Tuple[FloatArray, ...], ScalarCollection] -) -> typing.Tuple[int, ...]: +def _shape_of(result: tuple[FloatArray, ...] | ScalarCollection) -> tuple[int, ...]: """ Calculates the shape of a tuple of ``numpy.array``s. The shape returned is the highest (numerical) value of the shapes present in the tuple. @@ -288,7 +286,7 @@ def _shape_of( """ if not isinstance(result, tuple): result = (result,) - shape: typing.Optional[typing.List[int]] = None + shape: list[int] | None = None for x in result: if hasattr(x, "shape"): thisshape = list(x.shape) @@ -302,15 +300,13 @@ def _shape_of( def _is_type_safe( - array: typing.Union[ - "VectorNumpy2D", - "VectorNumpy3D", - "VectorNumpy4D", - "MomentumNumpy2D", - "MomentumNumpy3D", - "MomentumNumpy4D", - "CoordinatesNumpy", - ], + array: VectorNumpy2D + | VectorNumpy3D + | VectorNumpy4D + | MomentumNumpy2D + | MomentumNumpy3D + | MomentumNumpy4D + | CoordinatesNumpy, ) -> bool: for i in range(0, len(array.dtype)): # type: ignore[arg-type] if not issubclass( @@ -329,10 +325,10 @@ def __getitem__(self, where: str) -> FloatArray: ... @typing.overload - def __getitem__(self, where: typing.Any) -> typing.Union[float, FloatArray]: + def __getitem__(self, where: typing.Any) -> float | FloatArray: ... - def __getitem__(self, where: typing.Any) -> typing.Union[float, FloatArray]: + def __getitem__(self, where: typing.Any) -> float | FloatArray: return _getitem(self, where, self.__class__._IS_MOMENTUM) # type: ignore[arg-type] @@ -340,25 +336,25 @@ class CoordinatesNumpy: """Coordinates class for the Numpy backend.""" lib = numpy - dtype: "numpy.dtype[typing.Any]" + dtype: numpy.dtype[typing.Any] class AzimuthalNumpy(CoordinatesNumpy, Azimuthal): """Azimuthal class for the NumPy backend.""" - ObjectClass: typing.Type[vector.backends.object.AzimuthalObject] + ObjectClass: type[vector.backends.object.AzimuthalObject] class LongitudinalNumpy(CoordinatesNumpy, Longitudinal): """Longitudinal class for the NumPy backend.""" - ObjectClass: typing.Type[vector.backends.object.LongitudinalObject] + ObjectClass: type[vector.backends.object.LongitudinalObject] class TemporalNumpy(CoordinatesNumpy, Temporal): """Temporal class for the NumPy backend.""" - ObjectClass: typing.Type[vector.backends.object.TemporalObject] + ObjectClass: type[vector.backends.object.TemporalObject] class AzimuthalNumpyXY(AzimuthalNumpy, AzimuthalXY, GetItem, FloatArray): # type: ignore[misc] @@ -376,7 +372,7 @@ class AzimuthalNumpyXY(AzimuthalNumpy, AzimuthalXY, GetItem, FloatArray): # typ ObjectClass = vector.backends.object.AzimuthalObjectXY _IS_MOMENTUM = False - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "AzimuthalNumpyXY": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> AzimuthalNumpyXY: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -387,7 +383,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray, FloatArray]: + def elements(self) -> tuple[FloatArray, FloatArray]: """ Azimuthal coordinates (``x`` and ``y``) as a tuple. @@ -427,7 +423,7 @@ class AzimuthalNumpyRhoPhi(AzimuthalNumpy, AzimuthalRhoPhi, GetItem, FloatArray) ObjectClass = vector.backends.object.AzimuthalObjectRhoPhi _IS_MOMENTUM = False - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "AzimuthalNumpyRhoPhi": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> AzimuthalNumpyRhoPhi: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -438,7 +434,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray, FloatArray]: + def elements(self) -> tuple[FloatArray, FloatArray]: """ Azimuthal coordinates (``rho`` and ``phi``) as a tuple. @@ -477,7 +473,7 @@ class LongitudinalNumpyZ(LongitudinalNumpy, LongitudinalZ, GetItem, FloatArray): ObjectClass = vector.backends.object.LongitudinalObjectZ _IS_MOMENTUM = False - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "LongitudinalNumpyZ": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> LongitudinalNumpyZ: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -488,7 +484,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray]: + def elements(self) -> tuple[FloatArray]: """ Longitudinal coordinates (``z``) as a tuple. @@ -522,9 +518,7 @@ class LongitudinalNumpyTheta(LongitudinalNumpy, LongitudinalTheta, GetItem, Floa ObjectClass = vector.backends.object.LongitudinalObjectTheta _IS_MOMENTUM = False - def __new__( - cls, *args: typing.Any, **kwargs: typing.Any - ) -> "LongitudinalNumpyTheta": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> LongitudinalNumpyTheta: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -535,7 +529,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray]: + def elements(self) -> tuple[FloatArray]: """ Longitudinal coordinates (``theta``) as a tuple. @@ -569,7 +563,7 @@ class LongitudinalNumpyEta(LongitudinalNumpy, LongitudinalEta, GetItem, FloatArr ObjectClass = vector.backends.object.LongitudinalObjectEta _IS_MOMENTUM = False - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "LongitudinalNumpyEta": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> LongitudinalNumpyEta: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -580,7 +574,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray]: + def elements(self) -> tuple[FloatArray]: """ Longitudinal coordinates (``eta``) as a tuple. @@ -614,7 +608,7 @@ class TemporalNumpyT(TemporalNumpy, TemporalT, GetItem, FloatArray): # type: ig ObjectClass = vector.backends.object.TemporalObjectT _IS_MOMENTUM = False - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "TemporalNumpyT": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> TemporalNumpyT: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -625,7 +619,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray]: + def elements(self) -> tuple[FloatArray]: """ Temporal coordinates (``t``) as a tuple. @@ -651,7 +645,7 @@ class TemporalNumpyTau(TemporalNumpy, TemporalTau, GetItem, FloatArray): # type ObjectClass = vector.backends.object.TemporalObjectTau _IS_MOMENTUM = False - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "TemporalNumpyTau": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> TemporalNumpyTau: return numpy.array(*args, **kwargs).view(cls) def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] @@ -662,7 +656,7 @@ def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] ) @property - def elements(self) -> typing.Tuple[FloatArray]: + def elements(self) -> tuple[FloatArray]: """ Temporal coordinates (``tau``) as a tuple. @@ -686,14 +680,14 @@ class VectorNumpy(Vector, GetItem): """One dimensional vector class for the NumPy backend.""" lib = numpy - dtype: "numpy.dtype[typing.Any]" + dtype: numpy.dtype[typing.Any] def allclose( self, other: VectorProtocol, - rtol: typing.Union[float, FloatArray] = 1e-05, - atol: typing.Union[float, FloatArray] = 1e-08, - equal_nan: typing.Union[bool, FloatArray] = False, + rtol: float | FloatArray = 1e-05, + atol: float | FloatArray = 1e-08, + equal_nan: bool | FloatArray = False, ) -> FloatArray: """Like ``np.ndarray.allclose``, but for VectorNumpy.""" return self.isclose(other, rtol=rtol, atol=atol, equal_nan=equal_nan).all() @@ -704,7 +698,7 @@ def __eq__(self, other: typing.Any) -> typing.Any: def __ne__(self, other: typing.Any) -> typing.Any: return numpy.not_equal(self, other) - def __reduce__(self) -> typing.Union[str, typing.Tuple[typing.Any, ...]]: + def __reduce__(self) -> str | tuple[typing.Any, ...]: pickled_state = super().__reduce__() new_state = (*pickled_state[2], self.__dict__) return pickled_state[0], pickled_state[1], new_state @@ -731,7 +725,7 @@ def __array_ufunc__( # Let a higher-precedence backend handle it. return NotImplemented - outputs: typing.Tuple["VectorNumpy", ...] = kwargs.get("out", ()) + outputs: tuple[VectorNumpy, ...] = kwargs.get("out", ()) if any(not isinstance(x, VectorNumpy) for x in outputs): raise TypeError( "ufunc operating on VectorNumpys can only use the 'out' keyword " @@ -960,11 +954,9 @@ class VectorNumpy2D(VectorNumpy, Planar, Vector2D, FloatArray): # type: ignore[ ObjectClass = vector.backends.object.VectorObject2D _IS_MOMENTUM = False - _azimuthal_type: typing.Union[ - typing.Type[AzimuthalNumpyXY], typing.Type[AzimuthalNumpyRhoPhi] - ] + _azimuthal_type: type[AzimuthalNumpyXY] | type[AzimuthalNumpyRhoPhi] - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "VectorNumpy2D": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> VectorNumpy2D: """Returns the object of ``VectorNumpy2D``. Behaves as ``__init__`` in this case.""" if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], dict): array = _array_from_columns(args[0]) @@ -1179,7 +1171,7 @@ class MomentumNumpy2D(PlanarMomentum, VectorNumpy2D): # type: ignore[misc] ObjectClass = vector.backends.object.MomentumObject2D _IS_MOMENTUM = True - dtype: "numpy.dtype[typing.Any]" + dtype: numpy.dtype[typing.Any] def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] if obj is None: @@ -1229,16 +1221,12 @@ class VectorNumpy3D(VectorNumpy, Spatial, Vector3D, FloatArray): # type: ignore ObjectClass = vector.backends.object.VectorObject3D _IS_MOMENTUM = False - _azimuthal_type: typing.Union[ - typing.Type[AzimuthalNumpyXY], typing.Type[AzimuthalNumpyRhoPhi] - ] - _longitudinal_type: typing.Union[ - typing.Type[LongitudinalNumpyZ], - typing.Type[LongitudinalNumpyTheta], - typing.Type[LongitudinalNumpyEta], + _azimuthal_type: type[AzimuthalNumpyXY] | type[AzimuthalNumpyRhoPhi] + _longitudinal_type: type[LongitudinalNumpyZ] | type[LongitudinalNumpyTheta] | type[ + LongitudinalNumpyEta ] - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "VectorNumpy3D": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> VectorNumpy3D: """Returns the object of ``VectorNumpy3D``. Behaves as ``__init__`` in this case.""" if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], dict): array = _array_from_columns(args[0]) @@ -1464,7 +1452,7 @@ class MomentumNumpy3D(SpatialMomentum, VectorNumpy3D): # type: ignore[misc] ObjectClass = vector.backends.object.MomentumObject3D _IS_MOMENTUM = True - dtype: "numpy.dtype[typing.Any]" + dtype: numpy.dtype[typing.Any] def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] if obj is None: @@ -1525,20 +1513,13 @@ class VectorNumpy4D(VectorNumpy, Lorentz, Vector4D, FloatArray): # type: ignore ObjectClass = vector.backends.object.VectorObject4D _IS_MOMENTUM = False - _azimuthal_type: typing.Union[ - typing.Type[AzimuthalNumpyXY], typing.Type[AzimuthalNumpyRhoPhi] - ] - _longitudinal_type: typing.Union[ - typing.Type[LongitudinalNumpyZ], - typing.Type[LongitudinalNumpyTheta], - typing.Type[LongitudinalNumpyEta], - ] - _temporal_type: typing.Union[ - typing.Type[TemporalNumpyT], - typing.Type[TemporalNumpyTau], + _azimuthal_type: type[AzimuthalNumpyXY] | type[AzimuthalNumpyRhoPhi] + _longitudinal_type: type[LongitudinalNumpyZ] | type[LongitudinalNumpyTheta] | type[ + LongitudinalNumpyEta ] + _temporal_type: type[TemporalNumpyT] | type[TemporalNumpyTau] - def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> "VectorNumpy4D": + def __new__(cls, *args: typing.Any, **kwargs: typing.Any) -> VectorNumpy4D: """Returns the object of ``VectorNumpy4D``. Behaves as ``__init__`` in this case.""" if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], dict): array = _array_from_columns(args[0]) @@ -1790,7 +1771,7 @@ class MomentumNumpy4D(LorentzMomentum, VectorNumpy4D): # type: ignore[misc] ObjectClass = vector.backends.object.MomentumObject4D _IS_MOMENTUM = True - dtype: "numpy.dtype[typing.Any]" + dtype: numpy.dtype[typing.Any] def __array_finalize__(self, obj: typing.Any) -> None: # type: ignore[override] if obj is None: @@ -1897,7 +1878,7 @@ def array(*args: typing.Any, **kwargs: typing.Any) -> VectorNumpy: to make the vector a momentum vector. """ - names: typing.Tuple[str, ...] + names: tuple[str, ...] if len(args) == 1 and len(kwargs) == 0 and isinstance(args[0], dict): names = tuple(args[0].keys()) elif "dtype" in kwargs: @@ -1907,7 +1888,7 @@ def array(*args: typing.Any, **kwargs: typing.Any) -> VectorNumpy: else: names = () - cls: typing.Type[VectorNumpy] + cls: type[VectorNumpy] is_momentum = any(x in _repr_momentum_to_generic for x in names) diff --git a/src/vector/backends/object.py b/src/vector/backends/object.py index 8f109fbc..19b44d42 100644 --- a/src/vector/backends/object.py +++ b/src/vector/backends/object.py @@ -21,6 +21,8 @@ vec = vector.VectorObject2D.from_xy(1, 2) """ +from __future__ import annotations + import numbers import typing @@ -97,7 +99,7 @@ class AzimuthalObjectXY(AzimuthalObject, AzimuthalXY, TupleXY): """ @property - def elements(self) -> typing.Tuple[float, float]: + def elements(self) -> tuple[float, float]: """ Azimuthal coordinates (``x`` and ``y``) as a tuple. Each coordinate is a scalar and not a vector. @@ -126,7 +128,7 @@ class AzimuthalObjectRhoPhi(AzimuthalObject, AzimuthalRhoPhi, TupleRhoPhi): """ @property - def elements(self) -> typing.Tuple[float, float]: + def elements(self) -> tuple[float, float]: """ Azimuthal coordinates (``rho`` and ``phi``) as a tuple. Each coordinate is a scalar and not a vector. @@ -154,7 +156,7 @@ class LongitudinalObjectZ(LongitudinalObject, LongitudinalZ, TupleZ): """ @property - def elements(self) -> typing.Tuple[float]: + def elements(self) -> tuple[float]: """ Longitudinal coordinates (``z``) as a tuple. Each coordinate is a scalar and not a vector. @@ -182,7 +184,7 @@ class LongitudinalObjectTheta(LongitudinalObject, LongitudinalTheta, TupleTheta) """ @property - def elements(self) -> typing.Tuple[float]: + def elements(self) -> tuple[float]: """ Longitudinal coordinates (``theta``) as a tuple. Each coordinate is a scalar and not a vector. @@ -212,7 +214,7 @@ class LongitudinalObjectEta(LongitudinalObject, LongitudinalEta, TupleEta): eta: float @property - def elements(self) -> typing.Tuple[float]: + def elements(self) -> tuple[float]: """ Longitudinal coordinates (``theta``) as a tuple. Each coordinate is a scalar and not a vector. @@ -242,7 +244,7 @@ class TemporalObjectT(TemporalObject, TemporalT, TupleT): t: float @property - def elements(self) -> typing.Tuple[float]: + def elements(self) -> tuple[float]: """ Temporal coordinates (``t``) as a tuple. Each coordinate is a scalar and not a vector. @@ -270,7 +272,7 @@ class TemporalObjectTau(TemporalObject, TemporalTau, TupleTau): """ @property - def elements(self) -> typing.Tuple[float]: + def elements(self) -> tuple[float]: """ Temporal coordinates (``tau``) as a tuple. Each coordinate is a scalar and not a vector. @@ -612,7 +614,7 @@ class VectorObject2D(VectorObject, Planar, Vector2D): azimuthal: AzimuthalObject @classmethod - def from_xy(cls, x: float, y: float) -> "VectorObject2D": + def from_xy(cls, x: float, y: float) -> VectorObject2D: """ Constructs a ``VectorObject2D`` from Cartesian coordinates. @@ -628,7 +630,7 @@ def from_xy(cls, x: float, y: float) -> "VectorObject2D": return cls(AzimuthalObjectXY(x, y)) @classmethod - def from_rhophi(cls, rho: float, phi: float) -> "VectorObject2D": + def from_rhophi(cls, rho: float, phi: float) -> VectorObject2D: """ Constructs a ``VectorObject2D`` from polar coordinates. @@ -847,7 +849,7 @@ class VectorObject3D(VectorObject, Spatial, Vector3D): longitudinal: LongitudinalObject @classmethod - def from_xyz(cls, x: float, y: float, z: float) -> "VectorObject3D": + def from_xyz(cls, x: float, y: float, z: float) -> VectorObject3D: """ Constructs a ``VectorObject3D`` from Cartesian coordinates. @@ -863,7 +865,7 @@ def from_xyz(cls, x: float, y: float, z: float) -> "VectorObject3D": return cls(AzimuthalObjectXY(x, y), LongitudinalObjectZ(z)) @classmethod - def from_xytheta(cls, x: float, y: float, theta: float) -> "VectorObject3D": + def from_xytheta(cls, x: float, y: float, theta: float) -> VectorObject3D: r""" Constructs a ``VectorObject3D`` from Cartesian azimuthal coordinates and a polar angle $\theta$. @@ -880,7 +882,7 @@ def from_xytheta(cls, x: float, y: float, theta: float) -> "VectorObject3D": return cls(AzimuthalObjectXY(x, y), LongitudinalObjectTheta(theta)) @classmethod - def from_xyeta(cls, x: float, y: float, eta: float) -> "VectorObject3D": + def from_xyeta(cls, x: float, y: float, eta: float) -> VectorObject3D: r""" Constructs a ``VectorObject3D`` from Cartesian coordinates and a pseudorapidity $\eta$. @@ -897,7 +899,7 @@ def from_xyeta(cls, x: float, y: float, eta: float) -> "VectorObject3D": return cls(AzimuthalObjectXY(x, y), LongitudinalObjectEta(eta)) @classmethod - def from_rhophiz(cls, rho: float, phi: float, z: float) -> "VectorObject3D": + def from_rhophiz(cls, rho: float, phi: float, z: float) -> VectorObject3D: """ Constructs a ``VectorObject3D`` from polar azimuthal coordinates and a Cartesian longitudinal coordinate $z$. @@ -914,7 +916,7 @@ def from_rhophiz(cls, rho: float, phi: float, z: float) -> "VectorObject3D": return cls(AzimuthalObjectRhoPhi(rho, phi), LongitudinalObjectZ(z)) @classmethod - def from_rhophitheta(cls, rho: float, phi: float, theta: float) -> "VectorObject3D": + def from_rhophitheta(cls, rho: float, phi: float, theta: float) -> VectorObject3D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates and a polar angle $\theta$. @@ -931,7 +933,7 @@ def from_rhophitheta(cls, rho: float, phi: float, theta: float) -> "VectorObject return cls(AzimuthalObjectRhoPhi(rho, phi), LongitudinalObjectTheta(theta)) @classmethod - def from_rhophieta(cls, rho: float, phi: float, eta: float) -> "VectorObject3D": + def from_rhophieta(cls, rho: float, phi: float, eta: float) -> VectorObject3D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates and a pseudorapidity $\eta$. @@ -1210,7 +1212,7 @@ def from_xyzt( y: float, z: float, t: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: """ Constructs a ``VectorObject3D`` from Cartesian coordinates and a time coordinate $t$. @@ -1233,7 +1235,7 @@ def from_xyztau( y: float, z: float, tau: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from Cartesian coordinates and a proper time coordinate $\tau$. @@ -1258,7 +1260,7 @@ def from_xythetat( y: float, theta: float, t: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from Cartesian azimuthal coordinates, a polar angle $\theta$, and a time coordinate $t$. @@ -1283,7 +1285,7 @@ def from_xythetatau( y: float, theta: float, tau: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from Cartesian azimuthal coordinates, a polar angle $\theta$, and a proper time coordinate $\tau$. @@ -1310,7 +1312,7 @@ def from_xyetat( y: float, eta: float, t: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from Cartesian coordinates, a pseudorapidity $\eta$, and a time coordinate $t$. @@ -1335,7 +1337,7 @@ def from_xyetatau( y: float, eta: float, tau: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from Cartesian coordinates, a pseudorapidity $\eta$, and a proper time coordinate $\tau$. @@ -1360,7 +1362,7 @@ def from_rhophizt( phi: float, z: float, t: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: """ Constructs a ``VectorObject3D`` from polar azimuthal coordinates, a Cartesian longitudinal coordinate $z$, and a time coordinate $t$. @@ -1385,7 +1387,7 @@ def from_rhophiztau( phi: float, z: float, tau: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates, a Cartesian longitudinal coordinate $z$, and a proper time coordinate $\tau$. @@ -1412,7 +1414,7 @@ def from_rhophithetat( phi: float, theta: float, t: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates, a polar angle $\theta$, and a time coordinate $t$. @@ -1439,7 +1441,7 @@ def from_rhophithetatau( phi: float, theta: float, tau: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates, a polar angle $\theta$, and a proper time coordinate $\tau$. @@ -1466,7 +1468,7 @@ def from_rhophietat( phi: float, eta: float, t: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates, a pseudorapidity $\eta$, and a time coordinate $t$. @@ -1493,7 +1495,7 @@ def from_rhophietatau( phi: float, eta: float, tau: float, - ) -> "VectorObject4D": + ) -> VectorObject4D: r""" Constructs a ``VectorObject3D`` from polar azimuthal coordinates, a pseudorapidity $\eta$, and a proper time coordinate $\tau$. @@ -1821,10 +1823,10 @@ def mass(self, mass: float) -> None: def _gather_coordinates( - planar_class: typing.Type[VectorObject2D], - spatial_class: typing.Type[VectorObject3D], - lorentz_class: typing.Type[VectorObject4D], - coordinates: typing.Dict[str, typing.Any], + planar_class: type[VectorObject2D], + spatial_class: type[VectorObject3D], + lorentz_class: type[VectorObject4D], + coordinates: dict[str, typing.Any], ) -> typing.Any: """ Helper function for :func:`vector.backends.object.obj`. @@ -1834,9 +1836,7 @@ def _gather_coordinates( spatial (``VectorObject3D`` or ``MomentumObject3D``), and lorentz (``VectorObject4D`` or ``MomentumObject4D``) classes. """ - azimuthal: typing.Optional[ - typing.Union[AzimuthalObjectXY, AzimuthalObjectRhoPhi] - ] = None + azimuthal: None | (AzimuthalObjectXY | AzimuthalObjectRhoPhi) = None if "x" in coordinates and "y" in coordinates: if "rho" in coordinates or "phi" in coordinates: @@ -1849,11 +1849,9 @@ def _gather_coordinates( coordinates.pop("rho"), coordinates.pop("phi") ) - longitudinal: typing.Optional[ - typing.Union[ - LongitudinalObjectZ, LongitudinalObjectTheta, LongitudinalObjectEta - ] - ] = None + longitudinal: None | ( + LongitudinalObjectZ | LongitudinalObjectTheta | LongitudinalObjectEta + ) = None if "z" in coordinates: if "theta" in coordinates or "eta" in coordinates: @@ -1866,7 +1864,7 @@ def _gather_coordinates( elif "eta" in coordinates: longitudinal = LongitudinalObjectEta(coordinates.pop("eta")) - temporal: typing.Optional[typing.Union[TemporalObjectT, TemporalObjectTau]] = None + temporal: TemporalObjectT | TemporalObjectTau | None = None if "t" in coordinates: if "tau" in coordinates: diff --git a/src/vector/version.pyi b/src/vector/version.pyi index 5bb2b22f..91744f98 100644 --- a/src/vector/version.pyi +++ b/src/vector/version.pyi @@ -1,2 +1,4 @@ +from __future__ import annotations + version: str version_tuple: tuple[int, int, int] | tuple[int, int, int, str, str] diff --git a/tests/backends/test_awkward.py b/tests/backends/test_awkward.py index fbc850b2..ebe1e898 100644 --- a/tests/backends/test_awkward.py +++ b/tests/backends/test_awkward.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import os import pytest diff --git a/tests/backends/test_awkward_numba.py b/tests/backends/test_awkward_numba.py index 51907d4b..62f800e5 100644 --- a/tests/backends/test_awkward_numba.py +++ b/tests/backends/test_awkward_numba.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import os import pytest diff --git a/tests/backends/test_numba_numpy.py b/tests/backends/test_numba_numpy.py index 7df04efe..1a7a7f03 100644 --- a/tests/backends/test_numba_numpy.py +++ b/tests/backends/test_numba_numpy.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector diff --git a/tests/backends/test_numba_object.py b/tests/backends/test_numba_object.py index 9a0c76e0..68dd1985 100644 --- a/tests/backends/test_numba_object.py +++ b/tests/backends/test_numba_object.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import sys import numpy diff --git a/tests/backends/test_numpy.py b/tests/backends/test_numpy.py index c75cdd75..a27591c5 100644 --- a/tests/backends/test_numpy.py +++ b/tests/backends/test_numpy.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pickle diff --git a/tests/backends/test_object.py b/tests/backends/test_object.py index e6ecfb1b..7789c5cf 100644 --- a/tests/backends/test_object.py +++ b/tests/backends/test_object.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/backends/test_operators.py b/tests/backends/test_operators.py index 5a7d2cd3..ec8fa226 100644 --- a/tests/backends/test_operators.py +++ b/tests/backends/test_operators.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/lorentz/test_Et.py b/tests/compute/lorentz/test_Et.py index 4a877193..e6180940 100644 --- a/tests/compute/lorentz/test_Et.py +++ b/tests/compute/lorentz/test_Et.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/lorentz/test_Et2.py b/tests/compute/lorentz/test_Et2.py index 36d21255..8412af16 100644 --- a/tests/compute/lorentz/test_Et2.py +++ b/tests/compute/lorentz/test_Et2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_Mt.py b/tests/compute/lorentz/test_Mt.py index 8730f0ac..47800870 100644 --- a/tests/compute/lorentz/test_Mt.py +++ b/tests/compute/lorentz/test_Mt.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/lorentz/test_Mt2.py b/tests/compute/lorentz/test_Mt2.py index 7cef75ef..7a3970ed 100644 --- a/tests/compute/lorentz/test_Mt2.py +++ b/tests/compute/lorentz/test_Mt2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_beta.py b/tests/compute/lorentz/test_beta.py index ca7f1a9a..04db7cbb 100644 --- a/tests/compute/lorentz/test_beta.py +++ b/tests/compute/lorentz/test_beta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_boostX_beta.py b/tests/compute/lorentz/test_boostX_beta.py index 2fe16944..328beea2 100644 --- a/tests/compute/lorentz/test_boostX_beta.py +++ b/tests/compute/lorentz/test_boostX_beta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boostX_gamma.py b/tests/compute/lorentz/test_boostX_gamma.py index 2f08b955..97cc3bbc 100644 --- a/tests/compute/lorentz/test_boostX_gamma.py +++ b/tests/compute/lorentz/test_boostX_gamma.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boostY_beta.py b/tests/compute/lorentz/test_boostY_beta.py index 6c242fc5..97f47702 100644 --- a/tests/compute/lorentz/test_boostY_beta.py +++ b/tests/compute/lorentz/test_boostY_beta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boostY_gamma.py b/tests/compute/lorentz/test_boostY_gamma.py index 87766fe6..9327d14c 100644 --- a/tests/compute/lorentz/test_boostY_gamma.py +++ b/tests/compute/lorentz/test_boostY_gamma.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boostZ_beta.py b/tests/compute/lorentz/test_boostZ_beta.py index cc6da9d5..f73d4c39 100644 --- a/tests/compute/lorentz/test_boostZ_beta.py +++ b/tests/compute/lorentz/test_boostZ_beta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boostZ_gamma.py b/tests/compute/lorentz/test_boostZ_gamma.py index 1f2ad4fe..dd60247e 100644 --- a/tests/compute/lorentz/test_boostZ_gamma.py +++ b/tests/compute/lorentz/test_boostZ_gamma.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boost_beta3.py b/tests/compute/lorentz/test_boost_beta3.py index 243bb3af..8278ae13 100644 --- a/tests/compute/lorentz/test_boost_beta3.py +++ b/tests/compute/lorentz/test_boost_beta3.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_boost_p4.py b/tests/compute/lorentz/test_boost_p4.py index 81063166..b5f34611 100644 --- a/tests/compute/lorentz/test_boost_p4.py +++ b/tests/compute/lorentz/test_boost_p4.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/lorentz/test_deltaRapidityPhi.py b/tests/compute/lorentz/test_deltaRapidityPhi.py index 19f658c8..63e64dba 100644 --- a/tests/compute/lorentz/test_deltaRapidityPhi.py +++ b/tests/compute/lorentz/test_deltaRapidityPhi.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/lorentz/test_deltaRapidityPhi2.py b/tests/compute/lorentz/test_deltaRapidityPhi2.py index dcb85863..c27ccf5b 100644 --- a/tests/compute/lorentz/test_deltaRapidityPhi2.py +++ b/tests/compute/lorentz/test_deltaRapidityPhi2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/lorentz/test_gamma.py b/tests/compute/lorentz/test_gamma.py index 65c7914a..443e7411 100644 --- a/tests/compute/lorentz/test_gamma.py +++ b/tests/compute/lorentz/test_gamma.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_rapidity.py b/tests/compute/lorentz/test_rapidity.py index 5c68dd0b..5d086f9a 100644 --- a/tests/compute/lorentz/test_rapidity.py +++ b/tests/compute/lorentz/test_rapidity.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_t.py b/tests/compute/lorentz/test_t.py index 66ad8c8c..e9197f48 100644 --- a/tests/compute/lorentz/test_t.py +++ b/tests/compute/lorentz/test_t.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_t2.py b/tests/compute/lorentz/test_t2.py index 97ddcb48..ca08a5a7 100644 --- a/tests/compute/lorentz/test_t2.py +++ b/tests/compute/lorentz/test_t2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_tau.py b/tests/compute/lorentz/test_tau.py index 0850dab8..7ef638be 100644 --- a/tests/compute/lorentz/test_tau.py +++ b/tests/compute/lorentz/test_tau.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_tau2.py b/tests/compute/lorentz/test_tau2.py index 947e1193..dc21e442 100644 --- a/tests/compute/lorentz/test_tau2.py +++ b/tests/compute/lorentz/test_tau2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/lorentz/test_to_beta3.py b/tests/compute/lorentz/test_to_beta3.py index 5a7493df..42cd0462 100644 --- a/tests/compute/lorentz/test_to_beta3.py +++ b/tests/compute/lorentz/test_to_beta3.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/planar/test_deltaphi.py b/tests/compute/planar/test_deltaphi.py index 21482659..6a78f6ef 100644 --- a/tests/compute/planar/test_deltaphi.py +++ b/tests/compute/planar/test_deltaphi.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/planar/test_phi.py b/tests/compute/planar/test_phi.py index 7a0e78d4..6ae5cbc0 100644 --- a/tests/compute/planar/test_phi.py +++ b/tests/compute/planar/test_phi.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/planar/test_rho.py b/tests/compute/planar/test_rho.py index e075d08a..352f547a 100644 --- a/tests/compute/planar/test_rho.py +++ b/tests/compute/planar/test_rho.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/planar/test_rho2.py b/tests/compute/planar/test_rho2.py index 52593ffc..731b4195 100644 --- a/tests/compute/planar/test_rho2.py +++ b/tests/compute/planar/test_rho2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/planar/test_rotateZ.py b/tests/compute/planar/test_rotateZ.py index 39b8ef1d..c13f1e74 100644 --- a/tests/compute/planar/test_rotateZ.py +++ b/tests/compute/planar/test_rotateZ.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/planar/test_x.py b/tests/compute/planar/test_x.py index a2bf16d2..7879d5ec 100644 --- a/tests/compute/planar/test_x.py +++ b/tests/compute/planar/test_x.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/planar/test_y.py b/tests/compute/planar/test_y.py index 819ce77f..5d570a64 100644 --- a/tests/compute/planar/test_y.py +++ b/tests/compute/planar/test_y.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/spatial/test_costheta.py b/tests/compute/spatial/test_costheta.py index 2476e5d6..8795f5c0 100644 --- a/tests/compute/spatial/test_costheta.py +++ b/tests/compute/spatial/test_costheta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/spatial/test_cottheta.py b/tests/compute/spatial/test_cottheta.py index 88cc45fb..fadb7fc1 100644 --- a/tests/compute/spatial/test_cottheta.py +++ b/tests/compute/spatial/test_cottheta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/spatial/test_cross.py b/tests/compute/spatial/test_cross.py index 413f7d1a..9cfd5551 100644 --- a/tests/compute/spatial/test_cross.py +++ b/tests/compute/spatial/test_cross.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_deltaR.py b/tests/compute/spatial/test_deltaR.py index b0a54d45..9e5a3d97 100644 --- a/tests/compute/spatial/test_deltaR.py +++ b/tests/compute/spatial/test_deltaR.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import numpy diff --git a/tests/compute/spatial/test_deltaR2.py b/tests/compute/spatial/test_deltaR2.py index c13fa61b..620c8188 100644 --- a/tests/compute/spatial/test_deltaR2.py +++ b/tests/compute/spatial/test_deltaR2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_deltaangle.py b/tests/compute/spatial/test_deltaangle.py index 655e250b..c068d206 100644 --- a/tests/compute/spatial/test_deltaangle.py +++ b/tests/compute/spatial/test_deltaangle.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_deltaeta.py b/tests/compute/spatial/test_deltaeta.py index e0f609ae..ab6158de 100644 --- a/tests/compute/spatial/test_deltaeta.py +++ b/tests/compute/spatial/test_deltaeta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_eta.py b/tests/compute/spatial/test_eta.py index 3994fc96..2bc367ee 100644 --- a/tests/compute/spatial/test_eta.py +++ b/tests/compute/spatial/test_eta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/spatial/test_mag.py b/tests/compute/spatial/test_mag.py index 0f4f8cb8..467c3208 100644 --- a/tests/compute/spatial/test_mag.py +++ b/tests/compute/spatial/test_mag.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import math import pytest diff --git a/tests/compute/spatial/test_mag2.py b/tests/compute/spatial/test_mag2.py index e1f45706..2b9de7f4 100644 --- a/tests/compute/spatial/test_mag2.py +++ b/tests/compute/spatial/test_mag2.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/spatial/test_rotateX.py b/tests/compute/spatial/test_rotateX.py index e192eac5..8af2230c 100644 --- a/tests/compute/spatial/test_rotateX.py +++ b/tests/compute/spatial/test_rotateX.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_rotateY.py b/tests/compute/spatial/test_rotateY.py index ec589a96..6392c52c 100644 --- a/tests/compute/spatial/test_rotateY.py +++ b/tests/compute/spatial/test_rotateY.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_rotate_axis.py b/tests/compute/spatial/test_rotate_axis.py index f4713246..83bad81b 100644 --- a/tests/compute/spatial/test_rotate_axis.py +++ b/tests/compute/spatial/test_rotate_axis.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/spatial/test_rotate_euler.py b/tests/compute/spatial/test_rotate_euler.py index ac85f1e9..02f9f529 100644 --- a/tests/compute/spatial/test_rotate_euler.py +++ b/tests/compute/spatial/test_rotate_euler.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/spatial/test_rotate_quaternion.py b/tests/compute/spatial/test_rotate_quaternion.py index 0acdee87..45204f69 100644 --- a/tests/compute/spatial/test_rotate_quaternion.py +++ b/tests/compute/spatial/test_rotate_quaternion.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/spatial/test_theta.py b/tests/compute/spatial/test_theta.py index 1913ad9b..b5574d57 100644 --- a/tests/compute/spatial/test_theta.py +++ b/tests/compute/spatial/test_theta.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/spatial/test_z.py b/tests/compute/spatial/test_z.py index 44bb2a92..06788491 100644 --- a/tests/compute/spatial/test_z.py +++ b/tests/compute/spatial/test_z.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.object diff --git a/tests/compute/test_add.py b/tests/compute/test_add.py index 79833712..3bcc8c3b 100644 --- a/tests/compute/test_add.py +++ b/tests/compute/test_add.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/test_conversions.py b/tests/compute/test_conversions.py index 5f7d414c..33d7accf 100644 --- a/tests/compute/test_conversions.py +++ b/tests/compute/test_conversions.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/test_dot.py b/tests/compute/test_dot.py index e6d729b8..5e08c673 100644 --- a/tests/compute/test_dot.py +++ b/tests/compute/test_dot.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/test_equal.py b/tests/compute/test_equal.py index 4cd888c0..9c0801db 100644 --- a/tests/compute/test_equal.py +++ b/tests/compute/test_equal.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import vector.backends.numpy diff --git a/tests/compute/test_isclose.py b/tests/compute/test_isclose.py index 00927503..3678cefe 100644 --- a/tests/compute/test_isclose.py +++ b/tests/compute/test_isclose.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import vector.backends.numpy diff --git a/tests/compute/test_not_equal.py b/tests/compute/test_not_equal.py index 911e1811..06f18d8f 100644 --- a/tests/compute/test_not_equal.py +++ b/tests/compute/test_not_equal.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import vector.backends.numpy diff --git a/tests/compute/test_scale.py b/tests/compute/test_scale.py index eeba4f7f..311c8a94 100644 --- a/tests/compute/test_scale.py +++ b/tests/compute/test_scale.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import pytest import vector.backends.numpy diff --git a/tests/compute/test_subtract.py b/tests/compute/test_subtract.py index f6be8bb6..96a33122 100644 --- a/tests/compute/test_subtract.py +++ b/tests/compute/test_subtract.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/compute/test_unit.py b/tests/compute/test_unit.py index 7fb90a3f..1a2da987 100644 --- a/tests/compute/test_unit.py +++ b/tests/compute/test_unit.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import numpy import pytest diff --git a/tests/conftest.py b/tests/conftest.py index a8a19b0d..81b8f5e1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import os import sys diff --git a/tests/test_compute_features.py b/tests/test_compute_features.py index d66b70a6..ea54f866 100644 --- a/tests/test_compute_features.py +++ b/tests/test_compute_features.py @@ -29,6 +29,8 @@ backends, and whether a (formally) simpler implementation is possible. """ +from __future__ import annotations + import collections import inspect import sys diff --git a/tests/test_issues.py b/tests/test_issues.py index 213e998c..33bf8963 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import os import pickle diff --git a/tests/test_methods.py b/tests/test_methods.py index 17a9dd16..60232aad 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -3,6 +3,8 @@ # Distributed under the 3-clause BSD license, see accompanying file LICENSE # or https://github.com/scikit-hep/vector for details. +from __future__ import annotations + import vector