Skip to content

DOC: further clarifications to docstring guide #20309

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

Open
jorisvandenbossche opened this issue Mar 12, 2018 · 8 comments
Open

DOC: further clarifications to docstring guide #20309

jorisvandenbossche opened this issue Mar 12, 2018 · 8 comments
Labels

Comments

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Mar 12, 2018

I merged the docstring guide #19704 in its current state from the sprint.

But based on the sprint experience, I think we noticed a few areas that can use further clarifications to have less confusion / discussion:

  • Better overview of when to use which type of quotes (single quotes ' or single ` or double backticks ``). The way I currently review:
    • no quotes in type description (even if it may need one according to next rules)
    • single backticks to reference parameter names
    • double backticks for small code snippets, like False or param=value, but, often used class names of pandas like Series, DataFrame, Index are not quoted.
  • In specifications like "See Also" or "Returns", include .pandas or not?
  • Do we use refer to missing values as "NA", "NaN", "NA/NaN", ..
  • Are we OK with using "label" in type descriptions to refer to column names? (instead of str, as this is in principle too restrictive)
  • ...

Did you experience any others?

Let's discuss here what to do with them. Detailed inline comments can still be made on #19704

cc @datapythonista @WillAyd @TomAugspurger @jreback

@TomAugspurger
Copy link
Contributor

Your quoting rules seem sensible to me.

For "See Also" I say no to things that are in pandas' top-level namespace, at least Index / Series / DataFrame. Maybe for less well-known things like Categorical.

For Missing values: NA when referring to the concept, NaN (or NaT) when referring to a specific value. So

# docstring for isna.

Check for missing (NA) values. The values ``NaN``, ``NaT``, ... are considered missing.

For "label", yes I think so. Likewise for row labels.


Some other ones: Do we use sphinx reference markup in types? I merged a couple in plotting that were like

Returns
--------
ax : :class:`matplotlib.axes.Axes`
    ...

But that's a bit noisy. I think it'd be better to just have

ax : Axes
    The :class:`matplotlib.axes.Axes` this was plotted on...

@TomAugspurger
Copy link
Contributor

We should emphasize linking back to relevant sections of the user guide.

@jorisvandenbossche
Copy link
Member Author

We should emphasize linking back to relevant sections of the user guide.

Yes, I was thinking about if we could have a separate section for this (like See Also now, but then similar box with eg "Related User Guides" or something like that), but that would require some changes to numpydoc to allow this. And I was also thinking of a kind of general way to do this from tagging sections in User guide with methods that should be linked to that section, and then those links could automatically be added in the docstrings (like with a Gallery, the links are also injected into the docstrings).
But since both are rather far off, more plain linking for now is a good recommendation :)

@TomAugspurger
Copy link
Contributor

For now, I think that the extended summary is the best place for referring to the user guide.

@TomAugspurger
Copy link
Contributor

Another quoting rule: exception classes like ValueError.

@IHackPy
Copy link
Contributor

IHackPy commented Mar 13, 2018

I thought example section too :

  1. We should copy our example from normal python terminal instead of IPython or jupyter.
  2. When we add comment with in the example and also when therir should gap b/w lines

@TomAugspurger
Copy link
Contributor

In #20332 @adatasetaday mentioned "format of axis parameters".

axis : "{0 or 'index', 1 or 'columns', None}, default None"

To what extent do we think that we can add rules like this to the linter? I'd like as much of this to be rules-based and automated.

@TomAugspurger
Copy link
Contributor

Should explain how we doctest warnings.

doctest doesn't make it show and test when a warning is issued. Our approach
is to include the warning as a comment in the input of the snippet.

def f(x):
    warnings.warn("This function warns")
    return x

So in the doctest, you would write

>>> f(2)
... # UserWarning: This function warns
2

Note that the line displaying the warning starts with `...`. This makes it part of the
input so it isn't actually tested. But it doesn't interfere with the test output.

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

No branches or pull requests

3 participants