Skip to content

BUG: invalid rolling window on empty input #21291

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 14 commits into from
Jun 8, 2018
Merged

Conversation

uds5501
Copy link
Contributor

@uds5501 uds5501 commented Jun 2, 2018

Added a raise Value Error for the case when window==0, Kindly refer to issue #21286 for the same

Added a raise Value Error for case when window==0, Kindly refer to issue pandas-dev#21286 for the same
@pep8speaks
Copy link

pep8speaks commented Jun 2, 2018

Hello @uds5501! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on June 08, 2018 at 14:07 Hours UTC

@uds5501
Copy link
Contributor Author

uds5501 commented Jun 2, 2018

Respected Seniors, this is literally my first PR. Kindly do guide me if I do anything wrong here

Included white spaces along the operator at line 94
@WillAyd
Copy link
Member

WillAyd commented Jun 2, 2018

Thanks for the PR! This appears to have broken a few tests. Be sure to check out the contributing to pandas guide and follow the steps locally to make sure you don't get any test errors before pushing to GitHub:

https://pandas.pydata.org/pandas-docs/stable/contributing.html

@jorisvandenbossche
Copy link
Member

Some of those tests were added explicitly to test this in #13441 (it was a PR to disallow negative windows, but explicitly tested windows of zero not too raise upon construction).
I am not fully sure why those were added, so I think you can actually change those tests.

@jorisvandenbossche
Copy link
Member

@uds5501 also general feedback: can you give the PR a more informative title? (you can still edit the title, see 'edit' button at the right of it)

@uds5501
Copy link
Contributor Author

uds5501 commented Jun 4, 2018

@jorisvandenbossche I would do that soon and thanks for the link

@jreback jreback changed the title Referring to Issue #21286 BUG: invalid rolling window on empty input Jun 5, 2018
@jreback jreback added the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jun 5, 2018
Added one more check for the windows == 0 problem
@WillAyd
Copy link
Member

WillAyd commented Jun 7, 2018

Can you add a test to ensure that this raises? Also will eventually want a whatsnew note (probably 0.24 at this point)

@@ -602,6 +604,8 @@ def validate(self):
if isinstance(window, (list, tuple, np.ndarray)):
pass
elif is_integer(window):
if window == 0:
Copy link
Member

Choose a reason for hiding this comment

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

Instead, you can combine this check with the one below (i.e window <= 0) and then raise an appropriate error message

uds5501 added 3 commits June 7, 2018 23:30
added windows (0) test cases
worked on the suggestion by @mroeschke and combined two cases in one
Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

Looks like there are some test failures that need to be addressed, but otherwise minor comments on current code

@@ -96,6 +96,8 @@ def is_freq_type(self):
return self.win_type == 'freq'

def validate(self):
if self.window == 0:
Copy link
Member

Choose a reason for hiding this comment

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

As @mroeschke pointed out can't you combine this with the check below? Don't think we need this

@@ -402,16 +402,17 @@ def test_constructor(self, which):
with pytest.raises(ValueError):
c(window=2, min_periods=1, center=w)

# these tests seems unnecessary here 21291
Copy link
Member

Choose a reason for hiding this comment

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

Don't need this comment

with pytest.raises(ValueError):
c(-1, win_type='boxcar')

Copy link
Member

Choose a reason for hiding this comment

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

Errant extra line here will fail LINTing

if window < 0:
raise ValueError("window must be non-negative")
if window <= 0:
raise ValueError("window must be positive")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd Combined them as pointed out by @mroeschke

Copy link
Member

Choose a reason for hiding this comment

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

My mistake in looking at the git diff I didn't realize they were two different methods. That said, are both required? Doesn't the call to super here raise already in the case where window == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WillAyd To be really honest, I don't think that it's required either. Let me remove this

@codecov
Copy link

codecov bot commented Jun 8, 2018

Codecov Report

Merging #21291 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21291      +/-   ##
==========================================
+ Coverage   91.85%   91.89%   +0.03%     
==========================================
  Files         153      153              
  Lines       49546    49579      +33     
