Skip to content

Commit 6c34f6b

Browse files
committed
FIX: support lazy items on Series in all versions of python
1 parent 32aa089 commit 6c34f6b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

doc/source/whatsnew/v0.21.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ Other Enhancements
128128
- :func:`DataFrame.add_prefix` and :func:`DataFrame.add_suffix` now accept strings containing the '%' character. (:issue:`17151`)
129129
- `read_*` methods can now infer compression from non-string paths, such as ``pathlib.Path`` objects (:issue:`17206`).
130130
- :func:`pd.read_sas()` now recognizes much more of the most frequently used date (datetime) formats in SAS7BDAT files (:issue:`15871`).
131-
- :func:`DataFrame.items` is now present in both Python 2 and 3 and is lazy in all cases (:issue:`13918`, :issue:`17213`)
131+
- :func:`DataFrame.items` and :func:`Serise.items` is now present in both Python 2 and 3 and is lazy in all cases (:issue:`13918`, :issue:`17213`)
132+
132133

133134

134135

pandas/core/series.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,7 @@ def iteritems(self):
11101110
"""
11111111
return zip(iter(self.index), iter(self))
11121112

1113-
if compat.PY3: # pragma: no cover
1114-
items = iteritems
1113+
items = iteritems
11151114

11161115
# ----------------------------------------------------------------------
11171116
# Misc public methods

pandas/tests/series/test_api.py

+10
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ def test_iteritems(self):
301301
# assert is lazy (genrators don't define reverse, lists do)
302302
assert not hasattr(self.series.iteritems(), 'reverse')
303303

304+
def test_items(self):
305+
for idx, val in self.series.items():
306+
assert val == self.series[idx]
307+
308+
for idx, val in self.ts.items():
309+
assert val == self.ts[idx]
310+
311+
# assert is lazy (genrators don't define reverse, lists do)
312+
assert not hasattr(self.series.items(), 'reverse')
313+
304314
def test_raise_on_info(self):
305315
s = Series(np.random.randn(10))
306316
with pytest.raises(AttributeError):

0 commit comments

Comments
 (0)