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