diff --git a/python/cudf/cudf/core/dtypes.py b/python/cudf/cudf/core/dtypes.py index 49c931a4218..edd557aad1f 100644 --- a/python/cudf/cudf/core/dtypes.py +++ b/python/cudf/cudf/core/dtypes.py @@ -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"): @@ -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.