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: | diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 69dd9ae9..0c683fc7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,6 +6,11 @@ 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'] + exclude: + - python-version: '3.12-dev' + numpy-version: '1.22' fail-fast: false steps: - uses: actions/checkout@v2 @@ -17,7 +22,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==${{ matrix.numpy-version }}.* + fi - name: Run Tests run: | set -x 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") 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/tests/test_shapetools.py b/ndindex/tests/test_shapetools.py index 9575eb04..17531deb 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: # pragma: no cover + 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 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.