@@ -157,7 +157,10 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
157157 with catch_warnings ():
158158 simplefilter ("ignore" , np .ComplexWarning )
159159 values = ensure_float64 (values )
160- return values , np .dtype ("float64" )
160+ # error: Incompatible return value type (got "Tuple[ExtensionArray,
161+ # dtype[floating[_64Bit]]]", expected "Tuple[ndarray, Union[dtype[Any],
162+ # ExtensionDtype]]")
163+ return values , np .dtype ("float64" ) # type: ignore[return-value]
161164
162165 except (TypeError , ValueError , OverflowError ):
163166 # if we are trying to coerce to a dtype
@@ -173,7 +176,9 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
173176 elif is_timedelta64_dtype (values .dtype ):
174177 from pandas import TimedeltaIndex
175178
176- values = TimedeltaIndex (values )._data
179+ # error: Incompatible types in assignment (expression has type
180+ # "TimedeltaArray", variable has type "ndarray")
181+ values = TimedeltaIndex (values )._data # type: ignore[assignment]
177182 else :
178183 # Datetime
179184 if values .ndim > 1 and is_datetime64_ns_dtype (values .dtype ):
@@ -182,27 +187,45 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
182187 # TODO(EA2D): special case not needed with 2D EAs
183188 asi8 = values .view ("i8" )
184189 dtype = values .dtype
185- return asi8 , dtype
190+ # error: Incompatible return value type (got "Tuple[Any,
191+ # Union[dtype, ExtensionDtype, None]]", expected
192+ # "Tuple[ndarray, Union[dtype, ExtensionDtype]]")
193+ return asi8 , dtype # type: ignore[return-value]
186194
187195 from pandas import DatetimeIndex
188196
189- values = DatetimeIndex (values )._data
197+ # Incompatible types in assignment (expression has type "DatetimeArray",
198+ # variable has type "ndarray")
199+ values = DatetimeIndex (values )._data # type: ignore[assignment]
190200 dtype = values .dtype
191- return values .asi8 , dtype
201+ # error: Item "ndarray" of "Union[PeriodArray, Any, ndarray]" has no attribute
202+ # "asi8"
203+ return values .asi8 , dtype # type: ignore[union-attr]
192204
193205 elif is_categorical_dtype (values .dtype ):
194- values = cast ("Categorical" , values )
195- values = values .codes
206+ # error: Incompatible types in assignment (expression has type "Categorical",
207+ # variable has type "ndarray")
208+ values = cast ("Categorical" , values ) # type: ignore[assignment]
209+ # error: Incompatible types in assignment (expression has type "ndarray",
210+ # variable has type "ExtensionArray")
211+ # error: Item "ndarray" of "Union[Any, ndarray]" has no attribute "codes"
212+ values = values .codes # type: ignore[assignment,union-attr]
196213 dtype = pandas_dtype ("category" )
197214
198215 # we are actually coercing to int64
199216 # until our algos support int* directly (not all do)
200217 values = ensure_int64 (values )
201218
202- return values , dtype
219+ # error: Incompatible return value type (got "Tuple[ExtensionArray,
220+ # Union[dtype[Any], ExtensionDtype]]", expected "Tuple[ndarray,
221+ # Union[dtype[Any], ExtensionDtype]]")
222+ return values , dtype # type: ignore[return-value]
203223
204224 # we have failed, return object
205- values = np .asarray (values , dtype = object )
225+
226+ # error: Incompatible types in assignment (expression has type "ndarray", variable
227+ # has type "ExtensionArray")
228+ values = np .asarray (values , dtype = object ) # type: ignore[assignment]
206229 return ensure_object (values ), np .dtype ("object" )
207230
208231
@@ -227,24 +250,40 @@ def _reconstruct_data(
227250 return values
228251
229252 if is_extension_array_dtype (dtype ):
230- cls = dtype .construct_array_type ()
253+ # error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no
254+ # attribute "construct_array_type"
255+ cls = dtype .construct_array_type () # type: ignore[union-attr]
231256 if isinstance (values , cls ) and values .dtype == dtype :
232257 return values
233258
234259 values = cls ._from_sequence (values )
235260 elif is_bool_dtype (dtype ):
236- values = values .astype (dtype , copy = False )
261+ # error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has
262+ # incompatible type "Union[dtype, ExtensionDtype]"; expected
263+ # "Union[dtype, None, type, _SupportsDtype, str, Tuple[Any, int],
264+ # Tuple[Any, Union[int, Sequence[int]]], List[Any], _DtypeDict,
265+ # Tuple[Any, Any]]"
266+ values = values .astype (dtype , copy = False ) # type: ignore[arg-type]
237267
238268 # we only support object dtypes bool Index
239269 if isinstance (original , ABCIndex ):
240270 values = values .astype (object , copy = False )
241271 elif dtype is not None :
242272 if is_datetime64_dtype (dtype ):
243- dtype = "datetime64[ns]"
273+ # error: Incompatible types in assignment (expression has type
274+ # "str", variable has type "Union[dtype, ExtensionDtype]")
275+ dtype = "datetime64[ns]" # type: ignore[assignment]
244276 elif is_timedelta64_dtype (dtype ):
245- dtype = "timedelta64[ns]"
277+ # error: Incompatible types in assignment (expression has type
278+ # "str", variable has type "Union[dtype, ExtensionDtype]")
279+ dtype = "timedelta64[ns]" # type: ignore[assignment]
246280
247- values = values .astype (dtype , copy = False )
281+ # error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has
282+ # incompatible type "Union[dtype, ExtensionDtype]"; expected
283+ # "Union[dtype, None, type, _SupportsDtype, str, Tuple[Any, int],
284+ # Tuple[Any, Union[int, Sequence[int]]], List[Any], _DtypeDict,
285+ # Tuple[Any, Any]]"
286+ values = values .astype (dtype , copy = False ) # type: ignore[arg-type]
248287
249288 return values
250289
@@ -296,14 +335,18 @@ def _get_values_for_rank(values: ArrayLike):
296335 if is_categorical_dtype (values ):
297336 values = cast ("Categorical" , values )._values_for_rank ()
298337
299- values , _ = _ensure_data (values )
338+ # error: Incompatible types in assignment (expression has type "ndarray", variable
339+ # has type "ExtensionArray")
340+ values , _ = _ensure_data (values ) # type: ignore[assignment]
300341 return values
301342
302343
303344def get_data_algo (values : ArrayLike ):
304345 values = _get_values_for_rank (values )
305346
306- ndtype = _check_object_for_strings (values )
347+ # error: Argument 1 to "_check_object_for_strings" has incompatible type
348+ # "ExtensionArray"; expected "ndarray"
349+ ndtype = _check_object_for_strings (values ) # type: ignore[arg-type]
307350 htable = _hashtables .get (ndtype , _hashtables ["object" ])
308351
309352 return htable , values
@@ -460,17 +503,46 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray:
460503 )
461504
462505 if not isinstance (values , (ABCIndex , ABCSeries , ABCExtensionArray , np .ndarray )):
463- values = _ensure_arraylike (list (values ))
506+ # error: Incompatible types in assignment (expression has type "ExtensionArray",
507+ # variable has type "Index")
508+ # error: Incompatible types in assignment (expression has type "ExtensionArray",
509+ # variable has type "Series")
510+ # error: Incompatible types in assignment (expression has type "ExtensionArray",
511+ # variable has type "ndarray")
512+ values = _ensure_arraylike (list (values )) # type: ignore[assignment]
464513 elif isinstance (values , ABCMultiIndex ):
465514 # Avoid raising in extract_array
466- values = np .array (values )
467- else :
468- values = extract_array (values , extract_numpy = True )
469515
470- comps = _ensure_arraylike (comps )
471- comps = extract_array (comps , extract_numpy = True )
516+ # error: Incompatible types in assignment (expression has type "ndarray",
517+ # variable has type "ExtensionArray")
518+ # error: Incompatible types in assignment (expression has type "ndarray",
519+ # variable has type "Index")
520+ # error: Incompatible types in assignment (expression has type "ndarray",
521+ # variable has type "Series")
522+ values = np .array (values ) # type: ignore[assignment]
523+ else :
524+ # error: Incompatible types in assignment (expression has type "Union[Any,
525+ # ExtensionArray]", variable has type "Index")
526+ # error: Incompatible types in assignment (expression has type "Union[Any,
527+ # ExtensionArray]", variable has type "Series")
528+ values = extract_array (values , extract_numpy = True ) # type: ignore[assignment]
529+
530+ # error: Incompatible types in assignment (expression has type "ExtensionArray",
531+ # variable has type "Index")
532+ # error: Incompatible types in assignment (expression has type "ExtensionArray",
533+ # variable has type "Series")
534+ # error: Incompatible types in assignment (expression has type "ExtensionArray",
535+ # variable has type "ndarray")
536+ comps = _ensure_arraylike (comps ) # type: ignore[assignment]
537+ # error: Incompatible types in assignment (expression has type "Union[Any,
538+ # ExtensionArray]", variable has type "Index")
539+ # error: Incompatible types in assignment (expression has type "Union[Any,
540+ # ExtensionArray]", variable has type "Series")
541+ comps = extract_array (comps , extract_numpy = True ) # type: ignore[assignment]
472542 if is_extension_array_dtype (comps .dtype ):
473- return comps .isin (values )
543+ # error: Incompatible return value type (got "Series", expected "ndarray")
544+ # error: Item "ndarray" of "Union[Any, ndarray]" has no attribute "isin"
545+ return comps .isin (values ) # type: ignore[return-value,union-attr]
474546
475547 elif needs_i8_conversion (comps .dtype ):
476548 # Dispatch to DatetimeLikeArrayMixin.isin
@@ -501,7 +573,19 @@ def f(c, v):
501573 f = np .in1d
502574
503575 else :
504- common = np .find_common_type ([values .dtype , comps .dtype ], [])
576+ # error: List item 0 has incompatible type "Union[Any, dtype[Any],
577+ # ExtensionDtype]"; expected "Union[dtype[Any], None, type, _SupportsDType, str,
578+ # Tuple[Any, Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any,
579+ # Any]]"
580+ # error: List item 1 has incompatible type "Union[Any, ExtensionDtype]";
581+ # expected "Union[dtype[Any], None, type, _SupportsDType, str, Tuple[Any,
582+ # Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]"
583+ # error: List item 1 has incompatible type "Union[dtype[Any], ExtensionDtype]";
584+ # expected "Union[dtype[Any], None, type, _SupportsDType, str, Tuple[Any,
585+ # Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]"
586+ common = np .find_common_type (
587+ [values .dtype , comps .dtype ], [] # type: ignore[list-item]
588+ )
505589 values = values .astype (common , copy = False )
506590 comps = comps .astype (common , copy = False )
507591 name = common .name
@@ -916,7 +1000,9 @@ def duplicated(values: ArrayLike, keep: Union[str, bool] = "first") -> np.ndarra
9161000 -------
9171001 duplicated : ndarray
9181002 """
919- values , _ = _ensure_data (values )
1003+ # error: Incompatible types in assignment (expression has type "ndarray", variable
1004+ # has type "ExtensionArray")
1005+ values , _ = _ensure_data (values ) # type: ignore[assignment]
9201006 ndtype = values .dtype .name
9211007 f = getattr (htable , f"duplicated_{ ndtype } " )
9221008 return f (values , keep = keep )
@@ -1188,7 +1274,9 @@ def _get_score(at):
11881274 else :
11891275 q = np .asarray (q , np .float64 )
11901276 result = [_get_score (x ) for x in q ]
1191- result = np .array (result , dtype = np .float64 )
1277+ # error: Incompatible types in assignment (expression has type
1278+ # "ndarray", variable has type "List[Any]")
1279+ result = np .array (result , dtype = np .float64 ) # type: ignore[assignment]
11921280 return result
11931281
11941282
@@ -1776,7 +1864,11 @@ def safe_sort(
17761864 if not isinstance (values , (np .ndarray , ABCExtensionArray )):
17771865 # don't convert to string types
17781866 dtype , _ = infer_dtype_from_array (values )
1779- values = np .asarray (values , dtype = dtype )
1867+ # error: Argument "dtype" to "asarray" has incompatible type "Union[dtype[Any],
1868+ # ExtensionDtype]"; expected "Union[dtype[Any], None, type, _SupportsDType, str,
1869+ # Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any],
1870+ # _DTypeDict, Tuple[Any, Any]]]"
1871+ values = np .asarray (values , dtype = dtype ) # type: ignore[arg-type]
17801872
17811873 sorter = None
17821874
0 commit comments