Skip to content

DOC: Added reverse rolling window examples #39091

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

Closed
wants to merge 2 commits into from
Closed

DOC: Added reverse rolling window examples #39091

wants to merge 2 commits into from

Conversation

vangorade
Copy link
Contributor

@MarcoGorelli MarcoGorelli self-requested a review January 10, 2021 16:57
@@ -198,6 +198,36 @@ from present information back to past information. This allows the rolling windo

df

.. _window.reverse_rolling_window:

Reverse rolling window
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 just add this as an example of using the FixedForwardWindowIndexer in the Custom window rolling section below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for late reply. Sure i will add it.

@jreback jreback added Docs Window rolling, ewma, expanding labels Jan 11, 2021
Comment on lines 212 to 213
# Using slicing
# apply the rolling aggregation and then flip the result.
Copy link
Member

@MarcoGorelli MarcoGorelli Jan 12, 2021

Choose a reason for hiding this comment

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

looking at other examples from this document, descriptions are typically outside the code blocks (rather than inside them as comments)

Copy link
Member

Choose a reason for hiding this comment

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

Agreed. Would be better if this description was a paragraph before the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done 👍

Comment on lines 214 to 219
df = pd.DataFrame(data=[[pd.Timestamp('2018-01-01 00:00:00'), 100],
[pd.Timestamp('2018-01-01 00:00:01'), 101],
[pd.Timestamp('2018-01-01 00:00:03'), 103],
[pd.Timestamp('2018-01-01 00:00:04'), 111]],
columns=['time', 'value']).set_index('time')
df
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 apply the black formatter to this code block?

df.rolling(2, method="table", min_periods=0).apply(weighted_mean, raw=True, engine="numba") # noqa:E501
df.rolling(2, method="table", min_periods=0).apply(
weighted_mean, raw=True, engine="numba"
) # noqa:E501
Copy link
Contributor

Choose a reason for hiding this comment

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

this noqa is no longer needed

@@ -132,13 +135,13 @@ time based index must be monotonic.

.. ipython:: python

times = ['2020-01-01', '2020-01-03', '2020-01-04', '2020-01-05', '2020-01-29']
times = ["2020-01-01", "2020-01-03", "2020-01-04", "2020-01-05", "2020-01-29"]
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer that you don't change the quoting as its non-essential to this change

).set_index("time")
df

