88 Any ,
99 Callable ,
1010 Hashable ,
11+ List ,
12+ cast ,
1113)
1214import warnings
1315
@@ -110,13 +112,7 @@ def __new__(
110112 copy : bool = False ,
111113 name : Hashable = None ,
112114 ) -> 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 )
120116 name = maybe_extract_name (name , start , cls )
121117
122118 # RangeIndex
@@ -159,13 +155,7 @@ def from_range(
159155 f"{ cls .__name__ } (...) must be called with object coercible to a "
160156 f"range, { repr (data )} was passed"
161157 )
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 )
169159 return cls ._simple_new (data , name = name )
170160
171161 @classmethod
@@ -439,9 +429,8 @@ def _get_indexer(
439429 def repeat (self , repeats , axis = None ) -> Int64Index :
440430 return self ._int64index .repeat (repeats , axis = axis )
441431
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 )
445434
446435 def take (
447436 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):
761750
762751 # --------------------------------------------------------------------
763752
764- def _concat (self , indexes : list [Index ], name : Hashable ):
753+ def _concat (self , indexes : list [Index ], name : Hashable ) -> Index :
765754 """
766755 Overriding parent method for the case of all RangeIndex instances.
767756
@@ -776,14 +765,15 @@ def _concat(self, indexes: list[Index], name: Hashable):
776765 elif len (indexes ) == 1 :
777766 return indexes [0 ]
778767
768+ rng_indexes = cast (List [RangeIndex ], indexes )
769+
779770 start = step = next_ = None
780771
781772 # 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 )]
783774
784775 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
787777
788778 if start is None :
789779 # This is set by the first non-empty index
@@ -793,7 +783,8 @@ def _concat(self, indexes: list[Index], name: Hashable):
793783 elif step is None :
794784 # First non-empty index had only one element
795785 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 )
797788 return result .rename (name )
798789
799790 step = rng .start - start
@@ -802,7 +793,7 @@ def _concat(self, indexes: list[Index], name: Hashable):
802793 next_ is not None and rng .start != next_
803794 )
804795 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 ]))
806797 return result .rename (name )
807798
808799 if step is not None :
@@ -811,12 +802,7 @@ def _concat(self, indexes: list[Index], name: Hashable):
811802 if non_empty_indexes :
812803 # Get the stop value from "next" or alternatively
813804 # 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_
820806 return RangeIndex (start , stop , step ).rename (name )
821807
822808 # Here all "indexes" had 0 length, i.e. were empty.
0 commit comments