Skip to content

DOC: Fixing EX01 - Added examples #53948

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
merged 9 commits into from
Jul 5, 2023
4 changes: 0 additions & 4 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas_object \
pandas.api.interchange.from_dataframe \
pandas.DatetimeIndex.snap \
pandas.core.window.rolling.Rolling.max \
pandas.core.window.rolling.Rolling.cov \
pandas.core.window.rolling.Rolling.skew \
pandas.core.window.rolling.Rolling.apply \
pandas.core.window.rolling.Window.mean \
pandas.core.window.rolling.Window.sum \
pandas.core.window.rolling.Window.var \
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/window/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def create_section_header(header: str) -> str:

template_see_also = dedent(
"""
pandas.Series.{window_method} : Calling {window_method} with Series data.
pandas.DataFrame.{window_method} : Calling {window_method} with DataFrames.
pandas.Series.{agg_method} : Aggregating {agg_method} for Series.
pandas.DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n
Series.{window_method} : Calling {window_method} with Series data.
DataFrame.{window_method} : Calling {window_method} with DataFrames.
Series.{agg_method} : Aggregating {agg_method} for Series.
DataFrame.{agg_method} : Aggregating {agg_method} for DataFrame.\n
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll put them back. It was to get rid of these errors after running validate_docstirngs.py:

        pandas.Series.rolling in `See Also` section does not need `pandas` prefix, use Series.rolling instead.
        pandas.DataFrame.rolling in `See Also` section does not need `pandas` prefix, use DataFrame.rolling instead.
        pandas.Series.max in `See Also` section does not need `pandas` prefix, use Series.max instead.
        pandas.DataFrame.max in `See Also` section does not need `pandas` prefix, use DataFrame.max instead.

But I did forget to see the preview again, sorry.

Copy link
Member

Choose a reason for hiding this comment

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

thanks! I'll check again once the new preview renders. this may be a bug in validate_docstrings unfortunately

"""
).replace("\n", "", 1)

Expand Down
63 changes: 59 additions & 4 deletions pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,19 @@ def count(self, numeric_only: bool = False):
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
template_see_also[:-1],
template_see_also,
create_section_header("Examples"),
dedent(
"""
>>> ser = pd.Series([1, 6, 5, 4])
>>> ser.rolling(2).apply(lambda s: s.sum() - s.min())
0 NaN
1 6.0
2 6.0
3 5.0
dtype: float64
"""
).replace("\n", "", 1),
window_method="rolling",
aggregation_description="custom aggregation function",
agg_method="apply",
Expand Down Expand Up @@ -2008,7 +2020,19 @@ def sum(
create_section_header("See Also"),
template_see_also,
create_section_header("Notes"),
numba_notes[:-1],
numba_notes,
create_section_header("Examples"),
dedent(
"""
>>> ser = pd.Series([1, 2, 3, 4])
>>> ser.rolling(2).max()
0 NaN
1 2.0
2 3.0
3 4.0
dtype: float64
"""
).replace("\n", "", 1),
window_method="rolling",
aggregation_description="maximum",
agg_method="max",
Expand Down Expand Up @@ -2288,7 +2312,25 @@ def var(
"scipy.stats.skew : Third moment of a probability density.\n",
template_see_also,
create_section_header("Notes"),
"A minimum of three periods is required for the rolling calculation.\n",
dedent(
"""
A minimum of three periods is required for the rolling calculation.\n
"""
).replace("\n", "", 1),
Copy link
Member

Choose a reason for hiding this comment

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

can we remove this replace too?

Copy link
Member Author

Choose a reason for hiding this comment

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

ouch - sure.
FYI .replace("\n", "", 1) is still 23 times on that rolling.py file. It was there before I touched the file. That is why I did the same.
It's 16 times on expanding.py (before my changes).

Copy link
Member

Choose a reason for hiding this comment

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

ah I see, thanks - maybe we can remove the rest as part of a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

create_section_header("Examples"),
dedent(
"""
>>> ser = pd.Series([1, 5, 2, 7, 12, 6])
>>> ser.rolling(3).skew().round(6)
0 NaN
1 NaN
2 1.293343
3 -0.585583
4 0.000000
5 1.545393
dtype: float64
"""
).replace("\n", "", 1),
window_method="rolling",
aggregation_description="unbiased skewness",
agg_method="skew",
Expand Down Expand Up @@ -2538,7 +2580,20 @@ def rank(
create_section_header("Returns"),
template_returns,
create_section_header("See Also"),
template_see_also[:-1],
template_see_also,
create_section_header("Examples"),
dedent(
"""
>>> ser1 = pd.Series([1, 2, 3, 4])
>>> ser2 = pd.Series([1, 4, 5, 8])
>>> ser1.rolling(2).cov(ser2)
0 NaN
1 1.5
2 0.5
3 1.5
dtype: float64
"""
).replace("\n", "", 1),
window_method="rolling",
aggregation_description="sample covariance",
agg_method="cov",
Expand Down