From 95b998b83012ac238b98065ab5a1a9b2c683c74c Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Thu, 7 Nov 2024 15:04:06 -0600 Subject: [PATCH] chore: remove Python 3.8, ensure Python 3.13 is included (#1332) * chore: remove Python 3.8, ensure Python 3.13 is included * Clean up fsspec.py now that Python 3.8 was dropped * Fix support for numpy v1.x * Use Python 3.9 for ReadTheDocs * Fixed numpy v1 support (attempt 2) --------- Co-authored-by: Andres Rios Tascon --- .github/workflows/build-test.yml | 4 ++-- .readthedocs.yml | 2 +- README.md | 2 +- pyproject.toml | 3 +-- src/uproot/_util.py | 5 ++++- src/uproot/source/fsspec.py | 16 +--------------- src/uproot/writing/_cascadetree.py | 12 ++++++++++-- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 6a326e316..acb309172 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.9', '3.10', '3.11', '3.12', '3.13'] runs-on: ${{ matrix.platform }} timeout-minutes: 30 @@ -41,7 +41,7 @@ jobs: run: python -c "import sys; assert '.'.join(str(s) for s in sys.version_info[:2]) == '${{ matrix.python-version }}', f'{version} incorrect!'" - name: Install ROOT - if: matrix.python-version == 3.8 && runner.os != 'macOS' && runner.os != 'Windows' + if: matrix.python-version == 3.9 && runner.os != 'macOS' && runner.os != 'Windows' run: | conda env list mamba install root diff --git a/.readthedocs.yml b/.readthedocs.yml index 6302ad680..47815e016 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -6,7 +6,7 @@ sphinx: build: os: ubuntu-22.04 tools: - python: '3.8' + python: '3.9' python: install: diff --git a/README.md b/README.md index a4fa80511..efc43b192 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPI version](https://badge.fury.io/py/uproot.svg)](https://pypi.org/project/uproot) [![Conda-Forge](https://img.shields.io/conda/vn/conda-forge/uproot)](https://github.com/conda-forge/uproot-feedstock) -[![Python 3.8‒3.12](https://img.shields.io/badge/python-3.8%E2%80%923.12-blue)](https://www.python.org) +[![Python 3.9‒3.13](https://img.shields.io/badge/python-3.9%E2%80%923.13-blue)](https://www.python.org) [![BSD-3 Clause License](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Continuous integration tests](https://github.com/scikit-hep/uproot5/actions/workflows/build-test.yml/badge.svg)](https://github.com/scikit-hep/uproot5/actions) diff --git a/pyproject.toml b/pyproject.toml index a726543c1..87b25f8fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,6 @@ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -53,7 +52,7 @@ dynamic = [ license = "BSD-3-Clause" name = "uproot" readme = "README.md" -requires-python = ">=3.8" +requires-python = ">=3.9" [project.optional-dependencies] dev = [ diff --git a/src/uproot/_util.py b/src/uproot/_util.py index 96e9e8d21..23e707440 100644 --- a/src/uproot/_util.py +++ b/src/uproot/_util.py @@ -91,7 +91,10 @@ def ensure_numpy(array, types=(numpy.bool_, numpy.integer, numpy.floating)): else: try: out = numpy.asarray(array) - except (ValueError, numpy.VisibleDeprecationWarning) as err: + except ( + ValueError, + getattr(numpy, "exceptions", numpy).VisibleDeprecationWarning, + ) as err: raise TypeError("cannot be converted to a NumPy array") from err if not issubclass(out.dtype.type, types): raise TypeError(f"cannot be converted to a NumPy array of type {types}") diff --git a/src/uproot/source/fsspec.py b/src/uproot/source/fsspec.py index 6f47890ba..b11663b14 100644 --- a/src/uproot/source/fsspec.py +++ b/src/uproot/source/fsspec.py @@ -133,24 +133,10 @@ def chunks( self._num_requested_chunks += len(ranges) self._num_requested_bytes += sum(stop - start for start, stop in ranges) - try: - # not available in python 3.8 - to_thread = asyncio.to_thread - except AttributeError: - import contextvars - import functools - - async def to_thread(func, /, *args, **kwargs): - loop = asyncio.get_running_loop() - ctx = contextvars.copy_context() - func_call = functools.partial(ctx.run, func, *args, **kwargs) - return await loop.run_in_executor(None, func_call) - async def async_wrapper_thread(blocking_func, *args, **kwargs): if not callable(blocking_func): raise TypeError("blocking_func must be callable") - # TODO: when python 3.8 is dropped, use `asyncio.to_thread` instead (also remove the try/except block above) - return await to_thread(blocking_func, *args, **kwargs) + return await asyncio.to_thread(blocking_func, *args, **kwargs) def submit(request_ranges: list[tuple[int, int]]): paths = [self._file_path] * len(request_ranges) diff --git a/src/uproot/writing/_cascadetree.py b/src/uproot/writing/_cascadetree.py index 66569c2c1..abf06053c 100644 --- a/src/uproot/writing/_cascadetree.py +++ b/src/uproot/writing/_cascadetree.py @@ -548,12 +548,20 @@ def extend(self, file, sink, data): try: with warnings.catch_warnings(): warnings.simplefilter( - "error", category=numpy.VisibleDeprecationWarning + "error", + category=getattr( + numpy, "exceptions", numpy + ).VisibleDeprecationWarning, ) v = numpy.array(v) # noqa: PLW2901 (overwriting v) if v.dtype == numpy.dtype("O"): raise Exception - except (numpy.VisibleDeprecationWarning, Exception): + except ( + getattr( + numpy, "exceptions", numpy + ).VisibleDeprecationWarning, + Exception, + ): try: awkward = uproot.extras.awkward() except ModuleNotFoundError as err: