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

Method _get_formatted_index

pandas/io/formats/format.py:801–840  ·  view source on GitHub ↗
(self, frame: DataFrame)

Source from the content-addressed store, hash-verified

799 return str_columns
800
801 def _get_formatted_index(self, frame: DataFrame) -> list[str]:
802 # Note: this is only used by to_string() and to_latex(), not by
803 # to_html(). so safe to cast col_space here.
804 col_space = {k: cast(int, v) for k, v in self.col_space.items()}
805 index = frame.index
806 columns = frame.columns
807 fmt = self._get_formatter("__index__")
808
809 if isinstance(index, MultiIndex):
810 fmt_index = index._format_multi(
811 sparsify=self.sparsify,
812 include_names=self.show_row_idx_names,
813 formatter=fmt,
814 )
815 else:
816 fmt_index = [
817 index._format_flat(include_name=self.show_row_idx_names, formatter=fmt)
818 ]
819
820 fmt_index = [
821 tuple(
822 _make_fixed_width(
823 list(x), justify="left", minimum=col_space.get("", 0), adj=self.adj
824 )
825 )
826 for x in fmt_index
827 ]
828
829 adjoined = self.adj.adjoin(1, *fmt_index).split("\n")
830
831 # empty space for columns
832 if self.show_col_idx_names:
833 col_header = [str(x) for x in self._get_column_name_list()]
834 else:
835 col_header = [""] * columns.nlevels
836
837 if self.header:
838 return col_header + adjoined
839 else:
840 return adjoined
841
842 def _get_column_name_list(self) -> list[Hashable]:
843 names: list[Hashable] = []

Callers 2

get_strcolsMethod · 0.95

Calls 9

_get_formatterMethod · 0.95
_get_column_name_listMethod · 0.95
_make_fixed_widthFunction · 0.85
_format_multiMethod · 0.80
_format_flatMethod · 0.80
splitMethod · 0.80
adjoinMethod · 0.80
itemsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected