Skip to content

Commit

Permalink
FIX: define DataFrame.items for all versions of python
Browse files Browse the repository at this point in the history
Closes pandas-dev#17213

This leaves a slight semantic difference between `dict.items` and
`DateFrame.items` in python2, however there is no code currently
expecting `DataFrame.items` to return a list and in python3 there is
no `dict.iteritems`.

This eases writing 'native' python3 code that also runs under python2.
  • Loading branch information
tacaswell committed Aug 19, 2017
1 parent 4e9c0d1 commit 62cfbad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pandas/core/frame.py
Expand Up @@ -802,8 +802,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

def __len__(self):
"""Returns length of info axis, but here we use the index """
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/frame/test_api.py
Expand Up @@ -173,6 +173,11 @@ def test_iteritems(self):
for k, v in compat.iteritems(df):
assert type(v) == self.klass._constructor_sliced

def test_items(self):
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b'])
for k, v in df.items():
assert type(v) == Series

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

Expand Down

0 comments on commit 62cfbad

Please sign in to comment.