From ad26255e46d562a79ce298333482ceac897250c7 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Fri, 6 Oct 2023 23:19:02 +0100 Subject: [PATCH 01/17] chore: bump Python version --- .pre-commit-config.yaml | 7 +++++++ pyproject.toml | 11 +++++------ src/uproot/extras.py | 7 +------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3f167b2e5..16347ae46 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,3 +27,10 @@ repos: hooks: - id: ruff args: ["--fix", "--show-fixes"] + + +- repo: https://github.com/asottile/pyupgrade + rev: v3.13.0 + hooks: + - id: pyupgrade + args: ["--py38-plus"] diff --git a/pyproject.toml b/pyproject.toml index b0da5b2c1..fd74028fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ name = "uproot" description = "ROOT I/O in pure Python and NumPy." readme = "README.md" license = "BSD-3-Clause" -requires-python = ">=3.7" +requires-python = ">=3.8" authors = [ { name = "Jim Pivarski", email = "pivarski@princeton.edu" }, ] @@ -25,11 +25,11 @@ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Information Analysis", "Topic :: Scientific/Engineering :: Mathematics", @@ -39,7 +39,6 @@ classifiers = [ ] dependencies = [ "awkward>=2.0.0", - "importlib-metadata;python_version<\"3.8\"", "numpy", "packaging", ] @@ -50,11 +49,11 @@ dynamic = [ [project.optional-dependencies] dev = [ "boost_histogram>=0.13", - "dask-awkward>=2023.9.0;python_version >= \"3.8\"", - "dask[array];python_version >= \"3.8\"", + "dask-awkward>=2023.9.0", + "dask[array]", "hist>=1.2", "pandas", - "awkward-pandas;python_version >= \"3.8\"", + "awkward-pandas", ] test = [ "lz4", diff --git a/src/uproot/extras.py b/src/uproot/extras.py index 10b6c0970..0e54c4ed0 100644 --- a/src/uproot/extras.py +++ b/src/uproot/extras.py @@ -10,16 +10,11 @@ import atexit +import importlib.metadata as importlib_metadata import os -import sys from uproot._util import parse_version -if sys.version_info < (3, 8): - import importlib_metadata -else: - import importlib.metadata as importlib_metadata - def awkward(): """ From 52c4edf9bf0022b2123f8f308fcd5189f5e59577 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 7 Oct 2023 01:49:14 -0500 Subject: [PATCH 02/17] remove python 3.7 from ci --- .github/workflows/build-test.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index f7fd78e76..fb8427f38 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,10 +16,7 @@ jobs: fail-fast: false matrix: platform: ["windows-latest", "macos-latest", "ubuntu-latest"] - python-version: ["3.7", "3.8", "3.9", "3.10"] - exclude: - - platform: "windows-latest" - python-version: "3.7" + python-version: ["3.8", "3.9", "3.10"] runs-on: "${{ matrix.platform }}" timeout-minutes: 30 @@ -73,7 +70,6 @@ jobs: runs-on: "${{ matrix.platform }}" timeout-minutes: 30 - steps: - uses: "actions/checkout@v4" From 0ee9e28901571a3846f36c3e27cc6f8160fec89e Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 7 Oct 2023 01:49:56 -0500 Subject: [PATCH 03/17] add python 3.11 to matrix build --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index fb8427f38..5995a0cef 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: platform: ["windows-latest", "macos-latest", "ubuntu-latest"] - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11"] runs-on: "${{ matrix.platform }}" timeout-minutes: 30 From 442ed9310b24bcc3ca757cb858f51ed7ec960355 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 7 Oct 2023 01:51:05 -0500 Subject: [PATCH 04/17] add python 3.12 --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 5995a0cef..83a86d9b6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: platform: ["windows-latest", "macos-latest", "ubuntu-latest"] - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: "${{ matrix.platform }}" timeout-minutes: 30 From e7e74c4c4d9758b12272f008a0aaaf85a62d1e4b Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 7 Oct 2023 01:53:52 -0500 Subject: [PATCH 05/17] remove python 3.12 --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 83a86d9b6..5995a0cef 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: platform: ["windows-latest", "macos-latest", "ubuntu-latest"] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + python-version: ["3.8", "3.9", "3.10", "3.11"] runs-on: "${{ matrix.platform }}" timeout-minutes: 30 From cba9d77253f7e4d124008cace66295372a1a5d43 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Sat, 7 Oct 2023 02:12:48 -0500 Subject: [PATCH 06/17] remove python 3.11 from matrix build (already in vanilla build) --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 5995a0cef..fb8427f38 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: platform: ["windows-latest", "macos-latest", "ubuntu-latest"] - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10"] runs-on: "${{ matrix.platform }}" timeout-minutes: 30 From 05cabdde12514cfb16358ec80983ac5a273e8763 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 08:51:38 +0100 Subject: [PATCH 07/17] fix: pull out `.data` from `NumpyArray` --- src/uproot/writing/_cascadetree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uproot/writing/_cascadetree.py b/src/uproot/writing/_cascadetree.py index e8e53cd59..231b68df7 100644 --- a/src/uproot/writing/_cascadetree.py +++ b/src/uproot/writing/_cascadetree.py @@ -780,7 +780,7 @@ def extend(self, file, sink, data): "how did this pass the type check?\n\n" + repr(content) ) - big_endian = numpy.asarray(content, dtype=datum["dtype"]) + big_endian = numpy.asarray(content.data, dtype=datum["dtype"]) shape = tuple(shape) + big_endian.shape[1:] if shape[1:] != datum["shape"]: From 06edcb71e943a64744e086004c1f6028f60e7f14 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 09:57:41 +0100 Subject: [PATCH 08/17] ci: test 3.12 --- .github/workflows/build-test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index fb8427f38..83b15fc65 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: platform: ["windows-latest", "macos-latest", "ubuntu-latest"] - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: "${{ matrix.platform }}" timeout-minutes: 30 @@ -82,4 +82,6 @@ jobs: - name: "Run pytest" run: | - python -m pytest -vv tests --reruns 3 --reruns-delay 30 --only-rerun requests.exceptions.HTTPError + python -m pytest -vv tests \ + --reruns 3 --reruns-delay 30 \ + --only-rerun requests.exceptions.HTTPError From b2aef4ae675a114d036cd26ea08c08fcf2446b52 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:10:28 +0100 Subject: [PATCH 09/17] fix: don't require aiohttp for 3.12 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index fd74028fb..88179aa9b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,7 +58,7 @@ dev = [ test = [ "lz4", "minio", - "aiohttp", + "aiohttp; python_version<\"3.12\"", "fsspec", "fsspec-xrootd", "pytest>=6", From 865b98366e248b3d0646c95acab7cd7d4fb9b8e8 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:11:49 +0100 Subject: [PATCH 10/17] ci: fix line breaks Windows PS1 does not like this. --- .github/workflows/build-test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 83b15fc65..83a86d9b6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -82,6 +82,4 @@ jobs: - name: "Run pytest" run: | - python -m pytest -vv tests \ - --reruns 3 --reruns-delay 30 \ - --only-rerun requests.exceptions.HTTPError + python -m pytest -vv tests --reruns 3 --reruns-delay 30 --only-rerun requests.exceptions.HTTPError From 7860d8d25b709be50d893cd3d7c3006679b970af Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:20:51 +0100 Subject: [PATCH 11/17] fix: deprecated `ast.Str` --- src/uproot/language/python.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/uproot/language/python.py b/src/uproot/language/python.py index 61ddcb751..23739322a 100644 --- a/src/uproot/language/python.py +++ b/src/uproot/language/python.py @@ -57,8 +57,12 @@ def _walk_ast_yield_symbols(node, keys, aliases, functions, getter): and isinstance(node.func, ast.Name) and node.func.id == getter ): - if len(node.args) == 1 and isinstance(node.args[0], ast.Str): - yield node.args[0].s + if ( + len(node.args) == 1 + and isinstance(node.args[0], ast.Constant) + and isinstance(node.args[0], str) + ): + yield node.args[0].value else: raise TypeError( f"expected a constant string as the only argument of {getter!r}; " @@ -104,7 +108,8 @@ def _ast_as_branch_expression(node, keys, aliases, functions, getter): and isinstance(node.func, ast.Name) and node.func.id == getter and len(node.args) == 1 - and isinstance(node.args[0], ast.Str) + and isinstance(node.args[0], ast.Constant) + and isinstance(node.args[0], str) ): return node From 04d71141c98bc26bb820c14aaec325462e22e28d Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:25:03 +0100 Subject: [PATCH 12/17] fix: deprecated parameters to HTTPConnection --- src/uproot/source/http.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/uproot/source/http.py b/src/uproot/source/http.py index 6278e0733..ecfd6d135 100644 --- a/src/uproot/source/http.py +++ b/src/uproot/source/http.py @@ -39,9 +39,7 @@ def make_connection(parsed_url, timeout): from http.client import HTTPConnection, HTTPSConnection if parsed_url.scheme == "https": - return HTTPSConnection( - parsed_url.hostname, parsed_url.port, None, None, timeout - ) + return HTTPSConnection(parsed_url.hostname, parsed_url.port, timeout=timeout) elif parsed_url.scheme == "http": return HTTPConnection(parsed_url.hostname, parsed_url.port, timeout) From ddaeb8871c089e101cb6f37e1584e856a93097d5 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:30:25 +0100 Subject: [PATCH 13/17] fix: check `node.value` --- src/uproot/language/python.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uproot/language/python.py b/src/uproot/language/python.py index 23739322a..8c0085ae6 100644 --- a/src/uproot/language/python.py +++ b/src/uproot/language/python.py @@ -60,7 +60,7 @@ def _walk_ast_yield_symbols(node, keys, aliases, functions, getter): if ( len(node.args) == 1 and isinstance(node.args[0], ast.Constant) - and isinstance(node.args[0], str) + and isinstance(node.args[0].value, str) ): yield node.args[0].value else: @@ -109,7 +109,7 @@ def _ast_as_branch_expression(node, keys, aliases, functions, getter): and node.func.id == getter and len(node.args) == 1 and isinstance(node.args[0], ast.Constant) - and isinstance(node.args[0], str) + and isinstance(node.args[0].value, str) ): return node From b42248dbd2cc56ebf8ac2cedf0941b91040b66b7 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:39:51 +0100 Subject: [PATCH 14/17] test: require aiohttp --- tests/test_0692_fsspec.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_0692_fsspec.py b/tests/test_0692_fsspec.py index e9c6adacf..eb6dd08c8 100644 --- a/tests/test_0692_fsspec.py +++ b/tests/test_0692_fsspec.py @@ -10,6 +10,8 @@ @pytest.mark.network def test_open_fsspec_http(): + pytest.importorskip("aiohttp") + with uproot.open( "https://github.com/scikit-hep/scikit-hep-testdata/raw/v0.4.33/src/skhep_testdata/data/uproot-issue121.root", http_handler=uproot.source.fsspec.FSSpecSource, From c8314c4fbc727bfa5389bd6d0ba202e829c7d34a Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:44:48 +0100 Subject: [PATCH 15/17] fix: `ask.Num` is deprecated --- src/uproot/interpretation/identify.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/uproot/interpretation/identify.py b/src/uproot/interpretation/identify.py index 13c50751d..edb7683ba 100644 --- a/src/uproot/interpretation/identify.py +++ b/src/uproot/interpretation/identify.py @@ -14,6 +14,7 @@ import ast +import numbers import re import numpy @@ -164,15 +165,15 @@ def _float16_double32_walk_ast(node, branch, source): and isinstance(node.ctx, ast.Load) and node.id.lower() == "pi" ): - out = ast.Num(3.141592653589793) # TMath::Pi() + out = ast.Constant(3.141592653589793) # TMath::Pi() elif ( isinstance(node, ast.Name) and isinstance(node.ctx, ast.Load) and node.id.lower() == "twopi" ): - out = ast.Num(6.283185307179586) # TMath::TwoPi() - elif isinstance(node, ast.Num): - out = ast.Num(float(node.n)) + out = ast.Constant(6.283185307179586) # TMath::TwoPi() + elif isinstance(node, ast.Constant) and isinstance(node.value, numbers.Number): + out = ast.Num(float(node.value)) elif isinstance(node, ast.BinOp) and isinstance( node.op, (ast.Add, ast.Sub, ast.Mult, ast.Div) ): @@ -201,7 +202,8 @@ def _float16_double32_walk_ast(node, branch, source): isinstance(node, ast.List) and isinstance(node.ctx, ast.Load) and len(node.elts) == 3 - and isinstance(node.elts[2], ast.Num) + and isinstance(node.elts[2], ast.Constant) + and isinstance(node.elts[2].value, numbers.Number) ): out = ast.List( [ From 129b29db302e58786e3dc9af2ddfc8793a9fd304 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Wed, 11 Oct 2023 10:51:36 +0100 Subject: [PATCH 16/17] fix: use `ast.Constant` in return --- src/uproot/interpretation/identify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uproot/interpretation/identify.py b/src/uproot/interpretation/identify.py index edb7683ba..1be3bdb79 100644 --- a/src/uproot/interpretation/identify.py +++ b/src/uproot/interpretation/identify.py @@ -173,7 +173,7 @@ def _float16_double32_walk_ast(node, branch, source): ): out = ast.Constant(6.283185307179586) # TMath::TwoPi() elif isinstance(node, ast.Constant) and isinstance(node.value, numbers.Number): - out = ast.Num(float(node.value)) + out = ast.Constant(float(node.value)) elif isinstance(node, ast.BinOp) and isinstance( node.op, (ast.Add, ast.Sub, ast.Mult, ast.Div) ): From b9d78e2b367c32fab9cb4da803faf5edae0037cd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 11 Oct 2023 13:18:13 +0000 Subject: [PATCH 17/17] style: pre-commit fixes --- src/uproot/_dask.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uproot/_dask.py b/src/uproot/_dask.py index 21009ee52..2a2a11f62 100644 --- a/src/uproot/_dask.py +++ b/src/uproot/_dask.py @@ -4,9 +4,9 @@ from collections.abc import Callable, Iterable, Mapping try: - from typing import TYPE_CHECKING + from typing import TYPE_CHECKING, Final - from typing_extensions import Any, Final, Protocol, TypeVar + from typing_extensions import Any, Protocol, TypeVar except ImportError: from typing import TYPE_CHECKING, Any, Final, Protocol, TypeVar