Skip to content

Commit 012a88b

Browse files
committed
REF: move _concat_indexes to pandas.core.dtypes.concat
1 parent 5d734ad commit 012a88b

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

pandas/core/dtypes/concat.py

+27
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,30 @@ def convert_sparse(x, axis):
491491
# coerce to object if needed
492492
result = result.astype('object')
493493
return result
494+
495+
496+
def _concat_indexes(to_concat, default=None):
497+
"""
498+
Concatenate elements of to_concat to single Index
499+
500+
Parameters
501+
----------
502+
to_concat : list-like of indexes
503+
default : Index subclass to use if "to_concat" is empty, or None
504+
505+
Returns
506+
-------
507+
a single index, preserving the combined dtypes
508+
"""
509+
510+
if len(to_concat) == 0:
511+
if default is None:
512+
raise ValueError("_concat_indexes called with empty \"to_concat\" "
513+
"and default=None")
514+
return default([])
515+
516+
typs = get_dtype_kinds(to_concat)
517+
if len(typs) == 1:
518+
return to_concat[0].__class__._concat_same_dtype(to_concat)
519+
else:
520+
return _concat_index_asobject(to_concat)

pandas/core/indexes/base.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1686,15 +1686,11 @@ def append(self, other):
16861686
return res
16871687

16881688
@classmethod
1689-
def _concat(self, to_concat):
1689+
def _concat(cls, to_concat):
16901690
"""
16911691
Concatenate to_concat to single Index
16921692
"""
1693-
typs = _concat.get_dtype_kinds(to_concat)
1694-
if len(typs) == 1:
1695-
return self._concat_same_dtype(to_concat)
1696-
else:
1697-
return _concat._concat_index_asobject(to_concat)
1693+
return _concat._concat_indexes(to_concat, default=cls)
16981694

16991695
@classmethod
17001696
def _concat_same_dtype(cls, to_concat):

0 commit comments

Comments
 (0)