diff --git a/pandas/_typing.py b/pandas/_typing.py index 171b76b4d2c4b..e2858441605f7 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -45,6 +45,7 @@ # other Dtype = Union[str, np.dtype, "ExtensionDtype"] +DtypeObj = Union[np.dtype, "ExtensionDtype"] FilePathOrBuffer = Union[str, Path, IO[AnyStr]] # FrameOrSeriesUnion means either a DataFrame or a Series. E.g. diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index f62f03be9b732..eb9b880cd10d9 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -6,7 +6,7 @@ from pandas._libs import algos, lib from pandas._libs.tslibs import conversion -from pandas._typing import ArrayLike +from pandas._typing import ArrayLike, DtypeObj from pandas.core.dtypes.dtypes import ( CategoricalDtype, @@ -1668,7 +1668,7 @@ def _is_dtype(arr_or_dtype, condition) -> bool: return condition(dtype) -def _get_dtype(arr_or_dtype): +def _get_dtype(arr_or_dtype) -> DtypeObj: """ Get the dtype instance associated with an array or dtype object. @@ -1840,7 +1840,7 @@ def _validate_date_like_dtype(dtype) -> None: ) -def pandas_dtype(dtype): +def pandas_dtype(dtype) -> DtypeObj: """ Convert input into a pandas only dtype object or a numpy dtype object. diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index fb579f2f58a57..0bc754b3e8fb3 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -8,6 +8,7 @@ from pandas._libs import lib import pandas._libs.missing as libmissing from pandas._libs.tslibs import NaT, iNaT +from pandas._typing import DtypeObj from pandas.core.dtypes.common import ( _NS_DTYPE, @@ -585,7 +586,7 @@ def remove_na_arraylike(arr): return arr[notna(lib.values_from_object(arr))] -def is_valid_nat_for_dtype(obj, dtype) -> bool: +def is_valid_nat_for_dtype(obj, dtype: DtypeObj) -> bool: """ isna check that excludes incompatible dtypes