df1 = df[::-1].rolling("2s").sum()[::-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

call this reversed_df or similar

df1 = df[::-1].rolling("2s").sum()[::-1]
df1

Or we can also do it using FixedForwardWindowIndexer which basically Creates window boundaries
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 add the refernce to this, something like :meth:`api.indexers.FixedForwardWindowIndexer`


.. ipython:: python

df = pd.DataFrame(
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to repeat this


indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size=2)

df2 = df.rolling(window=indexer, min_periods=1).sum()
Copy link
Contributor

Choose a reason for hiding this comment

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

name as above

@@ -280,11 +330,23 @@ conditions. In these cases it can be useful to perform forward-looking rolling w
This :func:`BaseIndexer <pandas.api.indexers.BaseIndexer>` subclass implements a closed fixed-width
forward-looking rolling window, and we can use it as follows:

.. ipython:: ipython
.. ipython:: python
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of having this here I woul dmove the example from above here. no reason to have this in 2 places and this is the best one.

@jreback
Copy link
Contributor

jreback commented Jan 21, 2021

can you merge master and update

@jreback
Copy link
Contributor

jreback commented Feb 11, 2021

@vangorade can you merge master and update

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Mar 14, 2021
@mroeschke
Copy link
Member

Going to close this PR due to lack of activity. Let us know if you'd like to continue working on it.

@mroeschke mroeschke closed this Mar 14, 2021
mdhsieh added a commit to mdhsieh/pandas that referenced this pull request Jun 6, 2021
File is copied from @vangorade last changes in pull request (pandas-dev#39091):
pandas-dev#39091

Fixed typo to pass pre-commit codespell hook.
mdhsieh added a commit to mdhsieh/pandas that referenced this pull request Jun 6, 2021
From pull request (pandas-dev#39091):
pandas-dev#39091

- remove noqa
- change line back to single quotes
- rename df1 to reversed_df
mdhsieh added a commit to mdhsieh/pandas that referenced this pull request Jun 6, 2021
From pull request (pandas-dev#39091):
pandas-dev#39091

- remove repeated df initialization in code example
- rename df2 to reversed_df
mdhsieh added a commit to mdhsieh/pandas that referenced this pull request Jun 6, 2021
…andas-dev#38627).

Move code example as suggested in pull request (pandas-dev#39091):
pandas-dev#39091

Compiled document to check it looked fine by running:
python make.py --single user_guide/window.rst
mroeschke pushed a commit that referenced this pull request Jun 11, 2021
* DOC: Add examples to do reversed rolling window (#38627).

File is copied from @vangorade last changes in pull request (#39091):
#39091

Fixed typo to pass pre-commit codespell hook.

* DOC: Add some suggested changes.

From pull request (#39091):
#39091

- remove noqa
- change line back to single quotes
- rename df1 to reversed_df

* DOC: Add reference to FixedForwardWindowIndexer.

* DOC: Add more suggested changes.

From pull request (#39091):
#39091

- remove repeated df initialization in code example
- rename df2 to reversed_df

* DOC: Add suggested changes to reverse rolling window code examples (#38627).

Move code example as suggested in pull request (#39091):
#39091

Compiled document to check it looked fine by running:
python make.py --single user_guide/window.rst

* DOC: Revert more double quotes to single quotes.

Unecessary changes.

* DOC: Change binary window description to match master branch.

Description was not modified after fetching and merging, so pasted from master branch:
https://github.com/pandas-dev/pandas/blob/master/doc/source/user_guide/window.rst

* DOC: Change exponentially weighted mean formula to one in master branch.

Since fetching and merging didn't modify this line.

* DOC: Replace window.rst with file from pandas-dev master branch.

To only add reverse rolling window section and avoid any unwanted changes.

* DOC: Add section with reverse rolling window example.

* DOC: Add section markup.

Forgot to add.

* DOC: Delete the same code example.

FixedForwaredWindowIndexer example is same as the one above the added section.

* DOC: Remove section and first sentence.

Modify sentence slightly to show this example should output same result.

* DOC: Remove unecessary words.

Coding is already in Python.
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
* DOC: Add examples to do reversed rolling window (pandas-dev#38627).

File is copied from @vangorade last changes in pull request (pandas-dev#39091):
pandas-dev#39091

Fixed typo to pass pre-commit codespell hook.

* DOC: Add some suggested changes.

From pull request (pandas-dev#39091):
pandas-dev#39091

- remove noqa
- change line back to single quotes
- rename df1 to reversed_df

* DOC: Add reference to FixedForwardWindowIndexer.

* DOC: Add more suggested changes.

From pull request (pandas-dev#39091):
pandas-dev#39091

- remove repeated df initialization in code example
- rename df2 to reversed_df

* DOC: Add suggested changes to reverse rolling window code examples (pandas-dev#38627).

Move code example as suggested in pull request (pandas-dev#39091):
pandas-dev#39091

Compiled document to check it looked fine by running:
python make.py --single user_guide/window.rst

* DOC: Revert more double quotes to single quotes.

Unecessary changes.

* DOC: Change binary window description to match master branch.

Description was not modified after fetching and merging, so pasted from master branch:
https://github.com/pandas-dev/pandas/blob/master/doc/source/user_guide/window.rst

* DOC: Change exponentially weighted mean formula to one in master branch.

Since fetching and merging didn't modify this line.

* DOC: Replace window.rst with file from pandas-dev master branch.

To only add reverse rolling window section and avoid any unwanted changes.

* DOC: Add section with reverse rolling window example.

* DOC: Add section markup.

Forgot to add.

* DOC: Delete the same code example.

FixedForwaredWindowIndexer example is same as the one above the added section.

* DOC: Remove section and first sentence.

Modify sentence slightly to show this example should output same result.

* DOC: Remove unecessary words.

Coding is already in Python.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Stale Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: example for doing a reversed rolling window
4 participants