Skip to content

Commit 62cfbad

Browse files
committed
FIX: define DataFrame.items for all versions of python
Closes #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.
1 parent 4e9c0d1 commit 62cfbad

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,7 @@ def itertuples(self, index=True, name="Pandas"):
802802
# fallback to regular tuples
803803
return zip(*arrays)
804804

805-
if compat.PY3: # pragma: no cover
806-
items = iteritems
805+
items = iteritems
807806

808807
def __len__(self):
809808
"""Returns length of info axis, but here we use the index """

pandas/tests/frame/test_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ def test_iteritems(self):
173173
for k, v in compat.iteritems(df):
174174
assert type(v) == self.klass._constructor_sliced
175175

176+
def test_items(self):
177+
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b'])
178+
for k, v in df.items():
179+
assert type(v) == Series
180+
176181
def test_iter(self):
177182
assert tm.equalContents(list(self.frame), self.frame.columns)
178183

0 commit comments

Comments
 (0)