Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doctests with dev numpy #162

Merged
merged 4 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions ndindex/shapetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand Down
2 changes: 1 addition & 1 deletion ndindex/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion ndindex/tests/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions ndindex/tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading