DOC: Add >>> import numpy as np stubs everywhere#26814
Conversation
|
Thanks @agriyakhetarpal. Note that the doc build CI is failing. Apologies in advance: I suggested splitting this off from your previous PR, but won't have time to actually review in detail over the next days. Request to potential reviewers: this PR has the potential for a lot of bikeshedding. In case you are feeling an inclination to actually start such a process, I strongly recommend to think twice before doing that, and read the linked threads under "additional context" first. |
[skip azp] [skip cirrus]
2ae139c to
347207f
Compare
[skip azp] [skip cirrus]
de82e9e to
811830b
Compare
|
Not sure if I understand the "Diverging branches can't be fast-forwarded" error in CircleCI with the 128 exit code. My branch and my commits seem fine, so it's most likely a downtime incident with GitHub. |
|
There was an incident for GitHub repo clones on Friday, which seems to have been resolved today, but there's a different error in CircleCI from |
[skip azp] [skip cirrus]
[skip azp] [skip cirrus]
[skip azp] [skip cirrus]
|
The docs build has been fixed in |
| @@ -191,29 +191,31 @@ Inexact types | |||
| This means that variables with equal binary values but whose datatypes are of | |||
| different precisions may display differently:: | |||
There was a problem hiding this comment.
Although maybe it's just the use of :: here that's problematic.
There was a problem hiding this comment.
Yes, I noticed this issue while working on #26745 in many places. Would it be better to handle such changes here? It would reduce the diff there, but I think there's no way to test the rendering of the examples out without having integrated jupyterlite-sphinx, so we might as well test it there better at the expense of a larger diff.
There was a problem hiding this comment.
If the plan is to merge this PR and then that one, I'd prefer to not knowingly make some examples not render very nicely. Just in case they get missed or that PR takes a long time to land for whatever reason. I don't mind making the diff a bit longer to sort out that, I think for this specific example all that's needed is to delete the :: and it will automatically get the nice example markup you changed the docs to use elsewhere in this PR.
There was a problem hiding this comment.
I really like the new example blocks that show up if you adjust the indentation for long examples! I think there's just one where it's not rendering correctly, see inline comment.
Overall I really like this change and distributed over the entire community I think this will save a lot of human time where currently people need to add the import after copy/pasting code from the docs and seeing an error.
[skip azp] [skip cirrus]
I restored this change to the original in 25f9a99. It's not neat, but adding the |
|
There is a merge conflict, I guess that is to be expected in a PR this big. Perhaps we could push this over the finish line, and fix any lingering indentation problems in follow-on PRs? |
|
Thanks, @mattip – I resolved the merge conflicts, and this is ready for review again. I, too, suggest fixing indentation problems in follow-on PRs. |
|
Thanks @agriyakhetarpal |
|
I wonder if there is a regex we could use on the rendered documentation to find indentation problems? Looking at the random example with extra indentation it seems the problem is that a |
|
This is a good idea, I can look into doing this. With this PR merged, I'll resume my work on gh-26745 and fix any cases of improper indentation. |

Description
This PR is a precursor to gh-26745. It adds the
>>> import numpy as npstatement in the docstrings and documentation-based examples everywhere wherever applicable to enable the use of the NumPy API under thenpnamespace. This aims to make examples self-contained, which will be helpful towards being able to run them in isolated mini-notebooks using Pyodide as created by theTryExamplesdirective via thejupyterlite-sphinxextension for Sphinx.Changes made
>>> import numpy as npstatements in most files (certain files like_npyio_impl.pyhave been left out, please let me know if that file should be modified – it won't run well in Pyodide because of the lack of a filesystem to access, but the examples can be made self-contained in general and outside of Pyodide)Additional context
jupyterlite-sphinx#26745 (review)