|
20 | 20 | is_timedelta64_dtype, |
21 | 21 | ) |
22 | 22 | from pandas.core.dtypes.generic import ( |
| 23 | + ABCCategoricalIndex, |
23 | 24 | ABCDatetimeArray, |
24 | | - ABCDatetimeIndex, |
25 | 25 | ABCIndexClass, |
26 | | - ABCPeriodIndex, |
27 | 26 | ABCRangeIndex, |
28 | | - ABCTimedeltaIndex, |
| 27 | + ABCSeries, |
29 | 28 | ) |
30 | 29 |
|
31 | 30 |
|
@@ -285,14 +284,14 @@ def union_categoricals(to_union, sort_categories=False, ignore_order=False): |
285 | 284 | [b, c, a, b] |
286 | 285 | Categories (3, object): [b, c, a] |
287 | 286 | """ |
288 | | - from pandas import Index, Categorical, CategoricalIndex, Series |
| 287 | + from pandas import Index, Categorical |
289 | 288 | from pandas.core.arrays.categorical import _recode_for_categories |
290 | 289 |
|
291 | 290 | if len(to_union) == 0: |
292 | 291 | raise ValueError("No Categoricals to union") |
293 | 292 |
|
294 | 293 | def _maybe_unwrap(x): |
295 | | - if isinstance(x, (CategoricalIndex, Series)): |
| 294 | + if isinstance(x, (ABCCategoricalIndex, ABCSeries)): |
296 | 295 | return x.values |
297 | 296 | elif isinstance(x, Categorical): |
298 | 297 | return x |
@@ -450,31 +449,6 @@ def _concat_datetimetz(to_concat, name=None): |
450 | 449 | return sample._concat_same_type(to_concat) |
451 | 450 |
|
452 | 451 |
|
453 | | -def _concat_index_same_dtype(indexes, klass=None): |
454 | | - klass = klass if klass is not None else indexes[0].__class__ |
455 | | - return klass(np.concatenate([x._values for x in indexes])) |
456 | | - |
457 | | - |
458 | | -def _concat_index_asobject(to_concat, name=None): |
459 | | - """ |
460 | | - concat all inputs as object. DatetimeIndex, TimedeltaIndex and |
461 | | - PeriodIndex are converted to object dtype before concatenation |
462 | | - """ |
463 | | - from pandas import Index |
464 | | - from pandas.core.arrays import ExtensionArray |
465 | | - |
466 | | - klasses = (ABCDatetimeIndex, ABCTimedeltaIndex, ABCPeriodIndex, ExtensionArray) |
467 | | - to_concat = [x.astype(object) if isinstance(x, klasses) else x for x in to_concat] |
468 | | - |
469 | | - self = to_concat[0] |
470 | | - attribs = self._get_attributes_dict() |
471 | | - attribs["name"] = name |
472 | | - |
473 | | - to_concat = [x._values if isinstance(x, Index) else x for x in to_concat] |
474 | | - |
475 | | - return self._shallow_copy_with_infer(np.concatenate(to_concat), **attribs) |
476 | | - |
477 | | - |
478 | 452 | def _concat_sparse(to_concat, axis=0, typs=None): |
479 | 453 | """ |
480 | 454 | provide concatenation of an sparse/dense array of arrays each of which is a |
@@ -505,52 +479,3 @@ def _concat_sparse(to_concat, axis=0, typs=None): |
505 | 479 | ] |
506 | 480 |
|
507 | 481 | return SparseArray._concat_same_type(to_concat) |
508 | | - |
509 | | - |
510 | | -def _concat_rangeindex_same_dtype(indexes): |
511 | | - """ |
512 | | - Concatenates multiple RangeIndex instances. All members of "indexes" must |
513 | | - be of type RangeIndex; result will be RangeIndex if possible, Int64Index |
514 | | - otherwise. E.g.: |
515 | | - indexes = [RangeIndex(3), RangeIndex(3, 6)] -> RangeIndex(6) |
516 | | - indexes = [RangeIndex(3), RangeIndex(4, 6)] -> Int64Index([0,1,2,4,5]) |
517 | | - """ |
518 | | - from pandas import Int64Index, RangeIndex |
519 | | - |
520 | | - start = step = next_ = None |
521 | | - |
522 | | - # Filter the empty indexes |
523 | | - non_empty_indexes = [obj for obj in indexes if len(obj)] |
524 | | - |
525 | | - for obj in non_empty_indexes: |
526 | | - rng = obj._range # type: range |
527 | | - |
528 | | - if start is None: |
529 | | - # This is set by the first non-empty index |
530 | | - start = rng.start |
531 | | - if step is None and len(rng) > 1: |
532 | | - step = rng.step |
533 | | - elif step is None: |
534 | | - # First non-empty index had only one element |
535 | | - if rng.start == start: |
536 | | - return _concat_index_same_dtype(indexes, klass=Int64Index) |
537 | | - step = rng.start - start |
538 | | - |
539 | | - non_consecutive = (step != rng.step and len(rng) > 1) or ( |
540 | | - next_ is not None and rng.start != next_ |
541 | | - ) |
542 | | - if non_consecutive: |
543 | | - return _concat_index_same_dtype(indexes, klass=Int64Index) |
544 | | - |
545 | | - if step is not None: |
546 | | - next_ = rng[-1] + step |
547 | | - |
548 | | - if non_empty_indexes: |
549 | | - # Get the stop value from "next" or alternatively |
550 | | - # from the last non-empty index |
551 | | - stop = non_empty_indexes[-1].stop if next_ is None else next_ |
552 | | - return RangeIndex(start, stop, step) |
553 | | - |
554 | | - # Here all "indexes" had 0 length, i.e. were empty. |
555 | | - # In this case return an empty range index. |
556 | | - return RangeIndex(0, 0) |
0 commit comments