Skip to content

Commit 9f54354

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 f165b90 commit 9f54354

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: pandas/core/frame.py

+1-2
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 """

Diff for: pandas/tests/frame/test_api.py

+5
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ def test_iteritems(self):
164164
for k, v in compat.iteritems(df):
165165
assert type(v) == Series
166166

167+
def test_items(self):
168+
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b'])
169+
for k, v in df.items():
170+
assert type(v) == Series
171+
167172
def test_iter(self):
168173
assert tm.equalContents(list(self.frame), self.frame.columns)
169174

0 commit comments

Comments
 (0)