8
8
Any ,
9
9
Callable ,
10
10
Hashable ,
11
+ cast ,
11
12
)
12
13
import warnings
13
14
@@ -110,13 +111,7 @@ def __new__(
110
111
copy : bool = False ,
111
112
name : Hashable = None ,
112
113
) -> RangeIndex :
113
-
114
- # error: Argument 1 to "_validate_dtype" of "NumericIndex" has incompatible type
115
- # "Union[ExtensionDtype, str, dtype[Any], Type[str], Type[float], Type[int],
116
- # Type[complex], Type[bool], Type[object], None]"; expected
117
- # "Union[ExtensionDtype, Union[str, dtype[Any]], Type[str], Type[float],
118
- # Type[int], Type[complex], Type[bool], Type[object]]"
119
- cls ._validate_dtype (dtype ) # type: ignore[arg-type]
114
+ cls ._validate_dtype (dtype )
120
115
name = maybe_extract_name (name , start , cls )
121
116
122
117
# RangeIndex
@@ -159,13 +154,7 @@ def from_range(
159
154
f"{ cls .__name__ } (...) must be called with object coercible to a "
160
155
f"range, { repr (data )} was passed"
161
156
)
162
-
163
- # error: Argument 1 to "_validate_dtype" of "NumericIndex" has incompatible type
164
- # "Union[ExtensionDtype, str, dtype[Any], Type[str], Type[float], Type[int],
165
- # Type[complex], Type[bool], Type[object], None]"; expected
166
- # "Union[ExtensionDtype, Union[str, dtype[Any]], Type[str], Type[float],
167
- # Type[int], Type[complex], Type[bool], Type[object]]"
168
- cls ._validate_dtype (dtype ) # type: ignore[arg-type]
157
+ cls ._validate_dtype (dtype )
169
158
return cls ._simple_new (data , name = name )
170
159
171
160
@classmethod
@@ -440,8 +429,7 @@ def repeat(self, repeats, axis=None) -> Int64Index:
440
429
return self ._int64index .repeat (repeats , axis = axis )
441
430
442
431
def delete (self , loc ) -> Int64Index :
443
- # error: Incompatible return value type (got "Index", expected "Int64Index")
444
- return self ._int64index .delete (loc ) # type: ignore[return-value]
432
+ return self ._int64index .delete (loc )
445
433
446
434
def take (
447
435
self , indices , axis : int = 0 , allow_fill : bool = True , fill_value = None , ** kwargs
@@ -779,11 +767,13 @@ def _concat(self, indexes: list[Index], name: Hashable):
779
767
start = step = next_ = None
780
768
781
769
# Filter the empty indexes
782
- non_empty_indexes = [obj for obj in indexes if len (obj )]
770
+ assert all (isinstance (x , RangeIndex ) for x in indexes )
771
+ non_empty_indexes : list [RangeIndex ] = [
772
+ cast (RangeIndex , obj ) for obj in indexes if len (obj )
773
+ ]
783
774
784
775
for obj in non_empty_indexes :
785
- # error: "Index" has no attribute "_range"
786
- rng : range = obj ._range # type: ignore[attr-defined]
776
+ rng = obj ._range
787
777
788
778
if start is None :
789
779
# This is set by the first non-empty index
@@ -809,14 +799,7 @@ def _concat(self, indexes: list[Index], name: Hashable):
809
799
next_ = rng [- 1 ] + step
810
800
811
801
if non_empty_indexes :
812
- # Get the stop value from "next" or alternatively
813
- # from the last non-empty index
814
- # error: "Index" has no attribute "stop"
815
- stop = (
816
- non_empty_indexes [- 1 ].stop # type: ignore[attr-defined]
817
- if next_ is None
818
- else next_
819
- )
802
+ stop = non_empty_indexes [- 1 ].stop if next_ is None else next_
820
803
return RangeIndex (start , stop , step ).rename (name )
821
804
822
805
# Here all "indexes" had 0 length, i.e. were empty.
0 commit comments