Skip to content

DOC: fix sphinx errors due to np.emath references #21032

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 7 commits into from
Apr 20, 2022

Conversation

jon-deng
Copy link
Contributor

Docstrings for some ufuncs reference np.emath which raises a warning
when sphinx generates documentation. Replacing the reference with
np.lib.scimath should fix the error, I think.

Currently I'm trying to figure out why changes to numpy/core/code_generators/ufunc_docstrings.py aren't reflected in numpy docstrings so have opened a draft pull request.

This should help fix some of the warnings raised in #13114.

@mattip
Copy link
Member

mattip commented Feb 11, 2022

Changes in python and C documentation are only reflected in the sphinx build after rebuilding numpy: pip install .; cd docs; make html.

You can see the ci result here if you open the "build devdocs w/ref warnings" fold. Comparing this build to a random PR's run the number of warnings dropped from 190 to 184. 👍

There is still a mention of

:mod:`emath`

in the RST documentation, could you take a look at that too? I think it should become

``emath``

with no link. What do you think?

@jon-deng
Copy link
Contributor Author

Hi matt, thanks for the feedback.

I had a look at doc/source/reference/routines.emath.rst and I think changing to :mod:numpy.emath to just emath with no link would be good.

It seems that sphinx can't find the np.emath module but I'm not sure why. The documentation page for emath (https://numpy.org/doc/stable/reference/routines.emath.html) says that emath should be available after numpy is imported. Do you know if sphinx just searches for emath in the numpy package after importing it?

@mattip
Copy link
Member

mattip commented Feb 16, 2022

It seems that sphinx can't find the np.emath module

I am not sure which occurence this is referring to, but if you are using np.emath, I am pretty sure you need to change that to numpy.emath

@jon-deng
Copy link
Contributor Author

Okay, thanks. I added the small additional change to doc/source/reference/routines.emath.rst replacing :mod:numpy.emath to numpy.emath as a code block. Is there anything else I should change as part of this PR?

@mattip
Copy link
Member

mattip commented Feb 24, 2022

Doesn't numpy.emath works as a link? It seems strange to refer to this as a preferred alias but then to not be able to use it.

@rossbar
Copy link
Contributor

rossbar commented Feb 24, 2022

It seems strange to refer to this as a preferred alias but then to not be able to use it.

Agreed - I'm -1 on changing all the links from emath.* to lib.scimath.* even though it fixes the broken links, since the docs state that emath is the preferred module name. I think the right way to fix this would be to update the module name/alias to reflect the "desired" access name. Not quite sure how difficult that will be but it's likely to be more involved than a docs-only change.

There are a number of broken links to the numpy.emath module because
there are no generated documentation for numpy.emath, which is an alias
of numpy.lib.scimath. This fixes the broken links by generating
documentation for numpy.emath, that duplicates the documentation for
numpy.lib.scimath.
@jon-deng jon-deng force-pushed the fix-sphinx-doc-errors branch from 7faf89e to 1258280 Compare February 25, 2022 21:02
@jon-deng
Copy link
Contributor Author

jon-deng commented Feb 25, 2022

I agree it's a bit weird.

I think I figured out a better way to fix it that should keep the emath type links. We can add two module documentation files doc/source/reference/routines.lib.scimath.rst and doc/source/reference/routines.emath.rst so each one generates the same documentation but with an appropriate module reference. The documentation in routines.lib.scimath.rst is under the module lib.scimath while the documentation in routines.emath.rst is under the module emath. What do you think?

@jon-deng jon-deng force-pushed the fix-sphinx-doc-errors branch from 5de6897 to 1258280 Compare March 1, 2022 01:00
@jon-deng
Copy link
Contributor Author

jon-deng commented Mar 1, 2022

Do you have any ideas how to fix the ci/circleci errors? It says there's an error in the Sphinx parallel build but I can't think of why that would be.

@rossbar
Copy link
Contributor

rossbar commented Mar 1, 2022

Do you have any ideas how to fix the ci/circleci errors? It says there's an error in the Sphinx parallel build but I can't think of why that would be.

I think this was a problem with one of the dependencies which has been fixed, try rebasing on (or merging with) main.

@jon-deng
Copy link
Contributor Author

jon-deng commented Mar 4, 2022

I think I've fixed the issue. I ended up changing the routines.emath.rst file to reference the numpy.emath module whereas previously routines.emath.rst referenced the numpy.lib.scimath module. This fixes the missing links to function belonging to numpy.emath and allows using the preferred alias.

***********************************************************************

.. currentmodule:: numpy

.. note:: :mod:`numpy.emath` is a preferred alias for :mod:`numpy.lib.scimath`,
.. note:: :mod:`numpy.emath` is a preferred alias for ``numpy.lib.scimath``,
Copy link
Member

Choose a reason for hiding this comment

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

revert this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The link to :mod:`numpy.lib.scimath` is broken now because I changed the line at the bottom of this file from ..automodule numpy.lib.scimath to ..automodule numpy.emath. Because of that, Sphinx generates references to members of numpy.emath which fixes the links but links to numpy.lib.scimath are now missing.

I was thinking of potentially adding the numpy.lib.scimath documentation but it seems there are no documents for the numpy.lib.* modules in doc/source/reference? Because of that, I'm unsure if it should be documented/how to document it? What do you think?

I think there are a few other warnings (aside from emath related ones) also related to missing numpy.lib.* functions and modules.

@mattip
Copy link
Member

mattip commented Mar 5, 2022

Nice. If this is ready please remove the draft status

@jon-deng jon-deng marked this pull request as ready for review March 8, 2022 01:27
@InessaPawson
Copy link
Member

@mattip It's now ready for review.

@mattip mattip merged commit dc5aba5 into numpy:main Apr 20, 2022
@mattip
Copy link
Member

mattip commented Apr 20, 2022

Thanks @jon-deng

@jon-deng
Copy link
Contributor Author

No problem and thanks for merging.

@InessaPawson
Copy link
Member

Hi-five on merging your first pull request to NumPy, @jon-deng! We hope you stick around! Your choices aren’t limited to programming – you can review pull requests, help us stay on top of new and old issues, develop educational material, work on our website, add or improve graphic design, create marketing materials, translate website content, write grant proposals, and help with other fundraising initiatives. For more info, check out: https://numpy.org/contribute
Also, consider joining our mailing list. This is a great way to connect with other cool people in our community and be part of important conversations that affect the development of NumPy: https://mail.python.org/mailman/listinfo/numpy-discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants