MCPcopy
hub / github.com/pandas-dev/pandas / _clean_index_names

Method _clean_index_names

pandas/io/parsers/base_parser.py:670–705  ·  view source on GitHub ↗
(self, columns, index_col)

Source from the content-addressed store, hash-verified

668
669 @final
670 def _clean_index_names(self, columns, index_col) -> tuple[list | None, list, list]:
671 if not is_index_col(index_col):
672 return None, columns, index_col
673
674 columns = list(columns)
675
676 # In case of no rows and multiindex columns we have to set index_names to
677 # list of Nones GH#38292
678 if not columns:
679 return [None] * len(index_col), columns, index_col
680
681 cp_cols = list(columns)
682 index_names: list[str | int | None] = []
683
684 # don't mutate
685 index_col = list(index_col)
686
687 for i, c in enumerate(index_col):
688 if isinstance(c, str):
689 index_names.append(c)
690 for j, name in enumerate(cp_cols):
691 if name == c:
692 index_col[i] = j
693 columns.remove(name)
694 break
695 else:
696 name = cp_cols[c]
697 columns.remove(name)
698 index_names.append(name)
699
700 # Only clean index names that were placeholders.
701 for i, name in enumerate(index_names):
702 if isinstance(name, str) and name in self.unnamed_cols:
703 index_names[i] = None
704
705 return index_names, columns, index_col
706
707 @final
708 def _get_empty_meta(

Callers 3

__init__Method · 0.80
_get_index_nameMethod · 0.80

Calls 3

is_index_colFunction · 0.85
appendMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected