diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 32f7447e5ef77..8d20d7b6b78bd 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -966,6 +966,7 @@ Other API Changes - Constructing a Series from a list of length 1 no longer broadcasts this list when a longer index is specified (:issue:`19714`, :issue:`20391`). - :func:`DataFrame.to_dict` with ``orient='index'`` no longer casts int columns to float for a DataFrame with only int and float columns (:issue:`18580`) - A user-defined-function that is passed to :func:`Series.rolling().aggregate() `, :func:`DataFrame.rolling().aggregate() `, or its expanding cousins, will now *always* be passed a ``Series``, rather than a ``np.array``; ``.apply()`` only has the ``raw`` keyword, see :ref:`here `. This is consistent with the signatures of ``.aggregate()`` across pandas (:issue:`20584`) +- Rolling and Expanding types raise ``NotImplementedError`` upon iteration (:issue:`11704`). .. _whatsnew_0230.deprecations: diff --git a/pandas/core/window.py b/pandas/core/window.py index 5fd054b1930e6..015e7f7913ed0 100644 --- a/pandas/core/window.py +++ b/pandas/core/window.py @@ -181,6 +181,10 @@ def __unicode__(self): return "{klass} [{attrs}]".format(klass=self._window_type, attrs=','.join(attrs)) + def __iter__(self): + url = 'https://github.com/pandas-dev/pandas/issues/11704' + raise NotImplementedError('See issue #11704 {url}'.format(url=url)) + def _get_index(self, index=None): """ Return index as ndarrays diff --git a/pandas/tests/test_window.py b/pandas/tests/test_window.py index 93f637a561718..d8e90ae0e1b35 100644 --- a/pandas/tests/test_window.py +++ b/pandas/tests/test_window.py @@ -512,6 +512,14 @@ def test_multi_index_names(self): tm.assert_index_equal(result.columns, df.columns) assert result.index.names == [None, '1', '2'] + @pytest.mark.parametrize('klass', [pd.Series, pd.DataFrame]) + def test_iter_raises(self, klass): + # https://github.com/pandas-dev/pandas/issues/11704 + # Iteration over a Window + obj = klass([1, 2, 3, 4]) + with pytest.raises(NotImplementedError): + iter(obj.rolling(2)) + class TestExpanding(Base): @@ -590,6 +598,14 @@ def test_missing_minp_zero(self): expected = pd.Series([np.nan]) tm.assert_series_equal(result, expected) + @pytest.mark.parametrize('klass', [pd.Series, pd.DataFrame]) + def test_iter_raises(self, klass): + # https://github.com/pandas-dev/pandas/issues/11704 + # Iteration over a Window + obj = klass([1, 2, 3, 4]) + with pytest.raises(NotImplementedError): + iter(obj.expanding(2)) + class TestEWM(Base):