194194 nargsort ,
195195)
196196
197- from pandas .io .common import get_handle
197+ from pandas .io .common import (
198+ dedup_names ,
199+ get_handle ,
200+ )
198201from pandas .io .formats import (
199202 console ,
200203 format as fmt ,
@@ -9026,7 +9029,7 @@ def combine(
90269029 2 NaN 3.0 1.0
90279030 """
90289031 other_idxlen = len (other .index ) # save for compare
9029- other_columns = other .columns
9032+ self_columns , other_columns = self . columns , other .columns
90309033
90319034 this , other = self .align (other )
90329035 new_index = this .index
@@ -9037,19 +9040,17 @@ def combine(
90379040 if self .empty and len (other ) == other_idxlen :
90389041 return other .copy ()
90399042
9040- def rename_duplicates (columns : Index ) -> Index :
9041- seen = {}
9042- for col in columns :
9043- if col in seen :
9044- col = col + f".{ seen [col ]} "
9045- seen [col ] = seen .get (col , 0 ) + 1
9046- return columns
9047-
90489043 new_columns_out = self .columns .union (other_columns , sort = False )
9049- self_columns , other_columns = (
9050- rename_duplicates (self .columns ),
9051- rename_duplicates (other_columns ),
9044+ # Deduplicate column names if necessary
9045+ self_columns = Index (dedup_names (self_columns , False ), dtype = self_columns .dtype )
9046+ other_columns = Index (
9047+ dedup_names (other_columns , False ), dtype = other_columns .dtype
90529048 )
9049+ this .columns = Index (dedup_names (this .columns , False ), dtype = this .columns .dtype )
9050+ other .columns = Index (
9051+ dedup_names (other .columns , False ), dtype = other .columns .dtype
9052+ )
9053+
90539054 # preserve column order
90549055 new_columns_unique = self_columns .union (other_columns , sort = False )
90559056 do_fill = fill_value is not None
0 commit comments