Skip to content

Commit b204e14

Browse files
committed
Merge pull request #3879 from cpcloud/itertuples-bug-3873
BUG: allow itertuples to work with frames with duplicate column names
2 parents 51cc9d9 + e7addae commit b204e14

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

RELEASE.rst

+3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ pandas 0.11.1
223223
- ``read_html`` now correctly skips tests (GH3741_)
224224
- Fix incorrect arguments passed to concat that are not list-like (e.g. concat(df1,df2)) (GH3481_)
225225
- Correctly parse when passed the ``dtype=str`` (or other variable-len string dtypes) in ``read_csv`` (GH3795_)
226+
- ``DataFrame.itertuples()`` now works with frames with duplicate column
227+
names (GH3873_)
226228

227229
.. _GH3164: https://github.com/pydata/pandas/issues/3164
228230
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -314,6 +316,7 @@ pandas 0.11.1
314316
.. _GH3795: https://github.com/pydata/pandas/issues/3795
315317
.. _GH3814: https://github.com/pydata/pandas/issues/3814
316318
.. _GH3834: https://github.com/pydata/pandas/issues/3834
319+
.. _GH3873: https://github.com/pydata/pandas/issues/3873
317320

318321

319322
pandas 0.11.0

doc/source/v0.11.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ Bug Fixes
349349

350350
- ``DataFrame.from_records`` did not accept empty recarrays (GH3682_)
351351
- ``read_html`` now correctly skips tests (GH3741_)
352+
- ``DataFrame.itertuples()`` now works with frames with duplicate column
353+
names (GH3873_)
352354

353355
See the `full release notes
354356
<https://github.com/pydata/pandas/blob/master/RELEASE.rst>`__ or issue tracker
@@ -399,3 +401,4 @@ on GitHub for a complete list.
399401
.. _GH3726: https://github.com/pydata/pandas/issues/3726
400402
.. _GH3425: https://github.com/pydata/pandas/issues/3425
401403
.. _GH3834: https://github.com/pydata/pandas/issues/3834
404+
.. _GH3873: https://github.com/pydata/pandas/issues/3873

pandas/core/frame.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,9 @@ def itertuples(self, index=True):
818818
arrays = []
819819
if index:
820820
arrays.append(self.index)
821-
arrays.extend(self[k] for k in self.columns)
821+
822+
# use integer indexing because of possible duplicate column names
823+
arrays.extend(self.iloc[:, k] for k in xrange(len(self.columns)))
822824
return izip(*arrays)
823825

824826
iterkv = iteritems

pandas/tests/test_frame.py

+4
Original file line numberDiff line numberDiff line change
@@ -3951,6 +3951,10 @@ def test_itertuples(self):
39513951
for tup in df.itertuples(index=False):
39523952
self.assert_(isinstance(tup[1], np.integer))
39533953

3954+
df = DataFrame(data={"a": [1, 2, 3], "b": [4, 5, 6]})
3955+
dfaa = df[['a', 'a']]
3956+
self.assertEqual(list(dfaa.itertuples()), [(0, 1, 1), (1, 2, 2), (2, 3, 3)])
3957+
39543958
def test_len(self):
39553959
self.assertEqual(len(self.frame), len(self.frame.index))
39563960

0 commit comments

Comments
 (0)