From 0947a6a31ee4db93cda8c44357d5266b999e3cb6 Mon Sep 17 00:00:00 2001 From: Prashant Tiwari Date: Sat, 26 Mar 2016 13:25:34 +0000 Subject: [PATCH 1/2] Raising TypeError on invalid window when using .rolling #12669 --- pandas/core/window.py | 2 ++ pandas/tests/test_window.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/pandas/core/window.py b/pandas/core/window.py index 31874a96f8111..66d35b7ef38a9 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -1354,6 +1354,8 @@ def _get_center_of_mass(com, span, halflife, alpha): def _offset(window, center): + if com.is_float(window): + raise TypeError("Window should be of type Integer, given Float") if not com.is_integer(window): window = len(window) offset = (window - 1) / 2. if center else 0 diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index fb0e2ad2ca34e..d4e51fbbdb8ca 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -761,6 +761,9 @@ def test_rolling_median(self): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): self._check_moment_func(mom.rolling_median, np.median, name='median') + # GH 12669 + with self.assertRaises(TypeError): + pd.DataFrame(np.arange(10)).rolling(2., center=True).median() def test_rolling_min(self): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): From 56a682d49f795d289c52ada325ae2ab14656d619 Mon Sep 17 00:00:00 2001 From: Prashant Tiwari Date: Tue, 29 Mar 2016 12:08:41 +0100 Subject: [PATCH 2/2] Adding whatsnew entry. --- doc/source/whatsnew/v0.18.1.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.18.1.txt b/doc/source/whatsnew/v0.18.1.txt index e6ea9217347ea..bbbb31ea48ed5 100644 --- a/doc/source/whatsnew/v0.18.1.txt +++ b/doc/source/whatsnew/v0.18.1.txt @@ -169,3 +169,4 @@ Bug Fixes - Bug in ``pivot_table`` when ``margins=True`` and ``dropna=True`` where nulls still contributed to margin count (:issue:`12577`) - Bug in ``Series.name`` when ``name`` attribute can be a hashable type (:issue:`12610`) +- Bug in ``window`` Better error message on invalid window when using .rolling (:issue:`12669`)