diff --git a/pandas/_typing.py b/pandas/_typing.py index 5225be33d7604..325c96f024f82 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -1,4 +1,11 @@ from pathlib import Path -from typing import IO, AnyStr, Union +from typing import IO, AnyStr, Type, Union +import numpy as np + +from pandas.core.dtypes.dtypes import ExtensionDtype +from pandas.core.dtypes.generic import ABCExtensionArray + +ArrayLike = Union[ABCExtensionArray, np.ndarray] +Dtype = Union[str, np.dtype, ExtensionDtype, Type] FilePathOrBuffer = Union[str, Path, IO[AnyStr]] diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 44662ce831b89..846eb442ef816 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -21,6 +21,7 @@ ABCExtensionArray, ABCIndexClass, ABCSeries) from pandas.core.dtypes.missing import isna +from pandas._typing import ArrayLike from pandas.core import ops _not_implemented_message = "{} does not implement {}." @@ -338,7 +339,7 @@ def astype(self, dtype, copy=True): """ return np.array(self, dtype=dtype, copy=copy) - def isna(self) -> Union[ABCExtensionArray, np.ndarray]: + def isna(self) -> ArrayLike: """ A 1-D array indicating if each value is missing. diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index 3d18255e78aa9..d09c0dbd0e398 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -4,7 +4,7 @@ import numbers import operator import re -from typing import Any, Callable, Type, Union +from typing import Any, Callable import warnings import numpy as np @@ -30,6 +30,7 @@ ABCIndexClass, ABCSeries, ABCSparseArray, ABCSparseSeries) from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna +from pandas._typing import Dtype from pandas.core.accessor import PandasDelegate, delegate_names import pandas.core.algorithms as algos from pandas.core.arrays import ExtensionArray, ExtensionOpsMixin @@ -79,7 +80,7 @@ class SparseDtype(ExtensionDtype): def __init__( self, - dtype: Union[str, np.dtype, ExtensionDtype, Type] = np.float64, + dtype: Dtype = np.float64, fill_value: Any = None ) -> None: from pandas.core.dtypes.missing import na_value_for_dtype