From 373ab0ff74ae6ca7b09743477fbd5bba2850c8aa Mon Sep 17 00:00:00 2001 From: TomAugspurger Date: Tue, 1 Apr 2014 13:06:08 -0500 Subject: [PATCH] BUG: Series.iteritems should be lazy --- doc/source/release.rst | 2 +- doc/source/v0.14.0.txt | 2 ++ pandas/core/series.py | 2 +- pandas/tests/test_series.py | 3 +++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/source/release.rst b/doc/source/release.rst index 3f3e3e87133a0..79daf09083fc1 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -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 ~~~~~~~~~~~~ diff --git a/doc/source/v0.14.0.txt b/doc/source/v0.14.0.txt index 057f83bff44f2..8ecb6b24083bf 100644 --- a/doc/source/v0.14.0.txt +++ b/doc/source/v0.14.0.txt @@ -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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/pandas/core/series.py b/pandas/core/series.py index 47721ab371c3b..4ab7855ec2f84 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index 95b7b6ace4e2d..3336c3948fac6 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -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)