Skip to content

Conversation

@luke396
Copy link
Contributor

@luke396 luke396 commented Dec 9, 2022

I'm a newbie, and welcome any comments!

@phofl phofl changed the title DOC: Add example for pandas.DataFrame.rolling() DOC: Add example for pandas.DataFrame.rolling() with on Dec 9, 2022
Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

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

It looks like the docstring validation is failing. Could you investigate?

I think one example is sufficient

@luke396
Copy link
Contributor Author

luke396 commented Dec 11, 2022

It looks like the docstring validation is failing. Could you investigate?

I think one example is sufficient

Ok, I will try to pass the docstring validation, and reduce two example to one.

Thanks for your comments!

@luke396
Copy link
Contributor Author

luke396 commented Dec 11, 2022

When I use python make.py --single pandas.DataFrame.rolling, there is a warning, WARNING: extlinks: Sphinx-6.0 will require a caption string to contain exactly one '%s' and all other '%' need to be escaped as '%%'., I'm not sure that matters.

@luke396 luke396 requested a review from phofl December 11, 2022 03:29
@luke396 luke396 closed this Dec 12, 2022
@luke396 luke396 deleted the add_exam_rolling_on branch December 12, 2022 00:25
@luke396 luke396 restored the add_exam_rolling_on branch December 12, 2022 00:27
@luke396 luke396 reopened this Dec 12, 2022
@luke396
Copy link
Contributor Author

luke396 commented Dec 12, 2022

I'm so sorry that my improper operation messed up the PR!

3 NaN 6.0
4 7.0 8.0
>>> df.rolling(2, on='A').sum()
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't this give the same result even without on='A'? might be more illustrative to have an example in which on= makes a difference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without on='A', the result will be like this:

>>> df.rolling(2).sum() A B 0 NaN NaN 1 4.0 6.0 2 8.0 NaN 3 NaN NaN 4 NaN 14.0 

Do I need to add this result as comparison?

Copy link
Member

@MarcoGorelli MarcoGorelli Dec 13, 2022

Choose a reason for hiding this comment

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

I was thinking more something like

In [62]: df = pd.DataFrame({ ...: 'A': to_datetime(['2020-01-01', '2020-01-01', '2020-01-02']), ...: 'B': [1,2,3], ...: }, ...: index=date_range('2020', periods=3))

in which if you do rolling('D'), then the values of 'B' differ if you do on='A' (instead of the default, which uses the index)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see what that means. How about the following:

>>> df = pd.DataFrame({ ... 'A': [pd.to_datetime('2020-01-01'), ... pd.to_datetime('2020-01-01'), ... pd.to_datetime('2020-01-02'),], ... 'B': [1, 2, 3], }, ... index=pd.date_range('2020', periods=3)) >>> df A B 2020-01-01 2020-01-01 1 2020-01-02 2020-01-01 2 2020-01-03 2020-01-02 3 >>> df['B'].rolling('2D').sum() # to avoid warning when sum on 'A' 2020-01-01 1.0 2020-01-02 3.0 2020-01-03 5.0 Freq: D, Name: B, dtype: float64 >>> df.rolling('2D', on='A').sum() # value of 'B' is differ from above A B 2020-01-01 2020-01-01 1.0 2020-01-02 2020-01-01 3.0 2020-01-03 2020-01-02 6.0 
Copy link
Member

@MarcoGorelli MarcoGorelli Dec 13, 2022

Choose a reason for hiding this comment

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

# value of 'B' differs from above

other than that, looks fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the correction, my English skills are a little rusty.

@mroeschke mroeschke added Docs Window rolling, ewma, expanding labels Dec 13, 2022
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Almost there 💪

**on**
Rolling sum with a window length of 2 on specific columon.
Copy link
Member

Choose a reason for hiding this comment

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

2 days?

Comment on lines 1131 to 1136
>>> df['B'].rolling('2D').sum() # to avoid warning when sum on 'A'
2020-01-01 1.0
2020-01-02 3.0
2020-01-03 5.0
Freq: D, Name: B, dtype: float64
Copy link
Member

Choose a reason for hiding this comment

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

Seeing as you start with

Rolling sum with a window length of 2 on specific columon.

we can probably exclude this example. If someone tries running it locally, then can remove on= and see the difference, at which point it should be clear what it's done

2020-01-03 5.0
Freq: D, Name: B, dtype: float64
>>> df.rolling('2D', on='A').sum() # value of 'B' differs from above
Copy link
Member

Choose a reason for hiding this comment

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

let's remove the comment

@luke396
Copy link
Contributor Author

luke396 commented Dec 14, 2022

Almost there 💪

How about this one 😄

Thank you for taking the time to share your thoughts with me. I really appreciate your review.

@MarcoGorelli MarcoGorelli added this to the 2.0 milestone Dec 14, 2022
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

looks good, thanks @luke396 !

@MarcoGorelli MarcoGorelli merged commit e17a7f8 into pandas-dev:main Dec 14, 2022
@luke396 luke396 deleted the add_exam_rolling_on branch December 15, 2022 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Docs Window rolling, ewma, expanding

4 participants