Skip to content

Commit 43edd83

Browse files
yoongkangjreback
authored andcommitted
BUG: Fixed DataFrame info() for duplicated columns, #11761
1 parent 111380f commit 43edd83

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ Bug Fixes
169169

170170
- Bug in ``Timedelta.round`` with negative values (:issue:`11690`)
171171
- Bug in ``.loc`` against ``CategoricalIndex`` may result in normal ``Index`` (:issue:`11586`)
172+
- Bug in ``DataFrame.info`` when duplicated column names exist (:issue:`11761`)
172173

173174

174175

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ def _verbose_repr():
16551655

16561656
dtypes = self.dtypes
16571657
for i, col in enumerate(self.columns):
1658-
dtype = dtypes[col]
1658+
dtype = dtypes.iloc[i]
16591659
col = com.pprint_thing(col)
16601660

16611661
count = ""

pandas/tests/test_frame.py

+12
Original file line numberDiff line numberDiff line change
@@ -7559,6 +7559,18 @@ def test_info_duplicate_columns(self):
75597559
columns=['a', 'a', 'b', 'b'])
75607560
frame.info(buf=io)
75617561

7562+
def test_info_duplicate_columns_shows_correct_dtypes(self):
7563+
# GH11761
7564+
io = StringIO()
7565+
7566+
frame = DataFrame([[1, 2.0]],
7567+
columns=['a', 'a'])
7568+
frame.info(buf=io)
7569+
io.seek(0)
7570+
lines = io.readlines()
7571+
self.assertEqual('a 1 non-null int64\n', lines[3])
7572+
self.assertEqual('a 1 non-null float64\n', lines[4])
7573+
75627574
def test_info_shows_column_dtypes(self):
75637575
dtypes = ['int64', 'float64', 'datetime64[ns]', 'timedelta64[ns]',
75647576
'complex128', 'object', 'bool']

0 commit comments

Comments
 (0)