Skip to content
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

Standard docstring formatting conventions proposal #1174

Open
jGaboardi opened this issue Apr 26, 2020 · 7 comments
Open

Standard docstring formatting conventions proposal #1174

jGaboardi opened this issue Apr 26, 2020 · 7 comments

Comments

@jGaboardi
Copy link
Member

jGaboardi commented Apr 26, 2020

Standard docstring formatting conventions proposal

  1. Based on numpy.
  2. Summary starts directly after triple quotes on first line.
  3. Empty line between all sections.
  4. Valid sections are documented here.
  5. If the docstring is a single-line summary, put triple quotes on that line.
  6. Variables should be returned whenever possible to aid in clarity and documentation.
  7. Enforce proper spelling, grammar, and punctuation.
  8. Add type hinting where appropriate.
  9. Elements within the Parameters and Returns section should be in the following format:
    <empty line>
    <Section>
    <parameter/variable name><single space><:><single space><type>
    <four-space indent><description>
    <parameter/variable name><single space><:><single space><type>
    <four-space indent><description>
    <empty line>
    <Section>
    

Basic example

def main_func(arg1, arg2):
    """Perform the main function calculation.
    
    Parameters
    ----------
    arg1 : list
        Some values of data.
    arg2 : int
        Some multiplier.
    
    Returns
    -------
    result : list
        Some transformed values of data.
    
    Notes
    -----
    This is a sample equation within a docstring:
    
    .. math::
        
       \displaystyle E = mc^2
        
    See also
    --------
    some.other.Class
    
    Examples
    --------
    Call ``main_func()`` with the following parameters.
    
    >>> main_func([3, 4], 2)
    [6, 8]
    
    """
    
    def helper_func(x: int) -> int:
        """Helper for calculating X."""
        new_x = x*arg2
        return new_x
    
    result = []
    for v in arg1:
        result.append(helper_func(v))
    
    return result
@jGaboardi
Copy link
Member Author

The @pysal/devs team voted in favor of the standard in the May meeting.

@jGaboardi jGaboardi self-assigned this May 1, 2020
@jGaboardi
Copy link
Member Author

@sjsrey @ljwolf I would like to create a new project board for keeping track of progress, etc. on this. Where would it best reside: pysal/pysal, pysal/libpysal, some other repo, or no other repo?

@jGaboardi
Copy link
Member Author

jGaboardi commented May 1, 2020

@sjsrey
Copy link
Member

sjsrey commented May 1, 2020

pysal/pysal makes sense to me

@slumnitz
Copy link
Member

slumnitz commented Jun 6, 2020

Thank you for initiating for bettering documentation @jGaboardi!
I'd like to double check, the official NumPy example does not contain lines between different Parameters,but only between section headers Parameters, Returns, ..., to keep the documentation compact. I would vouch for not including these extra lines, as documentation for functions with many parameters could get very lengthy/ easy to loose sight of parameter options. What do you think and could this be optional potentially?

@jGaboardi
Copy link
Member Author

@slumnitz Yes, you are correct. My example does not exactly conform to numpy's. Thanks for pointing this out. I will update the example and review the work I am currently doing in libpysal.

@jGaboardi
Copy link
Member Author

An automated tool for numpy-style docstring reformatting to keep an eye on from Matthias Bussonnier: see tweet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Standardize Docstrings
  
In progress
pysal 2.4.0
  
Done
Development

No branches or pull requests

3 participants