File tree 3 files changed +18
-1
lines changed
3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1201,3 +1201,4 @@ Bug Fixes
1201
1201
- Bug when initializing categorical series with a scalar value. (:issue:`12336`)
1202
1202
- Bug when specifying a UTC ``DatetimeIndex`` by setting ``utc=True`` in ``.to_datetime`` (:issue:`11934`)
1203
1203
- Bug when increasing the buffer size of CSV reader in ``read_csv`` (:issue:`12494`)
1204
+ - Bug when setting columns of a ``DataFrame`` with duplicate column names (:issue:`12344`)
Original file line number Diff line number Diff line change @@ -541,7 +541,7 @@ def can_do_equal_len():
541
541
if (len (indexer ) > info_axis and
542
542
is_integer (indexer [info_axis ]) and
543
543
all (is_null_slice (idx ) for i , idx in enumerate (indexer )
544
- if i != info_axis )):
544
+ if i != info_axis ) and item_labels . is_unique ):
545
545
self .obj [item_labels [indexer [info_axis ]]] = value
546
546
return
547
547
Original file line number Diff line number Diff line change @@ -452,3 +452,19 @@ def test_as_matrix_duplicates(self):
452
452
dtype = object )
453
453
454
454
self .assertTrue (np .array_equal (result , expected ))
455
+
456
+ def test_set_value_by_index (self ):
457
+ # See gh-12344
458
+ df = DataFrame (np .arange (9 ).reshape (3 , 3 ).T )
459
+ df .columns = list ('AAA' )
460
+ expected = df .iloc [:, 2 ]
461
+
462
+ df .iloc [:, 0 ] = 3
463
+ assert_series_equal (df .iloc [:, 2 ], expected )
464
+
465
+ df = DataFrame (np .arange (9 ).reshape (3 , 3 ).T )
466
+ df .columns = [2 , float (2 ), str (2 )]
467
+ expected = df .iloc [:, 1 ]
468
+
469
+ df .iloc [:, 0 ] = 3
470
+ assert_series_equal (df .iloc [:, 1 ], expected )
You can’t perform that action at this time.
0 commit comments