diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 40837ccad6ac8..088c44334495c 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -449,7 +449,7 @@ def __ne__(self, other: Any) -> ArrayLike: # type: ignore[override] def to_numpy( self, - dtype: Dtype | None = None, + dtype: npt.DTypeLike | None = None, copy: bool = False, na_value=lib.no_default, ) -> np.ndarray: @@ -478,12 +478,7 @@ def to_numpy( ------- numpy.ndarray """ - # error: Argument "dtype" to "asarray" has incompatible type - # "Union[ExtensionDtype, str, dtype[Any], Type[str], Type[float], Type[int], - # Type[complex], Type[bool], Type[object], None]"; expected "Union[dtype[Any], - # None, type, _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int, - # Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]]" - result = np.asarray(self, dtype=dtype) # type: ignore[arg-type] + result = np.asarray(self, dtype=dtype) if copy or na_value is not lib.no_default: result = result.copy() if na_value is not lib.no_default: diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 877babe4f18e8..e40d8b74c768c 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -224,12 +224,9 @@ def __len__(self) -> int: def __invert__(self: BaseMaskedArrayT) -> BaseMaskedArrayT: return type(self)(~self._data, self._mask.copy()) - # error: Argument 1 of "to_numpy" is incompatible with supertype "ExtensionArray"; - # supertype defines the argument type as "Union[ExtensionDtype, str, dtype[Any], - # Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" - def to_numpy( # type: ignore[override] + def to_numpy( self, - dtype: NpDtype | None = None, + dtype: npt.DTypeLike | None = None, copy: bool = False, na_value: Scalar = lib.no_default, ) -> np.ndarray: diff --git a/pandas/core/arrays/numpy_.py b/pandas/core/arrays/numpy_.py index ec7bd132832d1..410497d61c98b 100644 --- a/pandas/core/arrays/numpy_.py +++ b/pandas/core/arrays/numpy_.py @@ -10,6 +10,7 @@ Dtype, NpDtype, Scalar, + npt, ) from pandas.compat.numpy import function as nv @@ -365,12 +366,9 @@ def skew( # ------------------------------------------------------------------------ # Additional Methods - # error: Argument 1 of "to_numpy" is incompatible with supertype "ExtensionArray"; - # supertype defines the argument type as "Union[ExtensionDtype, str, dtype[Any], - # Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" - def to_numpy( # type: ignore[override] + def to_numpy( self, - dtype: NpDtype | None = None, + dtype: npt.DTypeLike | None = None, copy: bool = False, na_value=lib.no_default, ) -> np.ndarray: diff --git a/pandas/core/arrays/string_arrow.py b/pandas/core/arrays/string_arrow.py index 4be7f4eb0c521..9411d3535e06f 100644 --- a/pandas/core/arrays/string_arrow.py +++ b/pandas/core/arrays/string_arrow.py @@ -24,6 +24,7 @@ Scalar, ScalarIndexer, SequenceIndexer, + npt, ) from pandas.compat import ( pa_version_under1p0, @@ -199,12 +200,9 @@ def __arrow_array__(self, type=None): """Convert myself to a pyarrow Array or ChunkedArray.""" return self._data - # error: Argument 1 of "to_numpy" is incompatible with supertype "ExtensionArray"; - # supertype defines the argument type as "Union[ExtensionDtype, str, dtype[Any], - # Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" - def to_numpy( # type: ignore[override] + def to_numpy( self, - dtype: NpDtype | None = None, + dtype: npt.DTypeLike | None = None, copy: bool = False, na_value=lib.no_default, ) -> np.ndarray: diff --git a/pandas/core/base.py b/pandas/core/base.py index c7a707fd5cd6e..048831a74d1a5 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -516,16 +516,8 @@ def to_numpy( """ if is_extension_array_dtype(self.dtype): # error: Too many arguments for "to_numpy" of "ExtensionArray" - - # error: Argument 1 to "to_numpy" of "ExtensionArray" has incompatible type - # "Optional[Union[dtype[Any], None, type, _SupportsDType[dtype[Any]], str, - # Union[Tuple[Any, int], Tuple[Any, Union[SupportsIndex, - # Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]]]"; - # expected "Optional[Union[ExtensionDtype, Union[str, dtype[Any]], - # Type[str], Type[float], Type[int], Type[complex], Type[bool], - # Type[object]]]" return self.array.to_numpy( # type: ignore[call-arg] - dtype, copy=copy, na_value=na_value, **kwargs # type: ignore[arg-type] + dtype, copy=copy, na_value=na_value, **kwargs ) elif kwargs: bad_keys = list(kwargs.keys())[0]