==========================================
+ Hits        45509    45559      +50     
+ Misses       4037     4020      -17
Flag Coverage Δ
#multiple 90.29% <100%> (+0.04%) ⬆️
#single 41.85% <0%> (-0.02%) ⬇️
Impacted Files Coverage Δ
pandas/core/window.py 96.28% <100%> (ø) ⬆️
pandas/core/reshape/melt.py 97.34% <0%> (ø) ⬆️
pandas/io/formats/csvs.py 98.14% <0%> (+0.01%) ⬆️
pandas/core/indexes/interval.py 93.16% <0%> (+0.02%) ⬆️
pandas/core/indexes/datetimes.py 95.8% <0%> (+0.02%) ⬆️
pandas/core/series.py 94.17% <0%> (+0.05%) ⬆️
pandas/core/reshape/pivot.py 97.03% <0%> (+0.05%) ⬆️
pandas/io/formats/style.py 96.12% <0%> (+0.08%) ⬆️
pandas/core/dtypes/missing.py 92.52% <0%> (+0.57%) ⬆️
pandas/plotting/_core.py 83.53% <0%> (+1.14%) ⬆️

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 4274b84...9f5745c. Read the comment docs.

@uds5501
Copy link
Contributor Author

uds5501 commented Jun 8, 2018

@WillAyd Please check the corrections now and see if it is good enough

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.

can you add a whatsnew note (will be for 0.23.2), so wait for that (soon)

if window < 0:
raise ValueError("window must be non-negative")
if window <= 0:
raise ValueError("please enter a positive window")
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe : window must be > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback is this a suggestion for ValueError message?

@jreback jreback added this to the 0.23.2 milestone Jun 8, 2018
Updated the commit according to the suggestion
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.

actually if u can put a whatsnew note for 0.23.1
can get this in (bug fixes in the rolling section)

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.

can you add a whatsnew note (will be for 0.23.2), so wait for that (soon)

@@ -52,6 +52,7 @@ Groupby/Resample/Rolling
- Bug in :func:`DataFrame.agg` where applying multiple aggregation functions to a :class:`DataFrame` with duplicated column names would cause a stack overflow (:issue:`21063`)
- Bug in :func:`pandas.core.groupby.GroupBy.ffill` and :func:`pandas.core.groupby.GroupBy.bfill` where the fill within a grouping would not always be applied as intended due to the implementations' use of a non-stable sort (:issue:`21207`)
- Bug in :func:`pandas.core.groupby.GroupBy.rank` where results did not scale to 100% when specifying ``method='dense'`` and ``pct=True``
- Bug in :func:`pandas.core.windows.Windows.validate` where windows parameter was accpeting a numeric value of 0 (:issue:`21286`)
Copy link
Contributor

Choose a reason for hiding this comment

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

pls make this user facing, something like

Bug in :func:`pandas.DataFrame.rolling` and :func:`pandas.Series.rolling` which incorrectly accepted a 0 window size rather than raising

@jreback
Copy link
Contributor

jreback commented Jun 8, 2018

@WillAyd were your comments addressed?

@jreback jreback modified the milestones: 0.23.2, 0.23.1 Jun 8, 2018
@jreback
Copy link
Contributor

jreback commented Jun 8, 2018

lgtm. @WillAyd

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

lgtm as well. @jreback let me know if / when you want me to merge

@jreback jreback merged commit 93be27d into pandas-dev:master Jun 8, 2018
@jreback
Copy link
Contributor

jreback commented Jun 8, 2018

thanks @uds5501 (and @WillAyd )

TomAugspurger pushed a commit to TomAugspurger/pandas that referenced this pull request Jun 12, 2018
TomAugspurger pushed a commit that referenced this pull request Jun 12, 2018
david-liu-brattle-1 pushed a commit to david-liu-brattle-1/pandas that referenced this pull request Jun 18, 2018
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rolling on 0 window causes core dump
7 participants