-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
15819 rolling window on empty df #16431
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
15819 rolling window on empty df #16431
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a couple small comments.
doc/source/whatsnew/v0.20.2.txt
Outdated
@@ -37,6 +37,7 @@ Bug Fixes | |||
~~~~~~~~~ | |||
|
|||
- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`) | |||
- Bug creating rolling datetime rolling window on empty DataFrame (:issue:`15819`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think "datetime rolling window" (bit of a weird name).
pandas/tests/test_window.py
Outdated
@@ -441,6 +441,16 @@ def test_closed(self): | |||
with pytest.raises(ValueError): | |||
df.rolling(window=3, closed='neither') | |||
|
|||
def test_empty_df_datetime_rolling_sum(self): | |||
result = DataFrame().rolling('1s').sum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cna you leave a comment here with the github issue number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have updated with a comment
Codecov Report
@@ Coverage Diff @@
## master #16431 +/- ##
==========================================
- Coverage 90.42% 90.42% -0.01%
==========================================
Files 161 161
Lines 51023 51023
==========================================
- Hits 46138 46137 -1
- Misses 4885 4886 +1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16431 +/- ##
==========================================
+ Coverage 90.42% 90.43% +<.01%
==========================================
Files 161 161
Lines 51023 51036 +13
==========================================
+ Hits 46138 46152 +14
+ Misses 4885 4884 -1
Continue to review full report at Codecov.
|
pandas/tests/test_window.py
Outdated
|
||
def test_empty_df_integer_rolling_sum(self): | ||
# Verifies that integer rolling window can be applied to empty DataFrame | ||
# GH 15819 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the same tests for expanding (not that the expanding will raise for the time-aware, a separate issue, so xfail that one, put a ref to #16425 there).
pandas/tests/test_window.py
Outdated
|
||
def test_empty_df_integer_rolling_sum(self): | ||
# Verifies that integer rolling window can be applied to empty DataFrame | ||
# GH 15819 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add these as well (which are known working)
DataFrame(index=pd.DatetimeIndex([])).rolling(1).sum()
DataFrame(index=pd.DatetimeIndex([])).rolling('1s').sum()
doc/source/whatsnew/v0.20.2.txt
Outdated
@@ -37,6 +37,7 @@ Bug Fixes | |||
~~~~~~~~~ | |||
|
|||
- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`) | |||
- Bug creating datetime rolling window on empty DataFrame (:issue:`15819`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move to the rolling bug fix section
@jreback Thanks for the review - I have tried to address your comments |
doc/source/whatsnew/v0.20.2.txt
Outdated
@@ -68,7 +69,7 @@ Plotting | |||
Groupby/Resample/Rolling | |||
^^^^^^^^^^^^^^^^^^^^^^^^ | |||
|
|||
|
|||
- Bug creating datetime rolling window on empty DataFrame (:issue:`15819`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on an empty DataFrame
pandas/tests/test_window.py
Outdated
@@ -441,6 +441,34 @@ def test_closed(self): | |||
with pytest.raises(ValueError): | |||
df.rolling(window=3, closed='neither') | |||
|
|||
def test_empty_df_datetime_rolling_sum(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than making all separate tests, either use parametrize, or you can consolidate these into 2 tests for rolling (and 2 for expanding)
e.g.
@pytest.mark.parametrize('roller', ['1s', 1]):
def tests_empty_df_rolling(self, roller):
expected = DataFrame()
result = DataFrame().rolling(roller).sum()
tm.assert_frame_equal(result, expected)
expected = DataFrame(index=pd.DatetimeIndex([]))
result = DataFrame(index=pd.DatetimeIndex([])).rolling(roller).sum()
tm.assert_frame_equal(result, expected)
@jreback I have tried to address your comments. Thanks |
pandas/tests/test_window.py
Outdated
@@ -483,6 +496,35 @@ def test_numpy_compat(self): | |||
tm.assert_raises_regex(UnsupportedFunctionCall, msg, | |||
getattr(e, func), dtype=np.float64) | |||
|
|||
# TODO: GH 16425: Add '1s' datetime expander when GH 16425 is resolved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so you can add in a parameter that xfails itself, IOW
@pytest.mark.parametrize('expander', [1, pytest.mark.xfail(reason='GH 16425 expanding with offset not supported)('1s')])
pandas/tests/test_window.py
Outdated
result = DataFrame(index=pd.DatetimeIndex([])).expanding(expander).sum() | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# TODO: GH 16425: Remove this test and add '1s' to roller parameter of test_empty_df_expanding() parameter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these lines are too long for the linter
pandas/tests/test_window.py
Outdated
|
||
# TODO: GH 16425: Remove this test and add '1s' to roller parameter of test_empty_df_expanding() parameter | ||
# when GH 16425 is resolved | ||
@pytest.mark.xfail(reason="Open issue GH 16425") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a referece to what this issue is fixing as well (like I showed above), this is a printed warning when running the tests e.g.
pytest ..... -r x
will show them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor doc/test comments. some linting issues. ping when green.
@jreback Thanks for the suggestions. I have updated the tests as you have indicated and verified the new test code lints clean. |
thanks! |
(cherry picked from commit e41fe7f)
(cherry picked from commit e41fe7f)
git diff upstream/master --name-only -- '*.py' | flake8 --diff