Skip to content

Commit 8662176

Browse files
committed
BUG: DataFrame constructor list of lists with duplicated columns
1 parent 5c945e1 commit 8662176

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

pandas/core/frame.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,7 @@ def _arith_op(left, right):
33183318

33193319
if this._is_mixed_type or other._is_mixed_type:
33203320
# XXX no good for duplicate columns
3321+
# but cannot outer join in align if dups anyways?
33213322
result = {}
33223323
for col in this:
33233324
result[col] = _arith_op(this[col].values, other[col].values)

pandas/core/internals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,8 @@ def _shape_compat(x):
13251325
names, arrays = zip(*tuples)
13261326

13271327
# index may box values
1328-
items = ref_items[ref_items.isin(names)]
1328+
names = Index(names)
1329+
items = names[names.isin(ref_items)]
13291330

13301331
first = arrays[0]
13311332
shape = (len(arrays),) + _shape_compat(first)

pandas/tests/test_frame.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,13 @@ def test_constructor_column_duplicates(self):
23192319
[('a',[8]),('a',[5]), ('b', [6])],
23202320
columns=['b', 'a','a'])
23212321

2322+
#additional test for #2079
2323+
vals = [[1, -1, 2.], [2, -2, 3.]]
2324+
rs = DataFrame(vals, columns=['A', 'A', 'B'])
2325+
xp = DataFrame(vals)
2326+
xp.columns = ['A', 'A', 'B']
2327+
assert_frame_equal(rs, xp)
2328+
23222329
def test_new_empty_index(self):
23232330
df1 = DataFrame(randn(0, 3))
23242331
df2 = DataFrame(randn(0, 3))

0 commit comments

Comments
 (0)