-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
Added a raise Value Error for case when window==0, Kindly refer to issue pandas-dev#21286 for the same
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 |
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
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 |
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). |
@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) |
@jorisvandenbossche I would do that soon and thanks for the link |
Added one more check for the windows == 0 problem
Can you add a test to ensure that this raises? Also will eventually want a whatsnew note (probably 0.24 at this point) |
pandas/core/window.py
Outdated
@@ -602,6 +604,8 @@ def validate(self): | |||
if isinstance(window, (list, tuple, np.ndarray)): | |||
pass | |||
elif is_integer(window): | |||
if window == 0: |
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.
Instead, you can combine this check with the one below (i.e window <= 0
) and then raise an appropriate error message
added windows (0) test cases
worked on the suggestion by @mroeschke and combined two cases in one
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 like there are some test failures that need to be addressed, but otherwise minor comments on current code
pandas/core/window.py
Outdated
@@ -96,6 +96,8 @@ def is_freq_type(self): | |||
return self.win_type == 'freq' | |||
|
|||
def validate(self): | |||
if self.window == 0: |
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.
As @mroeschke pointed out can't you combine this with the check below? Don't think we need this
pandas/tests/test_window.py
Outdated
@@ -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 |
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.
Don't need this comment
pandas/tests/test_window.py
Outdated
with pytest.raises(ValueError): | ||
c(-1, win_type='boxcar') | ||
|
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.
Errant extra line here will fail LINTing
pandas/core/window.py
Outdated
if window < 0: | ||
raise ValueError("window must be non-negative") | ||
if window <= 0: | ||
raise ValueError("window must be positive") |
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.
@WillAyd Combined them as pointed out by @mroeschke
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.
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
?
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.
@WillAyd To be really honest, I don't think that it's required either. Let me remove this
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@WillAyd Please check the corrections now and see if it is good enough |
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 a whatsnew note (will be for 0.23.2), so wait for that (soon)
pandas/core/window.py
Outdated
if window < 0: | ||
raise ValueError("window must be non-negative") | ||
if window <= 0: | ||
raise ValueError("please enter a positive window") |
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.
maybe : window must be > 0
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.
@jreback is this a suggestion for ValueError
message?
Updated the commit according to the suggestion
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.
actually if u can put a whatsnew note for 0.23.1
can get this in (bug fixes in the rolling section)
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 a whatsnew note (will be for 0.23.2), so wait for that (soon)
doc/source/whatsnew/v0.23.1.txt
Outdated
@@ -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`) |
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.
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
@WillAyd were your comments addressed? |
lgtm. @WillAyd |
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.
lgtm as well. @jreback let me know if / when you want me to merge
(cherry picked from commit 93be27d)
(cherry picked from commit 93be27d)
Added a raise Value Error for the case when window==0, Kindly refer to issue #21286 for the same
git diff upstream/master -u -- "*.py" | flake8 --diff