Skip to content

DOC: Improve the docstring of pandas.core.window.Rolling.median #20260

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
38 changes: 35 additions & 3 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,41 @@ def mean(self, *args, **kwargs):
return self._apply('roll_mean', 'mean', **kwargs)

_shared_docs['median'] = dedent("""
%(name)s median
Calculate the %(name)s median.

Parameters
----------
**kwargs
Under Review.

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

See Also
--------
Series.%(name)s : Calling object with Series data
DataFrame.%(name)s : Calling object with DataFrames
Series.median : Equivalent method for Series
DataFrame.median : Equivalent method for DataFrame

Examples
--------
The below example will show a rolling calculation with a window size of
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be more direct and say "Compute the rolling mean of a series with a window size of 3:".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree... but this is median. Copy paste has failed me!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yes median, sorry.

three.

>>> import pandas as pd
>>> import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

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

Import pandas and numpy is not necessary in the examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. I've removed them.

>>> s = pd.Series(np.arange(5))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps construct the series manually to avoid the reader having to think about arange:

s = pd.Series([0, 1, 2, 3, 4])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That make sense. I've changed it from arange to a simple list

>>> s.rolling(3).median()
0 NaN
1 NaN
2 1.0
3 2.0
4 3.0
dtype: float64
""")

def median(self, **kwargs):
Expand Down Expand Up @@ -1244,7 +1278,6 @@ def mean(self, *args, **kwargs):
return super(Rolling, self).mean(*args, **kwargs)

@Substitution(name='rolling')
@Appender(_doc_template)
@Appender(_shared_docs['median'])
def median(self, **kwargs):
return super(Rolling, self).median(**kwargs)
Expand Down Expand Up @@ -1483,7 +1516,6 @@ def mean(self, *args, **kwargs):
return super(Expanding, self).mean(*args, **kwargs)

@Substitution(name='expanding')
@Appender(_doc_template)
@Appender(_shared_docs['median'])
def median(self, **kwargs):
return super(Expanding, self).median(**kwargs)
Expand Down