From efd03f9d1d2632274804ac5692ac218b4ea969f5 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Sat, 2 Jun 2018 10:33:08 +0530 Subject: [PATCH 01/14] Referring to Issue #21286 Added a raise Value Error for case when window==0, Kindly refer to issue #21286 for the same --- pandas/core/window.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/window.py b/pandas/core/window.py index 015e7f7913ed0..72ede160ae1dd 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -96,6 +96,8 @@ def is_freq_type(self): return self.win_type == 'freq' def validate(self): + if self.window==0: + 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 \ From 6a5a26c0847601d056b39079ecf5732e0751a456 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Sat, 2 Jun 2018 10:40:12 +0530 Subject: [PATCH 02/14] white spaces fixed Included white spaces along the operator at line 94 --- pandas/core/window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 72ede160ae1dd..64bb7e86112de 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -96,7 +96,7 @@ def is_freq_type(self): return self.win_type == 'freq' def validate(self): - if self.window==0: + if self.window == 0: 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") From 70e76dfd978a1ad590f3e771202ac936a125d6f2 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Thu, 7 Jun 2018 22:52:47 +0530 Subject: [PATCH 03/14] Update window.py Added one more check for the windows == 0 problem --- pandas/core/window.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/window.py b/pandas/core/window.py index 64bb7e86112de..ed49ba1356fd9 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -604,6 +604,8 @@ def validate(self): if isinstance(window, (list, tuple, np.ndarray)): pass elif is_integer(window): + if window == 0: + raise ValueError("window must not be zero") if window < 0: raise ValueError("window must be non-negative") try: From 2cd9b5cfae997cc6f78480d85781c1d4477fb557 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Thu, 7 Jun 2018 23:30:27 +0530 Subject: [PATCH 04/14] Update test_window.py added windows (0) test cases --- pandas/tests/test_window.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index 74f2c977e0db2..274c340e59532 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -389,9 +389,10 @@ def test_constructor(self, which): c(window=2, min_periods=1, center=False) # GH 13383 - c(0) + with pytest.raises(ValueError): c(-1) + c(0) # not valid for w in [2., 'foo', np.array([2])]: @@ -409,9 +410,9 @@ 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') + c(0, win_type='boxcar') @pytest.mark.parametrize( 'window', [timedelta(days=3), pd.Timedelta(days=3)]) From 87b24177ac5c2cc9b8b51bb7ec2b6f0ead7738a9 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 10:14:34 +0530 Subject: [PATCH 05/14] Update window.py worked on the suggestion by @mroeschke and combined two cases in one --- pandas/core/window.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index ed49ba1356fd9..5e1849bf2d4e4 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -604,10 +604,8 @@ def validate(self): if isinstance(window, (list, tuple, np.ndarray)): pass elif is_integer(window): - if window == 0: - raise ValueError("window must not be zero") - if window < 0: - raise ValueError("window must be non-negative") + if window <= 0: + raise ValueError("window must be positive") try: import scipy.signal as sig except ImportError: From 0349bf05d3cb92fda4fcbc4eece9e46df0979682 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 10:26:09 +0530 Subject: [PATCH 06/14] Update test_window.py --- pandas/tests/test_window.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index 274c340e59532..52e34a0b8dd42 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -389,10 +389,9 @@ def test_constructor(self, which): c(window=2, min_periods=1, center=False) # GH 13383 - with pytest.raises(ValueError): - c(-1) c(0) + c(-1) # not valid for w in [2., 'foo', np.array([2])]: @@ -403,6 +402,7 @@ def test_constructor(self, which): with pytest.raises(ValueError): c(window=2, min_periods=1, center=w) + # these tests seems unnecessary here 21291 @td.skip_if_no_scipy @pytest.mark.parametrize( 'which', ['series', 'frame']) @@ -412,7 +412,7 @@ def test_constructor_with_win_type(self, which): c = o.rolling with pytest.raises(ValueError): c(-1, win_type='boxcar') - c(0, win_type='boxcar') + @pytest.mark.parametrize( 'window', [timedelta(days=3), pd.Timedelta(days=3)]) From 5aacfbb8721841615c528863f8eaba858e39008a Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 11:20:16 +0530 Subject: [PATCH 07/14] Update test_window.py --- pandas/tests/test_window.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index 52e34a0b8dd42..cfd88f41f855e 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -402,7 +402,6 @@ def test_constructor(self, which): with pytest.raises(ValueError): c(window=2, min_periods=1, center=w) - # these tests seems unnecessary here 21291 @td.skip_if_no_scipy @pytest.mark.parametrize( 'which', ['series', 'frame']) @@ -412,7 +411,6 @@ def test_constructor_with_win_type(self, which): c = o.rolling with pytest.raises(ValueError): c(-1, win_type='boxcar') - @pytest.mark.parametrize( 'window', [timedelta(days=3), pd.Timedelta(days=3)]) From 4131f30e51d4e949e5b048b108b8d9608d78b7c6 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 11:22:12 +0530 Subject: [PATCH 08/14] Update window.py --- pandas/core/window.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 5e1849bf2d4e4..a4e277acc0f58 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -96,8 +96,8 @@ def is_freq_type(self): return self.win_type == 'freq' def validate(self): - if self.window == 0: - raise ValueError("Please Enter a window other than 0") + if self.window <= 0: + raise ValueError("please enter a positive window") 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 \ From 956a7f244367bfadbe2c8efc2fd655f9428a3eb9 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 11:28:41 +0530 Subject: [PATCH 09/14] Update window.py --- pandas/core/window.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index a4e277acc0f58..177d60e4660e9 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -604,8 +604,6 @@ def validate(self): if isinstance(window, (list, tuple, np.ndarray)): pass elif is_integer(window): - if window <= 0: - raise ValueError("window must be positive") try: import scipy.signal as sig except ImportError: From a69e0e086e80ed46d469edcbfe901fcda50be4c6 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 16:01:01 +0530 Subject: [PATCH 10/14] Update window.py --- pandas/core/window.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index 177d60e4660e9..cddf49ca6a337 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -96,8 +96,6 @@ def is_freq_type(self): return self.win_type == 'freq' def validate(self): - if self.window <= 0: - raise ValueError("please enter a positive window") 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 \ @@ -604,6 +602,8 @@ def validate(self): if isinstance(window, (list, tuple, np.ndarray)): pass elif is_integer(window): + if window <= 0: + raise ValueError("please enter a positive window") try: import scipy.signal as sig except ImportError: From c9c769e752ff3773a8bfc58db151a0d51371ed9e Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 17:14:43 +0530 Subject: [PATCH 11/14] Update window.py Updated the commit according to the suggestion --- pandas/core/window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/window.py b/pandas/core/window.py index cddf49ca6a337..9d0f9dc4f75f9 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -603,7 +603,7 @@ def validate(self): pass elif is_integer(window): if window <= 0: - raise ValueError("please enter a positive window") + raise ValueError("window must be > 0 ") try: import scipy.signal as sig except ImportError: From da21015b21f7439c1b633e8fae0e660aeb7226d0 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 17:27:32 +0530 Subject: [PATCH 12/14] Update v0.23.1.txt --- doc/source/whatsnew/v0.23.1.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index f2bc81eea186b..84336d8a97410 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -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`) Strings ^^^^^^^ From 5ecc43673f2c64cdf8eaa31e6ab01aa2c9c54193 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 19:33:55 +0530 Subject: [PATCH 13/14] Update v0.23.1.txt --- doc/source/whatsnew/v0.23.1.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index 84336d8a97410..6a462e44ef655 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -52,8 +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`) - +-Bug in :func:`pandas.DataFrame.rolling` and :func:`pandas.Series.rolling` which incorrectly accepted a 0 window size rather than raising (:issue:`21286`) Strings ^^^^^^^ From 9f5745cbb837ab8e7be10852c6dbaedf611a3c78 Mon Sep 17 00:00:00 2001 From: Uddeshya Singh Date: Fri, 8 Jun 2018 19:37:19 +0530 Subject: [PATCH 14/14] Update v0.23.1.txt --- doc/source/whatsnew/v0.23.1.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index 6a462e44ef655..733633c38c281 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -52,7 +52,8 @@ 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.DataFrame.rolling` and :func:`pandas.Series.rolling` which incorrectly accepted a 0 window size rather than raising (:issue:`21286`) +- Bug in :func:`pandas.DataFrame.rolling` and :func:`pandas.Series.rolling` which incorrectly accepted a 0 window size rather than raising (:issue:`21286`) + Strings ^^^^^^^