From 92ff4ab7c010f29d27e83fbdd23aa7e49b1cf239 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 01:28:05 -0600 Subject: [PATCH 1/8] Skip doctests that require NumPy 2.0 in NumPy 1 --- ndindex/shapetools.py | 2 +- ndindex/tests/doctest.py | 10 ++++++---- ndindex/tuple.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ndindex/shapetools.py b/ndindex/shapetools.py index 4ea2c94a..e3c5854b 100644 --- a/ndindex/shapetools.py +++ b/ndindex/shapetools.py @@ -188,7 +188,7 @@ def iter_indices(*shapes, skip_axes=(), _debug=False): array([[100], [110]]) >>> for idx1, idx2 in iter_indices((1, 3), (2, 1)): - ... print(f"{idx1 = }; {idx2 = }; {(a[idx1.raw], b[idx2.raw]) = }") # doctest: +SKIP38 + ... print(f"{idx1 = }; {idx2 = }; {(a[idx1.raw], b[idx2.raw]) = }") # doctest: +SKIPNP1 idx1 = Tuple(0, 0); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(0), np.int64(100)) idx1 = Tuple(0, 1); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(1), np.int64(100)) idx1 = Tuple(0, 2); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(2), np.int64(100)) diff --git a/ndindex/tests/doctest.py b/ndindex/tests/doctest.py index 6c06f0a1..55a0a02e 100644 --- a/ndindex/tests/doctest.py +++ b/ndindex/tests/doctest.py @@ -16,6 +16,8 @@ """ +import numpy + import sys import unittest import glob @@ -24,10 +26,10 @@ from doctest import (DocTestRunner, DocFileSuite, DocTestSuite, NORMALIZE_WHITESPACE, register_optionflag) -SKIP38 = register_optionflag("SKIP38") -PY38 = sys.version_info[1] == 8 -if PY38: - SKIP_THIS_VERSION = SKIP38 +SKIPNP1 = register_optionflag("SKIPNP1") +NP1 = numpy.__version__.startswith('1') +if NP1: + SKIP_THIS_VERSION = SKIPNP1 else: SKIP_THIS_VERSION = 0 diff --git a/ndindex/tuple.py b/ndindex/tuple.py index b9438e5d..30aa9646 100644 --- a/ndindex/tuple.py +++ b/ndindex/tuple.py @@ -246,7 +246,7 @@ def reduce(self, shape=None, *, negative_int=False): Integer(1) >>> a[..., 1] array(1) - >>> a[1] # doctest: +SKIP38 + >>> a[1] # doctest: +SKIPNP1 np.int64(1) See https://github.com/Quansight-Labs/ndindex/issues/22. From d6ad910980b1fcab8582f43068bf1c09e39a7c6d Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 13:22:08 -0600 Subject: [PATCH 2/8] Fix an import in NumPy 2.0 --- ndindex/array.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ndindex/array.py b/ndindex/array.py index 179b7433..4eafd990 100644 --- a/ndindex/array.py +++ b/ndindex/array.py @@ -20,9 +20,13 @@ class ArrayIndex(NDIndex): def _typecheck(self, idx, shape=None, _copy=True): try: - from numpy import ndarray, asarray, integer, bool_, empty, intp, VisibleDeprecationWarning + from numpy import ndarray, asarray, integer, bool_, empty, intp except ImportError: # pragma: no cover raise ImportError("NumPy must be installed to create array indices") + try: + from numpy import VisibleDeprecationWarning + except ImportError: # pragma: no cover + from numpy.exceptions import VisibleDeprecationWarning if self.dtype is None: raise TypeError("Do not instantiate the superclass ArrayIndex directly") From a9a3c77c8c22029fd17acea7983fd64b9e4071e1 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 13:23:45 -0600 Subject: [PATCH 3/8] Test against different numpy versions on CI --- .github/workflows/tests.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 69dd9ae9..0e10c3d3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,6 +6,8 @@ jobs: strategy: matrix: python-version: ['3.8', '3.9', '3.10', '3.11', '3.12-dev'] + # https://numpy.org/neps/nep-0029-deprecation_policy.html + numpy-version: ['1.22', 'latest', 'dev'] fail-fast: false steps: - uses: actions/checkout@v2 @@ -17,7 +19,13 @@ jobs: set -x set -e python -m pip install pyflakes pytest pytest-doctestplus hypothesis pytest-cov pytest-flakes packaging - python -m pip install --pre --upgrade --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy + if [[ ${{ matrix.numpy-version }} == 'latest' ]]; then + python -m pip install --pre --upgrade numpy + elif [[ ${{ matrix.numpy-version }} == 'dev' ]]; then + python -m pip install --pre --upgrade --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy + else + python -m pip install --upgrade numpy==$NUMPY_VERSION + fi - name: Run Tests run: | set -x From 56e9053c2712358082ab00eeb9d9725a559fa381 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 22:58:09 -0600 Subject: [PATCH 4/8] Fix NumPy 1.22 install on CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0e10c3d3..02736160 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,7 +24,7 @@ jobs: elif [[ ${{ matrix.numpy-version }} == 'dev' ]]; then python -m pip install --pre --upgrade --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy else - python -m pip install --upgrade numpy==$NUMPY_VERSION + python -m pip install --upgrade numpy==${{ matrix.numpy-version }}.* fi - name: Run Tests run: | From 5ba6a135d43eab57ff660f9906d3a07bf5480922 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 23:00:28 -0600 Subject: [PATCH 5/8] Fix a test failure with numpy 2.0 --- ndindex/tests/test_shapetools.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ndindex/tests/test_shapetools.py b/ndindex/tests/test_shapetools.py index 9575eb04..6eea536b 100644 --- a/ndindex/tests/test_shapetools.py +++ b/ndindex/tests/test_shapetools.py @@ -1,4 +1,8 @@ import numpy as np +try: + from numpy import AxisError as np_AxisError +except ImportError: + from numpy.exceptions import AxisError as np_AxisError from hypothesis import assume, given, example from hypothesis.strategies import (one_of, integers, tuples as @@ -271,7 +275,7 @@ def test_iter_indices_errors(): # Check that the message is the same one used by NumPy try: np.sum(np.arange(10), axis=2) - except np.AxisError as e: + except np_AxisError as e: np_msg = str(e) else: raise RuntimeError("np.sum() did not raise AxisError") # pragma: no cover From 6a4a4fbcaa4c5d70d009833da3f1d727c84ebcaa Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 23:06:39 -0600 Subject: [PATCH 6/8] Fix the CircleCI docs preview --- .github/workflows/docs-preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docs-preview.yml b/.github/workflows/docs-preview.yml index fce6fc2a..70b1f2e4 100644 --- a/.github/workflows/docs-preview.yml +++ b/.github/workflows/docs-preview.yml @@ -14,6 +14,7 @@ jobs: artifact-path: 0/docs/_build/html/index.html circleci-jobs: Build Docs Preview job-title: Click here to see a preview of the documentation. + api-token: ${{ secrets.CIRCLECI_TOKEN }} - name: Check the URL if: github.event.status != 'pending' run: | From 5ca685a7988cfdd0daed402001625686d4df841e Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 4 Oct 2023 23:08:38 -0600 Subject: [PATCH 7/8] Don't install numpy 1.12 on Python 3.12 --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 02736160..0c683fc7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,6 +8,9 @@ jobs: python-version: ['3.8', '3.9', '3.10', '3.11', '3.12-dev'] # https://numpy.org/neps/nep-0029-deprecation_policy.html numpy-version: ['1.22', 'latest', 'dev'] + exclude: + - python-version: '3.12-dev' + numpy-version: '1.22' fail-fast: false steps: - uses: actions/checkout@v2 From 898b6568e3c59eb2f8bd2fbce8d6f79071c6687d Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Thu, 5 Oct 2023 00:21:59 -0600 Subject: [PATCH 8/8] Fix coverage --- ndindex/tests/test_shapetools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndindex/tests/test_shapetools.py b/ndindex/tests/test_shapetools.py index 6eea536b..17531deb 100644 --- a/ndindex/tests/test_shapetools.py +++ b/ndindex/tests/test_shapetools.py @@ -1,7 +1,7 @@ import numpy as np try: from numpy import AxisError as np_AxisError -except ImportError: +except ImportError: # pragma: no cover from numpy.exceptions import AxisError as np_AxisError from hypothesis import assume, given, example