8
8
Any ,
9
9
Callable ,
10
10
Hashable ,
11
+ List ,
12
+ cast ,
11
13
)
12
14
import warnings
13
15
@@ -110,13 +112,7 @@ def __new__(
110
112
copy : bool = False ,
111
113
name : Hashable = None ,
112
114
) -> 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]
115
+ cls ._validate_dtype (dtype )
120
116
name = maybe_extract_name (name , start , cls )
121
117
122
118
# RangeIndex
@@ -159,13 +155,7 @@ def from_range(
159
155
f"{ cls .__name__ } (...) must be called with object coercible to a "
160
156
f"range, { repr (data )} was passed"
161
157
)
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]
158
+ cls ._validate_dtype (dtype )
169
159
return cls ._simple_new (data , name = name )
170
160
171
161
@classmethod
@@ -439,9 +429,8 @@ def _get_indexer(
439
429
def repeat (self , repeats , axis = None ) -> Int64Index :
440
430
return self ._int64index .repeat (repeats , axis = axis )
441
431
442
- 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
+ def delete (self , loc ) -> Int64Index : # type: ignore[override]
433
+ return self ._int64index .delete (loc )
445
434
446
435
def take (
447
436
self , indices , axis : int = 0 , allow_fill : bool = True , fill_value = None , ** kwargs
@@ -761,7 +750,7 @@ def symmetric_difference(self, other, result_name: Hashable = None, sort=None):
761
750
762
751
# --------------------------------------------------------------------
763
752
764
- def _concat (self , indexes : list [Index ], name : Hashable ):
753
+ def _concat (self , indexes : list [Index ], name : Hashable ) -> Index :
765
754
"""
766
755
Overriding parent method for the case of all RangeIndex instances.
767
756
@@ -776,14 +765,15 @@ def _concat(self, indexes: list[Index], name: Hashable):
776
765
elif len (indexes ) == 1 :
777
766
return indexes [0 ]
778
767
768
+ rng_indexes = cast (List [RangeIndex ], indexes )
769
+
779
770
start = step = next_ = None
780
771
781
772
# Filter the empty indexes
782
- non_empty_indexes = [obj for obj in indexes if len (obj )]
773
+ non_empty_indexes = [obj for obj in rng_indexes if len (obj )]
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
@@ -793,7 +783,8 @@ def _concat(self, indexes: list[Index], name: Hashable):
793
783
elif step is None :
794
784
# First non-empty index had only one element
795
785
if rng .start == start :
796
- result = Int64Index (np .concatenate ([x ._values for x in indexes ]))
786
+ values = np .concatenate ([x ._values for x in rng_indexes ])
787
+ result = Int64Index (values )
797
788
return result .rename (name )
798
789
799
790
step = rng .start - start
@@ -802,7 +793,7 @@ def _concat(self, indexes: list[Index], name: Hashable):
802
793
next_ is not None and rng .start != next_
803
794
)
804
795
if non_consecutive :
805
- result = Int64Index (np .concatenate ([x ._values for x in indexes ]))
796
+ result = Int64Index (np .concatenate ([x ._values for x in rng_indexes ]))
806
797
return result .rename (name )
807
798
808
799
if step is not None :
@@ -811,12 +802,7 @@ def _concat(self, indexes: list[Index], name: Hashable):
811
802
if non_empty_indexes :
812
803
# Get the stop value from "next" or alternatively
813
804
# 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
- )
805
+ stop = non_empty_indexes [- 1 ].stop if next_ is None else next_
820
806
return RangeIndex (start , stop , step ).rename (name )
821
807
822
808
# Here all "indexes" had 0 length, i.e. were empty.
0 commit comments