Skip to content

ENH: implement _typing.DtypeObj #31426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pandas/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
# other

Dtype = Union[str, np.dtype, "ExtensionDtype"]
DtypeObj = Union[np.dtype, "ExtensionDtype"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we call this DtypeType?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DtypeType seems easy to confuse with dtype.type, like it would be the type for CategoricalDtypeType

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh i c, so this is not a type, just a non-string Dtype. ok then.

FilePathOrBuffer = Union[str, Path, IO[AnyStr]]

# FrameOrSeriesUnion means either a DataFrame or a Series. E.g.
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down