@@ -235,41 +235,26 @@ def _reconstruct_data(
235235 # Catch DatetimeArray/TimedeltaArray
236236 return values
237237
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 ()
242241 if isinstance (values , cls ) and values .dtype == dtype :
243242 return values
244243
245244 values = cls ._from_sequence (values )
246245 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 )
253247
254248 # we only support object dtypes bool Index
255249 if isinstance (original , ABCIndex ):
256250 values = values .astype (object , copy = False )
257251 elif dtype is not None :
258252 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]" )
262254 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]" )
266256
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 )
273258
274259 return values
275260
@@ -772,7 +757,8 @@ def factorize(
772757 uniques = Index (uniques )
773758 return codes , uniques
774759
775- if is_extension_array_dtype (values .dtype ):
760+ if not isinstance (values .dtype , np .dtype ):
761+ # i.e. ExtensionDtype
776762 codes , uniques = values .factorize (na_sentinel = na_sentinel )
777763 dtype = original .dtype
778764 else :
@@ -1662,7 +1648,8 @@ def diff(arr, n: int, axis: int = 0, stacklevel=3):
16621648 arr = arr .to_numpy ()
16631649 dtype = arr .dtype
16641650
1665- if is_extension_array_dtype (dtype ):
1651+ if not isinstance (dtype , np .dtype ):
1652+ # i.e ExtensionDtype
16661653 if hasattr (arr , f"__{ op .__name__ } __" ):
16671654 if axis != 0 :
16681655 raise ValueError (f"cannot diff { type (arr ).__name__ } on axis={ axis } " )
0 commit comments