Skip to content

DOC: update the Rolling.var docstring #20233

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

Merged

Conversation

mmaybeno
Copy link

@mmaybeno mmaybeno commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

################################################################################
################## Docstring (pandas.core.window.Rolling.var) ##################
################################################################################

Calculate unbiased rolling variance.

Normalized by N-1 by default. This can be changed using the ddof argument.

Parameters
----------
ddof : int, default 1
    Delta Degrees of Freedom.  The divisor used in calculations
    is ``N - ddof``, where ``N`` represents the number of elements.
args
    Under Review.
kwargs
    Under Review.

Returns
-------
Series or DataFrame
    Returned object type is determined by the caller of the rolling
    calculation

See Also
--------
Series.rolling : Calling object with Series data
DataFrame.rolling : Calling object with DataFrames
Series.var : Equivalent method for Series
DataFrame.var : Equivalent method for DataFrame
numpy.var : Equivalent method for Numpy array

Notes
-----
A minimum of 1 periods is required for the rolling calculation.

Examples
--------
The below example will show a rolling example

>>> s = pd.Series((5,5,5,5,6,7,9,10,5,5,5,5))
>>> s.rolling(3).var(1)
0          NaN
1          NaN
2     0.000000
3     0.000000
4     0.333333
5     1.000000
6     2.333333
7     2.333333
8     7.000000
9     8.333333
10    0.000000
11    0.000000
dtype: float64

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
        Errors in parameters section
                Parameter "args" has no type
                Parameter "kwargs" has no type


################################################################################
################# Docstring (pandas.core.window.Expanding.var) #################
################################################################################

Calculate unbiased expanding variance.

Normalized by N-1 by default. This can be changed using the ddof argument.

Parameters
----------
ddof : int, default 1
    Delta Degrees of Freedom.  The divisor used in calculations
    is ``N - ddof``, where ``N`` represents the number of elements.
args
    Under Review.
kwargs
    Under Review.

Returns
-------
Series or DataFrame
    Returned object type is determined by the caller of the expanding
    calculation

See Also
--------
Series.expanding : Calling object with Series data
DataFrame.expanding : Calling object with DataFrames
Series.var : Equivalent method for Series
DataFrame.var : Equivalent method for DataFrame
numpy.var : Equivalent method for Numpy array

Notes
-----
A minimum of 1 periods is required for the rolling calculation.

Examples
--------
The below example will show a rolling example

>>> s = pd.Series((5,5,5,5,6,7,9,10,5,5,5,5))
>>> s.rolling(3).var(1)
0          NaN
1          NaN
2     0.000000
3     0.000000
4     0.333333
5     1.000000
6     2.333333
7     2.333333
8     7.000000
9     8.333333
10    0.000000
11    0.000000
dtype: float64

################################################################################
################################## Validation ##################################
################################################################################

Errors found:
        Errors in parameters section
                Parameter "args" has no type
                Parameter "kwargs" has no type

If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.

@mmaybeno
Copy link
Author

Also updates docs for expanding window

%(name)s variance
Calculate unbiased %(name)s variance.

Normalized by N-1 by default. This can be changed using the ddof argument.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single backtics around ddof since it's a parameter.

10 0.000000
11 0.000000
dtype: float64
""")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show s.expanding(3).var(1) as well?


Parameters
----------
ddof : int, default 1
Delta Degrees of Freedom. The divisor used in calculations
is ``N - ddof``, where ``N`` represents the number of elements.""")
is ``N - ddof``, where ``N`` represents the number of elements.
args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the underlying function takes any additional arguments. Can remove (I think).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it, it looks like it passes them through, but I didn't dive into it's usage.. I'll remove for now.

Returns
-------
Series or DataFrame
Returned object type is determined by the caller of the %(name)s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always the same type as the original object, right? Series.rolling().var is always a Series? Let's say that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But DataFrame.rolling().var() is a DataFrame, so that is what the above sentences tries to say. What do you want to change?

"is determined by " -> "same type as" ?

Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, added some comments.

%(name)s variance
Calculate unbiased %(name)s variance.

Normalized by N-1 by default. This can be changed using the ddof argument.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add backticks around ddof please?

--------
The below example will show a rolling example

>>> s = pd.Series((5,5,5,5,6,7,9,10,5,5,5,5))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add spaces after the commas, so this passes PEP-8


Examples
--------
The below example will show a rolling example
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd take this sentence out, I think users will assume that.

args
Under Review.
kwargs
Under Review.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*args and **kwargs should have the stars. We changed the convention last minute, and the validation script is wrong, ignore the messages.


Returns
-------
Returns the same object type as determined by the caller of the %(name)s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the Series or DataFrame on the line above (as you had it before), that makes it clearer it is one of those.

If you use "same object type", then you can omit "as determined by" I think


Examples
--------
>>> s = pd.Series((5, 5, 5, 5, 6, 7, 9, 10, 5, 5, 5, 5))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment on other PR, can you use a list here instead of tuple?
I also think it can maybe a bit shorter? Or is there something specific you want to illustrate with this exact sequence of numbers ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, no specific reason why I used such a long tuple.

numpy.var : Equivalent method for Numpy array

Notes
-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so in both this one and the std one, should put in the Notes that the ddof default is different than numpy. (we use 1, they use 0). This is in the Series.var/std strings already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jreback jreback added Docs Reshaping Concat, Merge/Join, Stack/Unstack, Explode Numeric Operations Arithmetic, Comparison, and Logical operations labels Mar 10, 2018
is ``N - ddof``, where ``N`` represents the number of elements.""")
is ``N - ddof``, where ``N`` represents the number of elements.
*args
Under Review.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was mentioned that the exact content for what should be documented for args/kwargs was to be determined. If you'd rather me add the documentation I can do that too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're noting that they're accepted, but not used.

@TomAugspurger TomAugspurger merged commit eea0350 into pandas-dev:master Mar 12, 2018
@TomAugspurger
Copy link
Contributor

Thanks again @mmaybeno.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Numeric Operations Arithmetic, Comparison, and Logical operations Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants