@@ -235,41 +235,26 @@ def _reconstruct_data(
235
235
# Catch DatetimeArray/TimedeltaArray
236
236
return values
237
237
238
- if is_extension_array_dtype (dtype ):
239
- # error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no
240
- # attribute "construct_array_type"
241
- cls = dtype .construct_array_type () # type: ignore[union-attr]
238
+ if not isinstance (dtype , np .dtype ):
239
+ # i.e. ExtensionDtype
240
+ cls = dtype .construct_array_type ()
242
241
if isinstance (values , cls ) and values .dtype == dtype :
243
242
return values
244
243
245
244
values = cls ._from_sequence (values )
246
245
elif is_bool_dtype (dtype ):
247
- # error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has
248
- # incompatible type "Union[dtype, ExtensionDtype]"; expected
249
- # "Union[dtype, None, type, _SupportsDtype, str, Tuple[Any, int],
250
- # Tuple[Any, Union[int, Sequence[int]]], List[Any], _DtypeDict,
251
- # Tuple[Any, Any]]"
252
- values = values .astype (dtype , copy = False ) # type: ignore[arg-type]
246
+ values = values .astype (dtype , copy = False )
253
247
254
248
# we only support object dtypes bool Index
255
249
if isinstance (original , ABCIndex ):
256
250
values = values .astype (object , copy = False )
257
251
elif dtype is not None :
258
252
if is_datetime64_dtype (dtype ):
259
- # error: Incompatible types in assignment (expression has type
260
- # "str", variable has type "Union[dtype, ExtensionDtype]")
261
- dtype = "datetime64[ns]" # type: ignore[assignment]
253
+ dtype = np .dtype ("datetime64[ns]" )
262
254
elif is_timedelta64_dtype (dtype ):
263
- # error: Incompatible types in assignment (expression has type
264
- # "str", variable has type "Union[dtype, ExtensionDtype]")
265
- dtype = "timedelta64[ns]" # type: ignore[assignment]
255
+ dtype = np .dtype ("timedelta64[ns]" )
266
256
267
- # error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has
268
- # incompatible type "Union[dtype, ExtensionDtype]"; expected
269
- # "Union[dtype, None, type, _SupportsDtype, str, Tuple[Any, int],
270
- # Tuple[Any, Union[int, Sequence[int]]], List[Any], _DtypeDict,
271
- # Tuple[Any, Any]]"
272
- values = values .astype (dtype , copy = False ) # type: ignore[arg-type]
257
+ values = values .astype (dtype , copy = False )
273
258
274
259
return values
275
260
@@ -772,7 +757,8 @@ def factorize(
772
757
uniques = Index (uniques )
773
758
return codes , uniques
774
759
775
- if is_extension_array_dtype (values .dtype ):
760
+ if not isinstance (values .dtype , np .dtype ):
761
+ # i.e. ExtensionDtype
776
762
codes , uniques = values .factorize (na_sentinel = na_sentinel )
777
763
dtype = original .dtype
778
764
else :
@@ -1662,7 +1648,8 @@ def diff(arr, n: int, axis: int = 0, stacklevel=3):
1662
1648
arr = arr .to_numpy ()
1663
1649
dtype = arr .dtype
1664
1650
1665
- if is_extension_array_dtype (dtype ):
1651
+ if not isinstance (dtype , np .dtype ):
1652
+ # i.e ExtensionDtype
1666
1653
if hasattr (arr , f"__{ op .__name__ } __" ):
1667
1654
if axis != 0 :
1668
1655
raise ValueError (f"cannot diff { type (arr ).__name__ } on axis={ axis } " )
0 commit comments