Skip to content

Commit 89f46a5

Browse files
committed
Merge pull request #11622 from kawochen/COMPAT-11108
CLN/COMPAT: Remove raise StopIteration syntax in SparseArray.__iter__
2 parents b54f2db + 3bd8a6b commit 89f46a5

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v0.17.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ API changes
8080
Legacy Python syntax (``set([x, y])``) (:issue:`11215`)
8181
- Indexing with a null key will raise a ``TypeError``, instead of a ``ValueError`` (:issue:`11356`)
8282
- ``Series.sort_index()`` now correctly handles the ``inplace`` option (:issue:`11402`)
83+
- ``SparseArray.__iter__()`` now does not cause ``PendingDeprecationWarning`` in Python 3.5 (:issue:`11622`)
8384

8485
- ``DataFrame.itertuples()`` now returns ``namedtuple`` objects, when possible. (:issue:`11269`)
8586
- ``Series.ptp`` will now ignore missing values by default (:issue:`11163`)

pandas/sparse/array.py

-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def to_dense(self, fill=None):
274274
def __iter__(self):
275275
for i in range(len(self)):
276276
yield self._get_val_at(i)
277-
raise StopIteration
278277

279278
def __getitem__(self, key):
280279
"""

pandas/sparse/tests/test_array.py

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55

66
import operator
7+
import warnings
78

89
from pandas.core.series import Series
910
from pandas.core.common import notnull
@@ -174,6 +175,18 @@ def _check_roundtrip(obj):
174175
_check_roundtrip(self.arr)
175176
_check_roundtrip(self.zarr)
176177

178+
def test_generator_warnings(self):
179+
sp_arr = SparseArray([1, 2, 3])
180+
with warnings.catch_warnings(record=True) as w:
181+
warnings.filterwarnings(action='always',
182+
category=DeprecationWarning)
183+
warnings.filterwarnings(action='always',
184+
category=PendingDeprecationWarning)
185+
for _ in sp_arr:
186+
pass
187+
assert len(w)==0
188+
189+
177190
if __name__ == '__main__':
178191
import nose
179192
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],

0 commit comments

Comments
 (0)