Skip to content

Commit

Permalink
Merge pull request #6761 from TomAugspurger/lazy-iteritems
Browse files Browse the repository at this point in the history
BUG: Series.iteritems should be lazy
  • Loading branch information
Tom Augspurger committed Apr 1, 2014
2 parents 95a562c + 373ab0f commit 772b13a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ API Changes
- ``DataFrame.sort`` now places NaNs at the beginning or end of the sort according to the ``na_position`` parameter. (:issue:`3917`)

- all offset operations now return ``Timestamp`` types (rather than datetime), Business/Week frequencies were incorrect (:issue:`4069`)

- ``Series.iteritems()`` is now lazy (returns an iterator rather than a list). This was the documented behavior prior to 0.14. (:issue:`6760`)

Deprecations
~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ API changes
covs = rolling_cov(df[['A','B','C']], df[['B','C','D']], 5, pairwise=True)
covs[df.index[-1]]

- ``Series.iteritems()`` is now lazy (returns an iterator rather than a list). This was the documented behavior prior to 0.14. (:issue:`6760`)


MultiIndexing Using Slicers
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ def iteritems(self):
"""
Lazily iterate over (index, value) tuples
"""
return lzip(iter(self.index), iter(self))
return zip(iter(self.index), iter(self))

if compat.PY3: # pragma: no cover
items = iteritems
Expand Down
3 changes: 3 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,9 @@ def test_iteritems(self):
for idx, val in compat.iteritems(self.ts):
self.assertEqual(val, self.ts[idx])

# assert is lazy (genrators don't define __getslice__, lists do)
self.assertFalse(hasattr(self.series.iteritems(), '__getslice__'))

def test_sum(self):
self._check_stat_op('sum', np.sum)

Expand Down

0 comments on commit 772b13a

Please sign in to comment.