Skip to content
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

First check for BaseDtype when infering the data type of an arbitrary object #13295

Merged
merged 2 commits into from
May 5, 2023
Merged
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
10 changes: 5 additions & 5 deletions python/cudf/cudf/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def dtype(arbitrary):
-------
dtype: the cuDF-supported dtype that best matches `arbitrary`
"""
# first, try interpreting arbitrary as a NumPy dtype that we support:
# first, check if `arbitrary` is one of our extension types:
if isinstance(arbitrary, cudf.core.dtypes._BaseDtype):
return arbitrary

# next, try interpreting arbitrary as a NumPy dtype that we support:
try:
np_dtype = np.dtype(arbitrary)
if np_dtype.kind in ("OU"):
Expand All @@ -54,10 +58,6 @@ def dtype(arbitrary):
raise TypeError(f"Unsupported type {np_dtype}")
return np_dtype

# next, check if `arbitrary` is one of our extension types:
if isinstance(arbitrary, cudf.core.dtypes._BaseDtype):
return arbitrary

# use `pandas_dtype` to try and interpret
# `arbitrary` as a Pandas extension type.
# Return the corresponding NumPy/cuDF type.
Expand Down