GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DOC: update to scipy-doctest 1.6.0 and fix tests by mattip · Pull Request #28023 · numpy/numpy

DOC: update to scipy-doctest 1.6.0 and fix tests #28023

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.

Sign up for GitHub

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

Merged
seberg merged 2 commits into numpy:main from mattip:doctest-1.6.0
Dec 18, 2024

Uh oh!

There was an error while loading. Please reload this page.

Merged

DOC: update to scipy-doctest 1.6.0 and fix tests #28023

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
5260965
DOC: update to scipy-doctest 1.6.1 and fix tests [skip azp][skip cirrus]
mattip Dec 17, 2024
84fa489
DOC: use unicode formatting in polynomial doctest [skip actions][skip…
mattip Dec 18, 2024
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

13 changes: 7 additions & 6 deletions 13 .github/workflows/linux.yml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,13 @@ jobs:
shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'
run: |
spin bench --quick
- name: Check docstests
shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'
run: |
pip install scipy-doctest==1.5.1 hypothesis==6.104.1 matplotlib scipy pytz pandas
spin check-docs -v
spin check-tutorials -v
# These are run on CircleCI
# - name: Check docstests
# shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'
# run: |
# pip install scipy-doctest==1.6.0 hypothesis==6.104.1 matplotlib scipy pytz pandas
# spin check-docs -v
# spin check-tutorials -v

sdist:
needs: [smoke_test]
Expand Down
72 changes: 31 additions & 41 deletions 72 numpy/_core/_add_newdocs.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2771,7 +2771,7 @@
>>> y.shape = (3, 6)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: total size of new array must be unchanged
ValueError: cannot reshape array of size 24 into shape (3,6)
>>> np.zeros((4,2))[::2].shape = (-1,)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Expand Down Expand Up @@ -2854,31 +2854,32 @@
Examples
--------
>>> import numpy as np
>>> y = np.reshape(np.arange(2*3*4), (2,3,4))
>>> y = np.reshape(np.arange(2 * 3 * 4, dtype=np.int32), (2, 3, 4))
>>> y
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
[20, 21, 22, 23]]], dtype=np.int32)
>>> y.strides
(48, 16, 4)
>>> y[1,1,1]
17
>>> offset=sum(y.strides * np.array((1,1,1)))
>>> offset/y.itemsize
17

>>> x = np.reshape(np.arange(5*6*7*8), (5,6,7,8)).transpose(2,3,1,0)
>>> y[1, 1, 1]
np.int32(17)
>>> offset = sum(y.strides * np.array((1, 1, 1)))
>>> offset // y.itemsize
np.int64(17)

>>> x = np.reshape(np.arange(5*6*7*8, dtype=np.int32), (5, 6, 7, 8))
>>> x = x.transpose(2, 3, 1, 0)
>>> x.strides
(32, 4, 224, 1344)
>>> i = np.array([3,5,2,2])
>>> i = np.array([3, 5, 2, 2], dtype=np.int32)
>>> offset = sum(i * x.strides)
>>> x[3,5,2,2]
813
>>> offset / x.itemsize
813
>>> x[3, 5, 2, 2]
np.int32(813)
>>> offset // x.itemsize
np.int64(813)

"""))

Expand Down Expand Up @@ -4964,8 +4965,8 @@
0
>>> np.multiply.identity
1
>>> np.power.identity
1
>>> print(np.power.identity)
None
>>> print(np.exp.identity)
None
"""))
Expand Down Expand Up @@ -5053,15 +5054,15 @@
--------
>>> import numpy as np
>>> np.add.ntypes
18
22
>>> np.multiply.ntypes
18
23
>>> np.power.ntypes
17
21
>>> np.exp.ntypes
7
10
>>> np.remainder.ntypes
14
16

"""))

Expand All @@ -5080,26 +5081,16 @@
--------
>>> import numpy as np
>>> np.add.types
['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l',
'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D',
'GG->G', 'OO->O']

>>> np.multiply.types
['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l',
'LL->L', 'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D',
'GG->G', 'OO->O']
['??->?', 'bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', ...
Comment thread

@mattip mattip Dec 17, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doctest does not like splitting lines, and I think a few examples is plenty. BTW, the docstring itself (on lines 5069-5074) is pretty unclear. I think the type signature mini-language is documented elsewhere, perhaps this docstring should point there?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seberg seberg Dec 17, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why long lines are an issue, but I agree that this can be short and this seems fine.
Not sure we have a good place to link to (maybe the ufunc registration), but the few who have a reason to look at it, know about it anyway, I think...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

>>> np.power.types
['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L',
'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'FF->F', 'DD->D', 'GG->G',
'OO->O']
['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', ...

>>> np.exp.types
['f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O']
['e->e', 'f->f', 'd->d', 'f->f', 'd->d', 'g->g', 'F->F', 'D->D', 'G->G', 'O->O']

>>> np.remainder.types
['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', 'LL->L',
'qq->q', 'QQ->Q', 'ff->f', 'dd->d', 'gg->g', 'OO->O']
['bb->b', 'BB->B', 'hh->h', 'HH->H', 'ii->i', 'II->I', 'll->l', ...

"""))

