Skip to content

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

Merged
merged 8 commits into from
May 25, 2017

Conversation

chernrick
Copy link
Contributor

@TomAugspurger TomAugspurger added this to the 0.20.2 milestone May 22, 2017
@TomAugspurger TomAugspurger added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Datetime Datetime data dtype labels May 22, 2017
Copy link
Contributor

@TomAugspurger TomAugspurger 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, just a couple small comments.

@@ -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`)
Copy link
Contributor

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).

@@ -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()
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link

codecov bot commented May 22, 2017

Codecov Report

Merging #16431 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.26% <100%> (-0.01%) ⬇️
#single 40.17% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/window.py 96.24% <100%> (ø) ⬆️
pandas/core/common.py 91.05% <0%> (-0.34%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49ec31b...d31b983. Read the comment docs.

@codecov
Copy link

codecov bot commented May 22, 2017

Codecov Report

Merging #16431 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 88.26% <100%> (ø) ⬆️
#single 40.17% <0%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/window.py 96.48% <100%> (+0.23%) ⬆️
pandas/io/feather_format.py 85.71% <0%> (-2.17%) ⬇️
pandas/core/reshape/merge.py 94.18% <0%> (-0.01%) ⬇️
pandas/errors/__init__.py 100% <0%> (ø) ⬆️
pandas/core/frame.py 97.69% <0%> (ø) ⬆️
pandas/core/missing.py 84.27% <0%> (ø) ⬆️
pandas/core/generic.py 92.13% <0%> (ø) ⬆️
pandas/core/reshape/reshape.py 99.28% <0%> (ø) ⬆️
pandas/io/formats/style.py 95.92% <0%> (+0.01%) ⬆️
pandas/io/parsers.py 95.33% <0%> (+0.01%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 49ec31b...4a81a5e. Read the comment docs.


def test_empty_df_integer_rolling_sum(self):
# Verifies that integer rolling window can be applied to empty DataFrame
# GH 15819
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 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).


def test_empty_df_integer_rolling_sum(self):
# Verifies that integer rolling window can be applied to empty DataFrame
# GH 15819
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 these as well (which are known working)

DataFrame(index=pd.DatetimeIndex([])).rolling(1).sum()

DataFrame(index=pd.DatetimeIndex([])).rolling('1s').sum()

@@ -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`)
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 move to the rolling bug fix section

@chernrick
Copy link
Contributor Author

@jreback Thanks for the review - I have tried to address your comments

@@ -68,7 +69,7 @@ Plotting
Groupby/Resample/Rolling
^^^^^^^^^^^^^^^^^^^^^^^^


- Bug creating datetime rolling window on empty DataFrame (:issue:`15819`)
Copy link
Contributor

Choose a reason for hiding this comment

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

on an empty DataFrame

@@ -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):
Copy link
Contributor

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)

@chernrick
Copy link
Contributor Author

@jreback I have tried to address your comments. Thanks

@@ -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
Copy link
Contributor

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')])

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
Copy link
Contributor

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


# 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")
Copy link
Contributor

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

Copy link
Contributor

@jreback jreback left a 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.

@chernrick
Copy link
Contributor Author

@jreback Thanks for the suggestions. I have updated the tests as you have indicated and verified the new test code lints clean.

@jreback jreback merged commit e41fe7f into pandas-dev:master May 25, 2017
@jreback
Copy link
Contributor

jreback commented May 25, 2017

thanks!

TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request May 29, 2017
TomAugspurger pushed a commit that referenced this pull request May 30, 2017
stangirala pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERR: consistency in rolling on empty frames
3 participants