Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Drop support for awkward v1 #434

Merged
merged 25 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 17 additions & 66 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

env:
# The "FORCE_COLOR" variable, when set to 1,
# tells Nox to colorize itself.
FORCE_COLOR: "1"

jobs:
pre-commit:
runs-on: ubuntu-latest
Expand All @@ -28,44 +33,7 @@ jobs:
echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
pipx run nox -s pylint

check-light:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
name: Python ${{ matrix.python-version }} - Light
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Requirements check
run: python -m pip list

- name: Install package
run: python -m pip install -e .[test]

- name: Test light package
run: python -m pytest -ra --ignore tests/test_notebooks.py

- name: Install numpy v2
if: matrix.python-version != 3.8
run: python -m pip install "numpy>=2.0.0b1"

- name: Test light package with numpy v2.x
if: matrix.python-version != 3.8
run: python -m pytest -ra --ignore tests/test_notebooks.py

check-awkward-v1:
needs: [check-light]
check-lite:
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -76,7 +44,7 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
name: Python ${{ matrix.python-version }} - Awkward v1
name: Python ${{ matrix.python-version }} - Lite
steps:
- uses: actions/checkout@v4

Expand All @@ -87,21 +55,11 @@ jobs:
- name: Requirements check
run: python -m pip list

- name: Install package
run: python -m pip install -e .[dev]

- name: Install awkward v1 and numpy v1
run: python -m pip install -U "awkward<2" "numpy<2"

- name: Run doctests on Python 3.11 with awkward v1.x and numpy v1.x
if: matrix.python-version == '3.11'
run: python -m pytest -ra --doctest-plus src/vector/
- name: Test lite package
run: pipx run nox -s lite-${{ matrix.python-version.key || matrix.python-version }} --verbose

- name: Test package with awkward v1.x
run: python -m pytest -ra --cov=vector --ignore tests/test_notebooks.py .

check-awkward-v2:
needs: [check-light]
check-full:
needs: [check-lite]
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -112,7 +70,7 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
name: Python ${{ matrix.python-version }} - Awkward v2
name: Python ${{ matrix.python-version }} - Full
steps:
- uses: actions/checkout@v4

Expand All @@ -123,18 +81,12 @@ jobs:
- name: Requirements check
run: python -m pip list

- name: Install package
run: python -m pip install -e .[dev]

- name: Install awkward v2
run: python -m pip install -U awkward "numpy<2.1"

- name: Run doctests on Python 3.11 with awkward v2.x
- name: Run doctests on Python 3.11
if: matrix.python-version == 3.11
run: python -m pytest -ra --doctest-plus src/vector/
run: pipx run nox -s doctests-${{ matrix.python-version.key || matrix.python-version }} --verbose

- name: Test package with awkward v2.x
run: python -m pytest -ra --cov=vector --ignore tests/test_notebooks.py .
- name: Test package and generate coverage report
run: pipx run nox -s coverage-${{ matrix.python-version.key || matrix.python-version }} --verbose

- name: Upload coverage report
uses: codecov/codecov-action@v4.5.0
Expand All @@ -161,8 +113,7 @@ jobs:
run: python -m pytest -ra -m dis --ignore tests/test_notebooks.py

pass:
needs:
[pre-commit, check-light, check-awkward-v1, check-awkward-v2, discheck]
needs: [pre-commit, check-lite, check-full, discheck]
runs-on: ubuntu-latest
steps:
- run: echo "All jobs passed"
Expand Down
20 changes: 7 additions & 13 deletions .github/workflows/notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,25 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
# The "FORCE_COLOR" variable, when set to 1,
# tells Nox to colorize itself.
FORCE_COLOR: "1"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade .[dev]
python -m pip install numba uproot
python -m pip install jupyter papermill
python-version: "3.10"

- name: List installed Python packages
run: python -m pip list

