diff --git a/pandas/io/parsers/python_parser.py b/pandas/io/parsers/python_parser.py index 547d8c1fe3d19..993ce4ce051f2 100644 --- a/pandas/io/parsers/python_parser.py +++ b/pandas/io/parsers/python_parser.py @@ -628,39 +628,9 @@ def _infer_columns( this_columns.append(c) if not have_mi_columns: - counts: DefaultDict = defaultdict(int) - # Ensure that regular columns are used before unnamed ones - # to keep given names and mangle unnamed columns - col_loop_order = [ - i - for i in range(len(this_columns)) - if i not in this_unnamed_cols - ] + this_unnamed_cols - - # TODO: Use pandas.io.common.dedup_names instead (see #50371) - for i in col_loop_order: - col = this_columns[i] - old_col = col - cur_count = counts[col] - - if cur_count > 0: - while cur_count > 0: - counts[old_col] = cur_count + 1 - col = f"{old_col}.{cur_count}" - if col in this_columns: - cur_count += 1 - else: - cur_count = counts[col] - - if ( - self.dtype is not None - and is_dict_like(self.dtype) - and self.dtype.get(old_col) is not None - and self.dtype.get(col) is None - ): - self.dtype.update({col: self.dtype.get(old_col)}) - this_columns[i] = col - counts[col] = cur_count + 1 + from pandas.io.common import dedup_names + this_columns = dedup_names(this_columns, is_potential_multiindex=False) + elif have_mi_columns: # if we have grabbed an extra line, but its not in our # format so save in the buffer, and create an blank extra