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
6 changes: 4 additions & 2 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

raise ValueError("Please Enter a window other than 0")
if self.center is not None and not is_bool(self.center):
raise ValueError("center must be a boolean")
if self.min_periods is not None and not \
Expand Down Expand Up @@ -602,8 +604,8 @@ def validate(self):
if isinstance(window, (list, tuple, np.ndarray)):
pass
elif is_integer(window):
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

try:
import scipy.signal as sig
except ImportError:
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ def test_constructor(self, which):
c(window=2, min_periods=1, center=False)

# GH 13383
c(0)
with pytest.raises(ValueError):
c(0)
c(-1)

# not valid
Expand All @@ -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

@td.skip_if_no_scipy
@pytest.mark.parametrize(
'which', ['series', 'frame'])
def test_constructor_with_win_type(self, which):
# GH 13383
o = getattr(self, which)
c = o.rolling
c(0, win_type='boxcar')
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


@pytest.mark.parametrize(
'window', [timedelta(days=3), pd.Timedelta(days=3)])
Expand Down