- name: Test example notebooks
run: |
pytest tests/test_notebooks.py
run: pipx run nox -s notebooks
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This overview is based on the [documentation here](https://vector.readthedocs.io
```python
import vector
import numpy as np
import awkward as ak # at least version 1.2.0
import awkward as ak # at least v2.0.0 (vector v1.4.* supports awkward v1 and v2 both)
import numba as nb
```

Expand Down
10 changes: 10 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## Version 1.5

### Version 1.5.0

#### Breaking

- drop support for awkward v1 [#434][]

[#434]: https://github.com/scikit-hep/vector/pull/434

## Version 1.4

### Version 1.4.2
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"\n",
"import numbers\n",
"\n",
"import awkward as ak # at least version 1.2.0rc5\n",
"import awkward as ak # at least v2.0.0 (vector v1.4.* supports awkward v1 and v2 both)\n",
"import numba as nb\n",
"import numpy as np\n",
"import sympy\n",
Expand Down
17 changes: 9 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

nox.options.sessions = ["lint", "lite", "tests", "doctests"]

ALL_PYTHON = ["3.8", "3.9", "3.10", "3.11", "3.12"]

DIR = Path(__file__).parent.resolve()

Expand All @@ -17,22 +18,22 @@ def lint(session: nox.Session) -> None:
session.run("pre-commit", "run", "--all-files", *session.posargs)


@nox.session
@nox.session(reuse_venv=True)
def pylint(session: nox.Session) -> None:
"""Run pylint."""
session.install("pylint~=2.14.0")
session.install("-e", ".")
session.run("pylint", "src/vector/", *session.posargs)


@nox.session
@nox.session(reuse_venv=True, python=ALL_PYTHON)
def lite(session: nox.Session) -> None:
"""Run the linter."""
session.install("-e", ".[test]")
session.run("pytest", "--ignore", "tests/test_notebooks.py", *session.posargs)


@nox.session(reuse_venv=True)
@nox.session(reuse_venv=True, python=ALL_PYTHON)
def tests(session: nox.Session) -> None:
"""Run the unit and regular tests."""
session.install("-e", ".[awkward,numba,test,test-extras,sympy]")
Expand All @@ -44,14 +45,14 @@ def tests(session: nox.Session) -> None:
)


@nox.session(reuse_venv=True)
@nox.session(reuse_venv=True, python=ALL_PYTHON)
def coverage(session: nox.Session) -> None:
"""Run tests and compute coverage."""
session.posargs.append("--cov=vector")
tests(session)


@nox.session(reuse_venv=True)
@nox.session(reuse_venv=True, python=ALL_PYTHON)
def doctests(session: nox.Session) -> None:
"""Run the doctests."""
session.install("-e", ".[awkward,numba,test,test-extras,sympy]")
Expand All @@ -61,8 +62,8 @@ def doctests(session: nox.Session) -> None:
@nox.session(reuse_venv=True)
def notebooks(session: nox.Session) -> None:
"""Run the notebook tests"""
session.install("-e", ".[awkward,numba,test,test-extras]", "numba")
session.install("jupyter", "papermill")
session.install("-e", ".[awkward,numba,test,sympy]")
session.install("jupyter")
session.run("pytest", "tests/test_notebooks.py", *session.posargs)


Expand All @@ -81,7 +82,7 @@ def docs(session: nox.Session) -> None:
print("Unsupported argument to docs")


@nox.session
@nox.session(reuse_venv=True)
def build(session: nox.Session) -> None:
"""Build an SDist and wheel."""
session.install("build")
Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ dependencies = [
"packaging>=19",
]
optional-dependencies.awkward = [
"awkward>=1.2",
"awkward>=2",
]
optional-dependencies.dev = [
"awkward>=1.2",
"awkward>=2",
"dask-awkward",
"nox",
"numba>=0.57; python_version<'3.12'",
Expand All @@ -60,7 +60,7 @@ optional-dependencies.dev = [
"sympy",
]
optional-dependencies.docs = [
"awkward>=1.2",
"awkward>=2",
"ipykernel",
"myst-parser>0.13",
"nbsphinx",
Expand All @@ -76,16 +76,16 @@ optional-dependencies.sympy = [
"sympy",
]
optional-dependencies.test = [
"dask-awkward",
"nox",
"papermill>=2.4",
"pytest>=6",
"pytest-cov>=3",
"pytest-doctestplus",
]
optional-dependencies.test-extras = [
"dask_awkward",
"spark-parser",
"uncompyle6",
'uncompyle6; python_version == "3.8"',
]
urls."Bug Tracker" = "https://github.com/scikit-hep/vector/issues"
urls.Changelog = "https://vector.readthedocs.io/en/latest/changelog.html"
Expand Down
12 changes: 2 additions & 10 deletions src/vector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,13 @@

def _import_awkward() -> None:
awk_version = packaging.version.Version(importlib.metadata.version("awkward"))
if awk_version < packaging.version.Version("1.2.0rc5"):
if awk_version < packaging.version.Version("2.0.0"):
# the only context users will see this message is if they're trying to use vector.awk
# VectorAwkward is still set to None
msg = f"awkward {awk_version} is too old; please upgrade to 1.2.0 or later"
msg = f"awkward {awk_version} is too old; please upgrade to 2.0.0 or later"
raise ImportError(msg)


_is_awkward_v2: bool | None
try:
_is_awkward_v2 = packaging.version.Version(
importlib.metadata.version("awkward")
) >= packaging.version.Version("2.0.0rc1")
except importlib.metadata.PackageNotFoundError:
_is_awkward_v2 = None

try:
import awkward

Expand Down
30 changes: 5 additions & 25 deletions src/vector/backends/awkward.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,33 +1638,17 @@ class MomentumRecord4D(MomentumAwkward4D, ak.Record): # type: ignore[misc]

# implementation of behaviors in Numba ########################################

if vector._is_awkward_v2:

def _lookup_field(record_type: typing.Any, name: str) -> int:
return record_type.fields.index(name)

else:

def _lookup_field(record_type: typing.Any, name: str) -> int:
return record_type.recordlookup.index(name)
def _lookup_field(record_type: typing.Any, name: str) -> int:
return record_type.fields.index(name)


def _arraytype_of(awkwardtype: typing.Any, component: str) -> typing.Any:
import numba

if isinstance(
awkwardtype,
ak._connect.numba.layout.NumpyArrayType
if hasattr(ak._connect, "numba") # Awkward v2
else ak._connect._numba.layout.NumpyArrayType,
):
if isinstance(awkwardtype, ak._connect.numba.layout.NumpyArrayType):
return awkwardtype.arraytype
elif isinstance(
awkwardtype,
ak._connect.numba.layout.IndexedArrayType
if hasattr(ak._connect, "numba") # Awkward v2
else ak._connect._numba.layout.IndexedArrayType,
):
elif isinstance(awkwardtype, ak._connect.numba.layout.IndexedArrayType):
return _arraytype_of(awkwardtype.contenttype, component)
raise numba.TypingError(
f"vector components like {component!r} must be NumpyArrayType, not {awkwardtype}"
Expand Down Expand Up @@ -1947,11 +1931,7 @@ def _numba_lower(

vectorcls = sig.return_type.instance_class

fields = (
sig.args[0].arrayviewtype.type.fields
if vector._is_awkward_v2
else sig.args[0].arrayviewtype.type.recordlookup
)
fields = sig.args[0].arrayviewtype.type.fields

if issubclass(vectorcls, (VectorObject2D, VectorObject3D, VectorObject4D)):
if issubclass(sig.return_type.azimuthaltype.instance_class, AzimuthalXY):
Expand Down
Loading
Loading