27
27
import pandas .core .common as com
28
28
from pandas .core .construction import extract_array
29
29
import pandas .core .indexes .base as ibase
30
- from pandas .core .indexes .base import Index , _index_shared_docs , maybe_extract_name
30
+ from pandas .core .indexes .base import _index_shared_docs , maybe_extract_name
31
31
from pandas .core .indexes .numeric import Int64Index
32
32
from pandas .core .ops .common import unpack_zerodim_and_defer
33
33
34
34
from pandas .io .formats .printing import pprint_thing
35
35
36
+ _empty_range = range (0 )
37
+
36
38
37
39
class RangeIndex (Int64Index ):
38
40
"""
@@ -130,15 +132,10 @@ def from_range(cls, data, name=None, dtype=None):
130
132
return cls ._simple_new (data , dtype = dtype , name = name )
131
133
132
134
@classmethod
133
- def _simple_new (cls , values , name = None , dtype = None ):
135
+ def _simple_new (cls , values : range , name = None , dtype = None ) -> "RangeIndex" :
134
136
result = object .__new__ (cls )
135
137
136
- # handle passed None, non-integers
137
- if values is None :
138
- # empty
139
- values = range (0 , 0 , 1 )
140
- elif not isinstance (values , range ):
141
- return Index (values , dtype = dtype , name = name )
138
+ assert isinstance (values , range )
142
139
143
140
result ._range = values
144
141
result .name = name
@@ -482,7 +479,7 @@ def intersection(self, other, sort=False):
482
479
return super ().intersection (other , sort = sort )
483
480
484
481
if not len (self ) or not len (other ):
485
- return self ._simple_new (None )
482
+ return self ._simple_new (_empty_range )
486
483
487
484
first = self ._range [::- 1 ] if self .step < 0 else self ._range
488
485
second = other ._range [::- 1 ] if other .step < 0 else other ._range
@@ -492,7 +489,7 @@ def intersection(self, other, sort=False):
492
489
int_low = max (first .start , second .start )
493
490
int_high = min (first .stop , second .stop )
494
491
if int_high <= int_low :
495
- return self ._simple_new (None )
492
+ return self ._simple_new (_empty_range )
496
493
497
494
# Method hint: linear Diophantine equation
498
495
# solve intersection problem
@@ -502,7 +499,7 @@ def intersection(self, other, sort=False):
502
499
503
500
# check whether element sets intersect
504
501
if (first .start - second .start ) % gcd :
505
- return self ._simple_new (None )
502
+ return self ._simple_new (_empty_range )
506
503
507
504
# calculate parameters for the RangeIndex describing the
508
505
# intersection disregarding the lower bounds
0 commit comments