diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index 62cec66cc22b0..d9bcbbf3d6c51 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -58,6 +58,7 @@ API changes Legacy Python syntax (``set([x, y])``) (:issue:`11215`) - Indexing with a null key will raise a ``TypeError``, instead of a ``ValueError`` (:issue:`11356`) - ``Series.sort_index()`` now correctly handles the ``inplace`` option (:issue:`11402`) +- ``SparseArray.__iter__()`` now does not cause ``PendingDeprecationWarning`` in Python 3.5 (:issue:`11622`) - ``DataFrame.itertuples()`` now returns ``namedtuple`` objects, when possible. (:issue:`11269`) - ``Series.ptp`` will now ignore missing values by default (:issue:`11163`) diff --git a/pandas/sparse/array.py b/pandas/sparse/array.py index f275a34ca90db..b40a23fb4556a 100644 --- a/pandas/sparse/array.py +++ b/pandas/sparse/array.py @@ -274,7 +274,6 @@ def to_dense(self, fill=None): def __iter__(self): for i in range(len(self)): yield self._get_val_at(i) - raise StopIteration def __getitem__(self, key): """ diff --git a/pandas/sparse/tests/test_array.py b/pandas/sparse/tests/test_array.py index 4ffc0b98ebc71..add680489548d 100644 --- a/pandas/sparse/tests/test_array.py +++ b/pandas/sparse/tests/test_array.py @@ -4,6 +4,7 @@ import numpy as np import operator +import warnings from pandas.core.series import Series from pandas.core.common import notnull @@ -174,6 +175,18 @@ def _check_roundtrip(obj): _check_roundtrip(self.arr) _check_roundtrip(self.zarr) + def test_generator_warnings(self): + sp_arr = SparseArray([1, 2, 3]) + with warnings.catch_warnings(record=True) as w: + warnings.filterwarnings(action='always', + category=DeprecationWarning) + warnings.filterwarnings(action='always', + category=PendingDeprecationWarning) + for _ in sp_arr: + pass + assert len(w)==0 + + if __name__ == '__main__': import nose nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],