|
10 | 10 | TYPE_CHECKING,
|
11 | 11 | Any,
|
12 | 12 | Callable,
|
13 |
| - DefaultDict, |
14 | 13 | Hashable,
|
15 | 14 | Iterable,
|
16 | 15 | List,
|
|
89 | 88 | from pandas.core.series import Series
|
90 | 89 | from pandas.core.tools import datetimes as tools
|
91 | 90 |
|
| 91 | +from pandas.io.common import is_potential_multi_index |
| 92 | + |
92 | 93 | if TYPE_CHECKING:
|
93 | 94 | from pandas import DataFrame
|
94 | 95 |
|
@@ -333,39 +334,14 @@ def extract(r):
|
333 | 334 |
|
334 | 335 | return names, index_names, col_names, passed_names
|
335 | 336 |
|
336 |
| - @final |
337 |
| - def _dedup_names(self, names: Sequence[Hashable]) -> Sequence[Hashable]: |
338 |
| - names = list(names) # so we can index |
339 |
| - counts: DefaultDict[Hashable, int] = defaultdict(int) |
340 |
| - is_potential_mi = _is_potential_multi_index(names, self.index_col) |
341 |
| - |
342 |
| - for i, col in enumerate(names): |
343 |
| - cur_count = counts[col] |
344 |
| - |
345 |
| - while cur_count > 0: |
346 |
| - counts[col] = cur_count + 1 |
347 |
| - |
348 |
| - if is_potential_mi: |
349 |
| - # for mypy |
350 |
| - assert isinstance(col, tuple) |
351 |
| - col = col[:-1] + (f"{col[-1]}.{cur_count}",) |
352 |
| - else: |
353 |
| - col = f"{col}.{cur_count}" |
354 |
| - cur_count = counts[col] |
355 |
| - |
356 |
| - names[i] = col |
357 |
| - counts[col] = cur_count + 1 |
358 |
| - |
359 |
| - return names |
360 |
| - |
361 | 337 | @final
|
362 | 338 | def _maybe_make_multi_index_columns(
|
363 | 339 | self,
|
364 | 340 | columns: Sequence[Hashable],
|
365 | 341 | col_names: Sequence[Hashable] | None = None,
|
366 | 342 | ) -> Sequence[Hashable] | MultiIndex:
|
367 | 343 | # possibly create a column mi here
|
368 |
| - if _is_potential_multi_index(columns): |
| 344 | + if is_potential_multi_index(columns): |
369 | 345 | list_columns = cast(List[Tuple], columns)
|
370 | 346 | return MultiIndex.from_tuples(list_columns, names=col_names)
|
371 | 347 | return columns
|
@@ -1326,35 +1302,6 @@ def _get_na_values(col, na_values, na_fvalues, keep_default_na):
|
1326 | 1302 | return na_values, na_fvalues
|
1327 | 1303 |
|
1328 | 1304 |
|
1329 |
| -def _is_potential_multi_index( |
1330 |
| - columns: Sequence[Hashable] | MultiIndex, |
1331 |
| - index_col: bool | Sequence[int] | None = None, |
1332 |
| -) -> bool: |
1333 |
| - """ |
1334 |
| - Check whether or not the `columns` parameter |
1335 |
| - could be converted into a MultiIndex. |
1336 |
| -
|
1337 |
| - Parameters |
1338 |
| - ---------- |
1339 |
| - columns : array-like |
1340 |
| - Object which may or may not be convertible into a MultiIndex |
1341 |
| - index_col : None, bool or list, optional |
1342 |
| - Column or columns to use as the (possibly hierarchical) index |
1343 |
| -
|
1344 |
| - Returns |
1345 |
| - ------- |
1346 |
| - bool : Whether or not columns could become a MultiIndex |
1347 |
| - """ |
1348 |
| - if index_col is None or isinstance(index_col, bool): |
1349 |
| - index_col = [] |
1350 |
| - |
1351 |
| - return bool( |
1352 |
| - len(columns) |
1353 |
| - and not isinstance(columns, MultiIndex) |
1354 |
| - and all(isinstance(c, tuple) for c in columns if c not in list(index_col)) |
1355 |
| - ) |
1356 |
| - |
1357 |
| - |
1358 | 1305 | def _validate_parse_dates_arg(parse_dates):
|
1359 | 1306 | """
|
1360 | 1307 | Check whether or not the 'parse_dates' parameter
|
|
0 commit comments