Skip to content

Commit bdb7edb

Browse files
authored
Merge pull request #163 from asmeurer/numpy-doctests
Fix some issues with NumPy 2.0
2 parents 47f9d89 + 898b656 commit bdb7edb

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

.github/workflows/docs-preview.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
artifact-path: 0/docs/_build/html/index.html
1515
circleci-jobs: Build Docs Preview
1616
job-title: Click here to see a preview of the documentation.
17+
api-token: ${{ secrets.CIRCLECI_TOKEN }}
1718
- name: Check the URL
1819
if: github.event.status != 'pending'
1920
run: |

.github/workflows/tests.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ jobs:
66
strategy:
77
matrix:
88
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12-dev']
9+
# https://numpy.org/neps/nep-0029-deprecation_policy.html
10+
numpy-version: ['1.22', 'latest', 'dev']
11+
exclude:
12+
- python-version: '3.12-dev'
13+
numpy-version: '1.22'
914
fail-fast: false
1015
steps:
1116
- uses: actions/checkout@v2
@@ -17,7 +22,13 @@ jobs:
1722
set -x
1823
set -e
1924
python -m pip install pyflakes pytest pytest-doctestplus hypothesis pytest-cov pytest-flakes packaging
20-
python -m pip install --pre --upgrade --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
25+
if [[ ${{ matrix.numpy-version }} == 'latest' ]]; then
26+
python -m pip install --pre --upgrade numpy
27+
elif [[ ${{ matrix.numpy-version }} == 'dev' ]]; then
28+
python -m pip install --pre --upgrade --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy
29+
else
30+
python -m pip install --upgrade numpy==${{ matrix.numpy-version }}.*
31+
fi
2132
- name: Run Tests
2233
run: |
2334
set -x

ndindex/array.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ class ArrayIndex(NDIndex):
2020

2121
def _typecheck(self, idx, shape=None, _copy=True):
2222
try:
23-
from numpy import ndarray, asarray, integer, bool_, empty, intp, VisibleDeprecationWarning
23+
from numpy import ndarray, asarray, integer, bool_, empty, intp
2424
except ImportError: # pragma: no cover
2525
raise ImportError("NumPy must be installed to create array indices")
26+
try:
27+
from numpy import VisibleDeprecationWarning
28+
except ImportError: # pragma: no cover
29+
from numpy.exceptions import VisibleDeprecationWarning
2630

2731
if self.dtype is None:
2832
raise TypeError("Do not instantiate the superclass ArrayIndex directly")

ndindex/shapetools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def iter_indices(*shapes, skip_axes=(), _debug=False):
188188
array([[100],
189189
[110]])
190190
>>> for idx1, idx2 in iter_indices((1, 3), (2, 1)):
191-
... print(f"{idx1 = }; {idx2 = }; {(a[idx1.raw], b[idx2.raw]) = }") # doctest: +SKIP38
191+
... print(f"{idx1 = }; {idx2 = }; {(a[idx1.raw], b[idx2.raw]) = }") # doctest: +SKIPNP1
192192
idx1 = Tuple(0, 0); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(0), np.int64(100))
193193
idx1 = Tuple(0, 1); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(1), np.int64(100))
194194
idx1 = Tuple(0, 2); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(2), np.int64(100))

ndindex/tests/doctest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
1717
"""
1818

19+
import numpy
20+
1921
import sys
2022
import unittest
2123
import glob
@@ -24,10 +26,10 @@
2426
from doctest import (DocTestRunner, DocFileSuite, DocTestSuite,
2527
NORMALIZE_WHITESPACE, register_optionflag)
2628

27-
SKIP38 = register_optionflag("SKIP38")
28-
PY38 = sys.version_info[1] == 8
29-
if PY38:
30-
SKIP_THIS_VERSION = SKIP38
29+
SKIPNP1 = register_optionflag("SKIPNP1")
30+
NP1 = numpy.__version__.startswith('1')
31+
if NP1:
32+
SKIP_THIS_VERSION = SKIPNP1
3133
else:
3234
SKIP_THIS_VERSION = 0
3335

ndindex/tests/test_shapetools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import numpy as np
2+
try:
3+
from numpy import AxisError as np_AxisError
4+
except ImportError: # pragma: no cover
5+
from numpy.exceptions import AxisError as np_AxisError
26

37
from hypothesis import assume, given, example
48
from hypothesis.strategies import (one_of, integers, tuples as
@@ -271,7 +275,7 @@ def test_iter_indices_errors():
271275
# Check that the message is the same one used by NumPy
272276
try:
273277
np.sum(np.arange(10), axis=2)
274-
except np.AxisError as e:
278+
except np_AxisError as e:
275279
np_msg = str(e)
276280
else:
277281
raise RuntimeError("np.sum() did not raise AxisError") # pragma: no cover

ndindex/tuple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def reduce(self, shape=None, *, negative_int=False):
246246
Integer(1)
247247
>>> a[..., 1]
248248
array(1)
249-
>>> a[1] # doctest: +SKIP38
249+
>>> a[1] # doctest: +SKIPNP1
250250
np.int64(1)
251251
252252
See https://github.com/Quansight-Labs/ndindex/issues/22.

0 commit comments

Comments
 (0)