Skip to content

TST: add test for rolling max with DatetimeIndex #29761

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/tests/window/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,20 @@ def test_rolling_corr_with_zero_variance(self, window):

assert s.rolling(window=window).corr(other=other).isna().all()

def test_rolling_max_datetimeindex(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

move to tests/window/test_timeseries_window.py and put near similar tests (this might be a duplicate)

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 feedback, @jreback. Moved the test to tests/window/test_timeseries_window.py. This test is different by being the only one using minutes as frequency in the file. Other minor differences is that it's using Series as opposed to DataFrame and explicit definition of expected.

Having said that, I agree that there are very similar tests and I'm happy to remove it all together.

Copy link
Member

Choose a reason for hiding this comment

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

@ganevgv if you would like to clean that up and parametrize frequencies / containers that would be very welcome

# GH 21096
n = 10
index = pd.date_range(start="2018-1-1 01:00:00", freq="1min", periods=n)
s = Series(data=0, index=index)

s.iloc[1] = np.nan
s.iloc[-1] = 2
maxes = s.rolling(window=f"{n}min").max()
result = maxes.value_counts(dropna=False)
expected = Series(data={0.0: n - 1, 2.0: 1})

tm.assert_series_equal(result, expected)

def _check_pairwise_moment(self, dispatch, name, **kwargs):
def get_result(obj, obj2=None):
return getattr(getattr(obj, dispatch)(**kwargs), name)(obj2)
Expand Down