Expand Down Expand Up @@ -5953,7 +5944,7 @@
>>> import numpy as np
>>> dt = np.dtype([('name', np.str_, 16), ('grades', np.float64, (2,))])
>>> print(dt.fields)
{'grades': (dtype(('float64',(2,))), 16), 'name': (dtype('|S16'), 0)}
{'name': (dtype('|S16'), 0), 'grades': (dtype(('float64',(2,))), 16)}

"""))

Expand Down Expand Up @@ -6131,13 +6122,12 @@
>>> (arr + arr).dtype.metadata
mappingproxy({'key': 'value'})

But if the arrays have different dtype metadata, the metadata may be
dropped:
If the arrays have different dtype metadata, the first one wins:
Comment thread

@seberg seberg Dec 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B.: The previous example says "currently", so I think this is fine, but we shouldn't make promises around this.
(the only true safe thing to do, IMO is to never propagate unless the dtype has custom logic)

FWIW, this works for our numerical dtypes, one already can't expect it to work e.g. with strings.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mattip mattip Dec 18, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the current rules, but the test was failing so I fixed the test and the comment accordingly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

seberg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

>>> dt2 = np.dtype(float, metadata={"key2": "value2"})
>>> arr2 = np.array([3, 2, 1], dtype=dt2)
>>> (arr + arr2).dtype.metadata is None
True # The metadata field is cleared so None is returned
>>> print((arr + arr2).dtype.metadata)
{'key': 'value'}
"""))

add_newdoc('numpy._core.multiarray', 'dtype', ('name',
Expand Down
6 changes: 4 additions & 2 deletions 6 numpy/polynomial/_polybase.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,11 @@ def degree(self):

Create a polynomial object for ``1 + 7*x + 4*x**2``:

# set the print format to ascii for doctests
>>> np.polynomial.set_default_printstyle("ascii")
Comment thread Outdated

@mattip mattip Dec 17, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have used 'unicode' but I am not sure what windows CI does...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seberg seberg Dec 17, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one, I think it would be nice to keep the unicode, because users are more likely to see it then not, I believe.

I suspect numpy/conftest.py is read? Maybe we can do p.polynomial.set_default_printstyle("unicode") there to remove windows from the equation?
(I think different defaults is just about bad terminals, which might print oddly if the test fails, but shouldn't influence test results.)

But if this isn't trivial, we can also just do this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mattip mattip Dec 18, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to unicode and checked that it works on my windows 10 machine. I prefer to leave the np.polynomial.set_default_printstyle in the example so it is more obvious there is an alternative. MAybe @rossbar knows why windows defaults to ascii?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seberg seberg Dec 18, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, maybe @rossbar can follow up if he prefers a different approach, would be nice to get this in.

IIRC, some windows terminals (older powershell?) have poor unicode printing support (it may even have just been the font missing symbols).

The overview docs and the docs of set_default_printstyle itself mention it, so I think that setting it globally would be OK, but then those two places should make sure to reset it to whatever it (with a comment that docs use unicode).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
>>> poly = np.polynomial.Polynomial([1, 7, 4])
>>> print(poly)
1.0 + 7.0·x + 4.0·x²
1.0 + 7.0 x + 4.0 x**2
>>> poly.degree()
2

Expand All @@ -696,7 +698,7 @@ def degree(self):

>>> poly = np.polynomial.Polynomial([1, 7, 0])
>>> print(poly)
1.0 + 7.0·x + 0.0·x²
1.0 + 7.0 x + 0.0 x**2
>>> poly.degree()
2
>>> poly.trim().degree()
Expand Down
2 changes: 1 addition & 1 deletion 2 requirements/doc_requirements.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ towncrier
toml

# for doctests, also needs pytz which is in test_requirements
scipy-doctest==1.5.1
scipy-doctest==1.6.0
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.