Skip to content

Commit 0701c5e

Browse files
authored
ENH: implement pd._typing.DtypeObj (#31426)
1 parent addfd7a commit 0701c5e

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

pandas/_typing.py

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
# other
4646

4747
Dtype = Union[str, np.dtype, "ExtensionDtype"]
48+
DtypeObj = Union[np.dtype, "ExtensionDtype"]
4849
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
4950

5051
# FrameOrSeriesUnion means either a DataFrame or a Series. E.g.

pandas/core/dtypes/common.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from pandas._libs import algos, lib
88
from pandas._libs.tslibs import conversion
9-
from pandas._typing import ArrayLike
9+
from pandas._typing import ArrayLike, DtypeObj
1010

1111
from pandas.core.dtypes.dtypes import (
1212
CategoricalDtype,
@@ -1668,7 +1668,7 @@ def _is_dtype(arr_or_dtype, condition) -> bool:
16681668
return condition(dtype)
16691669

16701670

1671-
def _get_dtype(arr_or_dtype):
1671+
def _get_dtype(arr_or_dtype) -> DtypeObj:
16721672
"""
16731673
Get the dtype instance associated with an array
16741674
or dtype object.
@@ -1840,7 +1840,7 @@ def _validate_date_like_dtype(dtype) -> None:
18401840
)
18411841

18421842

1843-
def pandas_dtype(dtype):
1843+
def pandas_dtype(dtype) -> DtypeObj:
18441844
"""
18451845
Convert input into a pandas only dtype object or a numpy dtype object.
18461846

pandas/core/dtypes/missing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pandas._libs import lib
99
import pandas._libs.missing as libmissing
1010
from pandas._libs.tslibs import NaT, iNaT
11+
from pandas._typing import DtypeObj
1112

1213
from pandas.core.dtypes.common import (
1314
_NS_DTYPE,
@@ -585,7 +586,7 @@ def remove_na_arraylike(arr):
585586
return arr[notna(lib.values_from_object(arr))]
586587

587588

588-
def is_valid_nat_for_dtype(obj, dtype) -> bool:
589+
def is_valid_nat_for_dtype(obj, dtype: DtypeObj) -> bool:
589590
"""
590591
isna check that excludes incompatible dtypes
591592

0 commit comments

Comments
 (0)