@@ -472,6 +472,11 @@ def _concat_datetimetz(to_concat, name=None):
472
472
return to_concat [0 ]._simple_new (new_values , tz = tz , name = name )
473
473
474
474
475
+ def _concat_index_same_dtype (indexes , klass = None ):
476
+ klass = klass if klass is not None else indexes [0 ].__class__
477
+ return klass (np .concatenate ([x ._values for x in indexes ]))
478
+
479
+
475
480
def _concat_index_asobject (to_concat , name = None ):
476
481
"""
477
482
concat all inputs as object. DatetimeIndex, TimedeltaIndex and
@@ -586,16 +591,15 @@ def _concat_rangeindex_same_dtype(indexes):
586
591
elif step is None :
587
592
# First non-empty index had only one element
588
593
if obj ._start == start :
589
- return _concat_index_asobject (indexes )
594
+ from pandas import Int64Index
595
+ return _concat_index_same_dtype (indexes , klass = Int64Index )
590
596
step = obj ._start - start
591
597
592
598
non_consecutive = ((step != obj ._step and len (obj ) > 1 ) or
593
599
(next is not None and obj ._start != next ))
594
600
if non_consecutive :
595
- # Int64Index._append_same_dtype([ix.astype(int) for ix in indexes])
596
- # would be preferred... but it currently resorts to
597
- # _concat_index_asobject anyway.
598
- return _concat_index_asobject (indexes )
601
+ from pandas import Int64Index
602
+ return _concat_index_same_dtype (indexes , klass = Int64Index )
599
603
600
604
if step is not None :
601
605
next = obj [- 1 ] + step
0 commit comments