Try several cases to get lines: 0) There are headers on row 0 and row 1 and their total summed lengths equals the length of the next line. Treat row 0 as columns and row 1 as indices 1) Look for implicit index: there are more columns on row 1 than ro
(
self,
)
| 1102 | ) |
| 1103 | |
| 1104 | def _get_index_name( |
| 1105 | self, |
| 1106 | ) -> tuple[Sequence[Hashable] | None, list[Hashable], list[Hashable]]: |
| 1107 | """ |
| 1108 | Try several cases to get lines: |
| 1109 | |
| 1110 | 0) There are headers on row 0 and row 1 and their |
| 1111 | total summed lengths equals the length of the next line. |
| 1112 | Treat row 0 as columns and row 1 as indices |
| 1113 | 1) Look for implicit index: there are more columns |
| 1114 | on row 1 than row 0. If this is true, assume that row |
| 1115 | 1 lists index columns and row 0 lists normal columns. |
| 1116 | 2) Get index from the columns if it was listed. |
| 1117 | """ |
| 1118 | columns: Sequence[Hashable] = self.orig_names |
| 1119 | orig_names = list(columns) |
| 1120 | columns = list(columns) |
| 1121 | |
| 1122 | line: list[Scalar] | None |
| 1123 | if self._header_line is not None: |
| 1124 | line = self._header_line |
| 1125 | else: |
| 1126 | try: |
| 1127 | line = self._next_line() |
| 1128 | except StopIteration: |
| 1129 | line = None |
| 1130 | |
| 1131 | next_line: list[Scalar] | None |
| 1132 | try: |
| 1133 | next_line = self._next_line() |
| 1134 | except StopIteration: |
| 1135 | next_line = None |
| 1136 | |
| 1137 | # implicitly index_col=0 b/c 1 fewer column names |
| 1138 | implicit_first_cols = 0 |
| 1139 | if line is not None: |
| 1140 | # leave it 0, #2442 |
| 1141 | # Case 1 |
| 1142 | index_col = self.index_col |
| 1143 | if index_col is not False: |
| 1144 | implicit_first_cols = len(line) - self.num_original_columns |
| 1145 | |
| 1146 | # Case 0 |
| 1147 | if ( |
| 1148 | next_line is not None |
| 1149 | and self.header is not None |
| 1150 | and index_col is not False |
| 1151 | ): |
| 1152 | if len(next_line) == len(line) + self.num_original_columns: |
| 1153 | # column and index names on diff rows |
| 1154 | self.index_col = list(range(len(line))) |
| 1155 | self.buf = self.buf[1:] |
| 1156 | |
| 1157 | for c in reversed(line): |
| 1158 | columns.insert(0, c) |
| 1159 | |
| 1160 | # Update list of original names to include all indices. |
| 1161 | orig_names = list(columns) |
no test coverage detected