-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DOC: Remove the tables of scalar types, and use ..autoclass
to create link targets instead
#17331
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
Conversation
f1e0a77
to
ff46e36
Compare
|
There also seems to be a bug that turns |
=================== ============================= =============== | ||
.. inheritance-diagram:: byte short intc int_ longlong ubyte ushort uintc uint ulonglong half single double longdouble csingle cdouble clongdouble bool_ datetime64 timedelta64 object_ bytes_ str_ void | ||
|
||
Signed integer types |
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.
Rather than ..autoclass:: numpy.byte
, try
.. autosummary::
:toctree: generated
:nosignatures:
numpy.byte
numpy.short
...
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.
That would probably work, but I don't really want a page per class, because then we lose the ability to see the character codes and aliases all in one place.
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.
Then I think you need to create a template to override the default one in doc/source/_templates/autosummary/class.rst
and use a :template:
option on the autosummary. I don't know if :template:
works with autoclass
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.
Autosummary shouldn't be relevant here - it's built on top of autodoc, not vice versa. I think numpydoc is injecting an autosummary into the autodoc docstring or something.
This prevents all the members from being listed (Maybe this behavior is undocumented, but already used in numpy document.) |
Thanks @takanori-pskq, I'll try that |
Wonderful, that did the trick! |
+1 on this PR. Here are suggestions; apologies if any are known issues.
|
Thanks for the feedback. Commenting on these one-by-one:
The full stop seems to be suggested by PEP 257
Agreed - that's there for users typing
That's true of all C functions, and probably something that should be fixed in numpydoc or sphinx
I'd like to keep the word alias there somehow
That would probably make sense, perhaps at the top of the page, or in a separate section about sized aliases
Yes, because on linux they have no aliases.
This is true of all autoclass directives. It might be possible to hide the
Yes, I don't know how we want to handle that.
I didn't think I changed this section
Personally I think neither is what we want. The second one has some major drawbacks:
Regarding 1, 4, 7, and 10: These docstrings are already present when you use |
Right, that's deliberate too. The idea behind the canonical name is that in normal use, Really, the "canonical name" entry should not be present on any of the scalar sphinx docs (as you remark in 2). This would be the case already, were it not for the fact that my hack executes after the docstrings have been computed. |
93f5136
to
475295f
Compare
I've pushed |
"8." is now fixed too |
Wow, you got stuff under control quickly. Thanks, it's looking good. Regarding the 2nd figure (item 11 above):
Did you plan to replace both figures with a better figure? Otherwise, it's perplexing to see both. I like the second, but you're right, it isn't very compact.
The way PEP 257 applies the rule makes sense: There's a summary description that includes a verb, the question of punctuation comes up naturally, and a rule is useful. It seems improbable they want a full stop after every field of any content or length. Is that how you read it? Or am I looking at the wrong section? Since the |
That was the main reason I added it
No, probably not. Perhaps I'll comment out the new inheritance diagram, and leave merging them for someone else to take on in future.
Oh, I thought by "entry" you meant "docstring". Sure, we could remove the
I have no idea. |
That's great! The wish list:
|
Comments addressed, I think |
7ffb338
to
d8cc5fa
Compare
Thank you, @eric-wieser, the changes look great. There's a sentence possibly outside the scope of this PR, but perhaps you can comment. Can the indecisive
instead read
|
Yeah, I'd like to declare that out of scope, along with the scalar types that have no docstring at all. |
Sure, no need to change it here. Were you planning to open issues for the scalar types that are missing docstrings? |
I borrowed Guido's time machine to file #10106 |
🔮
Nice.
|
docs build is still not happy, there must be a stray
Maybe the error already exists and this PR exposes it somehow? |
It's also possible the build is segfaulting due to the hacks in |
Ah, the failure is real. What's happening is:
How do we want to deal with the scalar renaming hack? We could add a |
349f340
to
b142a75
Compare
Build passes. If everything looks good, I can rewrite history to squash to a nasty hack commit and a doc cleanup commit. |
Where and why do we do this? |
('tp_name', ctypes.c_char_p), | ||
] | ||
|
||
# prevent numpy attaching docstrings to the scalar types |
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.
Ahh, this is what @eric-wieser meant about docstings.
The new page looks great. If it is not too much trouble to clean up git history that would be nice. |
Previously, these would all link to `numpy/core/__init__.py`. Now the scalar type and `ndarray` link to the files where the `PyTypeObject` is defined. In future, we should do this for all extension types, probably automatically.
… builds By default, the `.__name__` of the numeric `np.generic` subclasses is their bitlength name, such as `np.int64`. This is convenient when working interactively, because it lets users see the size of their array easily; but in docs it is confusing, as the sizes of the integers in the doc build may not match their size on the platform of the user reading them. Without this change, `..autoclass:: numpy.short` would just display "alias of uint16", which is backwards. Rather than changing the names globally, or adding a build flag to change the names, this uses `ctypes` to modify the scalar names at startup. This resembles the approach taken by the `forbiddenfruit` module for patching builtin slots, although that would be overkill here. The timing of when we perform this patching is important - we can't do it until after `numpy.core._umath_multiarray` has been loaded, but we need to do it before `numpy.core._add_newdocs` generates the name-based docstrings. Similarly, we can't just disable `numpy.core._add_newdocs` until later, as it populates docstrings in `ndarray` on which `numpy.ma.core` does further processing. To resolve this, we split out the scalar docstrings in `numpy.core._add_newdocs` into a new module `numpy.core._add_newdocs_scalars` that _is_ safe to disable until later.
This remove the tables. since they only had three columns, and using the character code is advised against anyway. With this change, the individual scalar types as well as their aliases are now valid sphinx python domain targets.
b142a75
to
3edc19f
Compare
Rebased, with an extensive commit message on the hack |
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.
Thanks @eric-wieser for the detailed commit messages, they really helped me to better understand what's going on.
It's a little unfortunate that so much metaprogramming is required to get resolvable links for the scalar types, but with my limited knowledge of sphinx I can't think of a way around it. The resulting scalars refguide page looks really good and this change reduces the number of link warnings from 623 (on e6b8b19) down to 484.
Thanks @eric-wieser |
Wonderful, thanks for counting that. |
The page in question after this PR: https://16096-908607-gh.circle-artifacts.com/0/doc/build/html/reference/arrays.scalars.html
What's changed:
class
documentation blocksconf.py
that adjustsPyTypeObject.tp_name
on the scalar objects.This page probably could do with some further cleanup in a future PR, but this should fix most of the technical issues and omissions.
See the commit message for more details
This likely closes gh-16884.