diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index db29e8c5..69dd9ae9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,11 +17,7 @@ jobs: set -x set -e python -m pip install pyflakes pytest pytest-doctestplus hypothesis pytest-cov pytest-flakes packaging - if [[ ${{ matrix.python-version }} == "3.12-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 numpy - fi; + python -m pip install --pre --upgrade --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy - name: Run Tests run: | set -x diff --git a/ndindex/shapetools.py b/ndindex/shapetools.py index 7e035d0f..4ea2c94a 100644 --- a/ndindex/shapetools.py +++ b/ndindex/shapetools.py @@ -188,13 +188,13 @@ 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]) = }") - idx1 = Tuple(0, 0); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (0, 100) - idx1 = Tuple(0, 1); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (1, 100) - idx1 = Tuple(0, 2); idx2 = Tuple(0, 0); (a[idx1.raw], b[idx2.raw]) = (2, 100) - idx1 = Tuple(0, 0); idx2 = Tuple(1, 0); (a[idx1.raw], b[idx2.raw]) = (0, 110) - idx1 = Tuple(0, 1); idx2 = Tuple(1, 0); (a[idx1.raw], b[idx2.raw]) = (1, 110) - idx1 = Tuple(0, 2); idx2 = Tuple(1, 0); (a[idx1.raw], b[idx2.raw]) = (2, 110) + ... print(f"{idx1 = }; {idx2 = }; {(a[idx1.raw], b[idx2.raw]) = }") # doctest: +SKIP38 + 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)) + idx1 = Tuple(0, 0); idx2 = Tuple(1, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(0), np.int64(110)) + idx1 = Tuple(0, 1); idx2 = Tuple(1, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(1), np.int64(110)) + idx1 = Tuple(0, 2); idx2 = Tuple(1, 0); (a[idx1.raw], b[idx2.raw]) = (np.int64(2), np.int64(110)) >>> a + b array([[100, 101, 102], [110, 111, 112]]) diff --git a/ndindex/slice.py b/ndindex/slice.py index bda8e26d..c73aca43 100644 --- a/ndindex/slice.py +++ b/ndindex/slice.py @@ -79,7 +79,7 @@ def __hash__(self): # Slices are only hashable in Python 3.12+ try: return hash(self.raw) - except TypeError: + except TypeError: # pragma: no cover return hash(self.args) @property diff --git a/ndindex/tests/doctest.py b/ndindex/tests/doctest.py index c110c60e..6c06f0a1 100644 --- a/ndindex/tests/doctest.py +++ b/ndindex/tests/doctest.py @@ -22,7 +22,14 @@ import os from contextlib import contextmanager from doctest import (DocTestRunner, DocFileSuite, DocTestSuite, - NORMALIZE_WHITESPACE) + NORMALIZE_WHITESPACE, register_optionflag) + +SKIP38 = register_optionflag("SKIP38") +PY38 = sys.version_info[1] == 8 +if PY38: + SKIP_THIS_VERSION = SKIP38 +else: + SKIP_THIS_VERSION = 0 @contextmanager def patch_doctest(): @@ -34,11 +41,17 @@ def patch_doctest(): orig_run = DocTestRunner.run def run(self, test, **kwargs): + filtered_examples = [] + for example in test.examples: + if SKIP_THIS_VERSION not in example.options: + filtered_examples.append(example) + # Remove ``` example.want = example.want.replace('```\n', '') example.exc_msg = example.exc_msg and example.exc_msg.replace('```\n', '') + test.examples = filtered_examples return orig_run(self, test, **kwargs) try: diff --git a/ndindex/tuple.py b/ndindex/tuple.py index 61052ac3..b9438e5d 100644 --- a/ndindex/tuple.py +++ b/ndindex/tuple.py @@ -246,8 +246,8 @@ def reduce(self, shape=None, *, negative_int=False): Integer(1) >>> a[..., 1] array(1) - >>> a[1] - 1 + >>> a[1] # doctest: +SKIP38 + np.int64(1) See https://github.com/Quansight-Labs/ndindex/issues/22.