Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed compat check for Series.items method #13920

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.17.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ API changes
result in ``NaT`` and not ``nan`` (:issue:`11245`).
- Indexing with a null key will raise a ``TypeError``, instead of a ``ValueError`` (:issue:`11356`)
- ``Series.ptp`` will now ignore missing values by default (:issue:`11163`)
- ``Series`` and ``DataFrame`` have gained the .items() method to mirror .iteritems() and for compat with PY3 (:issue:`13918`)

.. _whatsnew_0171.deprecations:

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,7 @@ def itertuples(self, index=True, name="Pandas"):
# fallback to regular tuples
return zip(*arrays)

if compat.PY3: # pragma: no cover
items = iteritems
items = iteritems
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here


def __len__(self):
"""Returns length of info axis, but here we use the index """
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,7 @@ def iteritems(self):
"""
return zip(iter(self.index), iter(self))

if compat.PY3: # pragma: no cover
items = iteritems
items = iteritems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @shoyer is right here,; I think this will work if you do

items=compat.iteritems which already has the correct PY2 (and 3) behavior

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think compa.iteritems just calls the object's iteritems method, so that would not make a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think @jorisvandenbossche is right - see my new comment.

# ----------------------------------------------------------------------
# Misc public methods
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/test_misc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ def test_iteritems(self):
for k, v in compat.iteritems(df):
self.assertEqual(type(v), Series)

def test_items(self):
# items is the same as iteritems (#13918)
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b'])
for k, v in df.items():
self.assertEqual(type(v), Series)

def test_iter(self):
self.assertTrue(tm.equalContents(list(self.frame), self.frame.columns))

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/series/test_misc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ def test_iteritems(self):
# assert is lazy (genrators don't define reverse, lists do)
self.assertFalse(hasattr(self.series.iteritems(), 'reverse'))

def test_items(self):
# items is the same as iteritems (#13918)
for idx, val in self.series.items():
self.assertEqual(val, self.series[idx])

for idx, val in self.ts.items():
self.assertEqual(val, self.ts[idx])

self.assertFalse(hasattr(self.series.items(), 'reverse'))

def test_raise_on_info(self):
s = Series(np.random.randn(10))
with tm.assertRaises(AttributeError):
Expand Down