@@ -157,7 +157,10 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
157
157
with catch_warnings ():
158
158
simplefilter ("ignore" , np .ComplexWarning )
159
159
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]
161
164
162
165
except (TypeError , ValueError , OverflowError ):
163
166
# if we are trying to coerce to a dtype
@@ -173,7 +176,9 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
173
176
elif is_timedelta64_dtype (values .dtype ):
174
177
from pandas import TimedeltaIndex
175
178
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]
177
182
else :
178
183
# Datetime
179
184
if values .ndim > 1 and is_datetime64_ns_dtype (values .dtype ):
@@ -182,27 +187,45 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
182
187
# TODO(EA2D): special case not needed with 2D EAs
183
188
asi8 = values .view ("i8" )
184
189
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]
186
194
187
195
from pandas import DatetimeIndex
188
196
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]
190
200
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]
192
204
193
205
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]
196
213
dtype = pandas_dtype ("category" )
197
214
198
215
# we are actually coercing to int64
199
216
# until our algos support int* directly (not all do)
200
217
values = ensure_int64 (values )
201
218
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]
203
223
204
224
# 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]
206
229
return ensure_object (values ), np .dtype ("object" )
207
230
208
231
@@ -227,24 +250,40 @@ def _reconstruct_data(
227
250
return values
228
251
229
252
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]
231
256
if isinstance (values , cls ) and values .dtype == dtype :
232
257
return values
233
258
234
259
values = cls ._from_sequence (values )
235
260
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]
237
267
238
268
# we only support object dtypes bool Index
239
269
if isinstance (original , ABCIndex ):
240
270
values = values .astype (object , copy = False )
241
271
elif dtype is not None :
242
272
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]
244
276
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]
246
280
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]
248
287
249
288
return values
250
289
@@ -296,14 +335,18 @@ def _get_values_for_rank(values: ArrayLike):
296
335
if is_categorical_dtype (values ):
297
336
values = cast ("Categorical" , values )._values_for_rank ()
298
337
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]
300
341
return values
301
342
302
343
303
344
def get_data_algo (values : ArrayLike ):
304
345
values = _get_values_for_rank (values )
305
346
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]
307
350
htable = _hashtables .get (ndtype , _hashtables ["object" ])
308
351
309
352
return htable , values
@@ -460,17 +503,46 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray:
460
503
)
461
504
462
505
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]
464
513
elif isinstance (values , ABCMultiIndex ):
465
514
# Avoid raising in extract_array
466
- values = np .array (values )
467
- else :
468
- values = extract_array (values , extract_numpy = True )
469
515
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]
472
542
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]
474
546
475
547
elif needs_i8_conversion (comps .dtype ):
476
548
# Dispatch to DatetimeLikeArrayMixin.isin
@@ -501,7 +573,19 @@ def f(c, v):
501
573
f = np .in1d
502
574
503
575
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
+ )
505
589
values = values .astype (common , copy = False )
506
590
comps = comps .astype (common , copy = False )
507
591
name = common .name
@@ -916,7 +1000,9 @@ def duplicated(values: ArrayLike, keep: Union[str, bool] = "first") -> np.ndarra
916
1000
-------
917
1001
duplicated : ndarray
918
1002
"""
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]
920
1006
ndtype = values .dtype .name
921
1007
f = getattr (htable , f"duplicated_{ ndtype } " )
922
1008
return f (values , keep = keep )
@@ -1188,7 +1274,9 @@ def _get_score(at):
1188
1274
else :
1189
1275
q = np .asarray (q , np .float64 )
1190
1276
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]
1192
1280
return result
1193
1281
1194
1282
@@ -1776,7 +1864,11 @@ def safe_sort(
1776
1864
if not isinstance (values , (np .ndarray , ABCExtensionArray )):
1777
1865
# don't convert to string types
1778
1866
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]
1780
1872
1781
1873
sorter = None
1782
1874
0 commit comments