-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
DOC: Describe how to include parameter sizes & shapes #423
base: main
Are you sure you want to change the base?
Conversation
I also think this style of including shape info when relevant is what numpydoc should recommend. Adding two extra notes for completeness: Extra pro: It would follow matplotlib's docstring guide (that extends numpydoc) and is followed also (at least) throughout the linalg modules in both numpy and scipy. Reference: https://matplotlib.org/stable/devel/documenting_mpl.html#parameter-type-descriptions, relevant quote:
Extra con: it would make other modules like the polinomyal or some of the random distributions not follow numpydoc anymore because they use the |
The proposal seems sensible to me, but I'd be hesitant to actually adopt any new suggestions/rules without first having some sense of how much churn the proposed rule would cause in e.g. the numpy & scipy docstrings themselves. The fact that the rule is already included in matplotlib's docstring style guide is indeed a strong point in favor though! Another angle I think should be considered is how well this will mesh with the work in NumPy's type annotations re: how array shapes are specified. That's not to say that they have to be (or even should be) the same, but we should at least have an idea of where that's going so we don't end up with two completely divergent ways of specifying shapes for type annotations vs. parameter type descriptions in docstrings. IMO, a great way to push this forward would be to try to systematically evaluate the current state of parameter type descriptions in the docstrings. @OriolAbril notes that this pattern seems to already be followed by the numpy/scipy linalg packages - if there were a listing that showed what set of changes would be necessary to make at least numpy/scipy compliant (preferably a script that could be run on the docs of any library), this would go a long way in supporting the idea that the rule should be enshrined as a style/standard. Then again, I tend to be conservative when it comes to changing/introducing new standards :) |
I still have many modules and pages to go over, but here are my observations so far:
Need to leave now, will continue at some other time. |
We just had an interesting case in scipy/scipy#20072 where there was confusion about the fact that the style of """
a : (M, N) ndarray
""" implies that I wonder if there is any way to be clearer about this, since it probably trips up quite a few new users. Would adding the word 'shape' anywhere be possible (and not overkill / worse overall)? |
Would |
I think so, although the confusion seemed to stem from not understanding that |
I think I prefer how it is done here for example |
Thank you for bringing this up! My main goal is that the style guide addresses this situation in a consistent and understandable way, so I'm totally open to including Since I originally made this PR, we ended up adding guidelines on type specifications in PlasmaPy's documentation guide (permalink). A lot of it came from matplotlib, plus a few other projects. Looking back at this again, I'm thinking that it'd be helpful for the guidelines to address uncommon edge cases too (like when there are multiple distinct shapes an array could have, or when different types have different shapes). Thank you again! |
For context, that was not in fact the source of confusion. The confusion was that it was not mentioned that batch dimensions are not supported, and the function silently returning nonsense for >2D cases. The syntax like (..., M, N) usually clarifies core vs batch cases, but the ommission of ellipsis to specify batch dimensions are not allowed/undefined behavior is imo too subtle/insufficient. I think this should always be stated explicitly if not checked by the function, given the widespread expectation that numpy-like code will handle batch dimensions correctly |
This pull request describes how to include size & shape information for a parameter in the type line of the Parameters section of docstrings. I adapted the example from
numpy.outer
. This is following a discussion in #419.I decided to place the size & shape information at the beginning of the type information because:
Some of the alternatives I considered were:
I am open to alternative possibilities. It's pretty common to need to include this information in docstrings. It's more important that it is included in the standard than the specific details of how it is included.
Thanks!