From 6f688e954a711f6265bb4311f7b8923982a3af89 Mon Sep 17 00:00:00 2001 From: Ianna Osborne Date: Fri, 21 Jun 2024 16:26:06 +0200 Subject: [PATCH] fix: correct dtypes for numpy v2 (#3159) * fix: import numpy for tests * fix: use the platform integer type * fix: use type * fix: np.intp type * fix: only for numpy 2+ * fix: remove duplicate workflows and test windows with numpy v1.xx * fix: add coverage * fix: remove duplicate test --- .github/workflows/test.yml | 16 ++++------------ dev/generate-tests.py | 1 + requirements-test-numpy1.txt | 4 ++++ requirements-test-numpy2.txt | 5 ----- src/awkward/_reducers.py | 4 +++- 5 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 requirements-test-numpy1.txt delete mode 100644 requirements-test-numpy2.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5afa88ac90..46a61b4424 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,6 +53,10 @@ jobs: python-architecture: x86 runs-on: windows-latest dependencies-kind: full + - python-version: '3.9' + python-architecture: x86 + runs-on: windows-latest + dependencies-kind: numpy1 - python-version: '3.8' python-architecture: x64 runs-on: ubuntu-latest @@ -61,18 +65,6 @@ jobs: python-architecture: x64 runs-on: ubuntu-latest dependencies-kind: pypy - - python-version: '3.11' - python-architecture: x64 - runs-on: ubuntu-latest - dependencies-kind: numpy2 - - python-version: '3.11' - python-architecture: x64 - runs-on: macos-11 - dependencies-kind: numpy2 - - python-version: '3.11' - python-architecture: x64 - runs-on: windows-latest - dependencies-kind: numpy2 runs-on: ${{ matrix.runs-on }} diff --git a/dev/generate-tests.py b/dev/generate-tests.py index 4eb9fefc3d..12c65708ec 100644 --- a/dev/generate-tests.py +++ b/dev/generate-tests.py @@ -425,6 +425,7 @@ def genspectests(specdict): """ ) f.write("import pytest\nimport kernels\n\n") + f.write("import pytest\nimport numpy as np\nimport kernels\n\n") num = 1 if spec.tests == []: f.write( diff --git a/requirements-test-numpy1.txt b/requirements-test-numpy1.txt new file mode 100644 index 0000000000..d4fa830d19 --- /dev/null +++ b/requirements-test-numpy1.txt @@ -0,0 +1,4 @@ +numpy<2.0.0 +pytest>=6 +pytest-cov +pytest-xdist diff --git a/requirements-test-numpy2.txt b/requirements-test-numpy2.txt deleted file mode 100644 index 57f93af2cb..0000000000 --- a/requirements-test-numpy2.txt +++ /dev/null @@ -1,5 +0,0 @@ -fsspec>=2022.11.0;sys_platform != "win32" -numpy>=2.0.0b1 -pytest>=6 -pytest-cov -pytest-xdist diff --git a/src/awkward/_reducers.py b/src/awkward/_reducers.py index 4c0d52c756..bb8fc22675 100644 --- a/src/awkward/_reducers.py +++ b/src/awkward/_reducers.py @@ -62,7 +62,9 @@ def _dtype_for_kernel(cls, dtype: DTypeLike) -> DTypeLike: else: return dtype - _use32 = (ak._util.win or ak._util.bits32) and not ak._util.numpy2 + _use32 = ((ak._util.win or ak._util.bits32) and not ak._util.numpy2) or ( + ak._util.numpy2 and np.intp is np.int32 + ) @classmethod def _promote_integer_rank(cls, given_dtype: DTypeLike) -> DTypeLike: