Skip to content

DOC: add Numpy import to examples #17115

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

Merged
merged 15 commits into from
Oct 11, 2022
Merged

Conversation

BassCoder2808
Copy link
Contributor

Reference issue
#16759

What does this implement/fix?
Added import numpy as np to docstring examples in every file as per the script https://gist.github.com/WarrenWeckesser/f81e1d6453a639c745da50746d7078fb

Additional information

Copy link
Member

@melissawm melissawm left a comment

Choose a reason for hiding this comment

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

These all look fine to me. I haven't looked into the files to see if there are any other examples that need the import line, but I did verify that all of those listed here actually use numpy for the example.

Comment on lines +75 to 77
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from numpy.fft import fft, ifft, fftshift, fftfreq
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: maybe we want to keep np.fft here instead of importing again? Not sure if that would be too verbose for the code, though.

Comment on lines 341 to 343
>>> import numpy as np
>>> from scipy import signal
>>> from numpy.random import default_rng
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above: might as well have one import?

Comment on lines 3517 to 3519
>>> import numpy as np
>>> from scipy import signal
>>> from numpy.random import default_rng
Copy link
Member

Choose a reason for hiding this comment

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

Again, might be simplified.

@tupui tupui added scipy.signal Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org labels Sep 29, 2022
@tupui tupui added this to the 1.10.0 milestone Sep 29, 2022
@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Sep 30, 2022

In cases where the example has code like this

    >>> from numpy.random import default_rng
    [...]
    >>> rng = default_rng()

I agree with @melissawm's suggestion to adjust to code to have just one numpy import. The code would become

    >>> import numpy as np
    [...]
    >>> rng = np.random.default_rng()

This is consistent with most other uses of default_rng throughout the SciPy examples.

The one other case like this involves scipy.signal.max_len_seq, which has the import

    from numpy.fft import fft, ifft, fftshift, fftfreq

I think we can leave that as is in this pull request. In a separate pull request, we could change that to import from scipy.fft instead of numpy.fft.

Copy link
Member

@WarrenWeckesser WarrenWeckesser left a comment

Choose a reason for hiding this comment

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

I think you missed a few fixes in the last update. I have some changes requested, otherwise this looks good. There are a few places where the import of numpy is not at the beginning, but that is still a topic of discussion, so not a problem.

@BassCoder2808 BassCoder2808 requested review from WarrenWeckesser and removed request for person142 October 7, 2022 17:26
Copy link
Member

@WarrenWeckesser WarrenWeckesser left a comment

Choose a reason for hiding this comment

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

There is one change needed. I'll push that, let the tests run again, and merge if that goes well.

@WarrenWeckesser WarrenWeckesser dismissed their stale review October 11, 2022 20:40

Requested changes have been made.

@WarrenWeckesser
Copy link
Member

The 3.11-dev job installs numpy from the main development branch. The failures are the result of numpy/numpy#22385, and not related to this pull request.

@WarrenWeckesser WarrenWeckesser merged commit 744c75f into scipy:main Oct 11, 2022
@WarrenWeckesser
Copy link
Member

Merged. Thanks @BassCoder2808!

ev-br pushed a commit to ev-br/scipy that referenced this pull request Oct 14, 2022
As decided in scipygh-13049, add 'import numpy as np' to the examples where needed.
This change updates most of the functions and classes listed in scipygh-16759.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.signal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants