diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index e9e3cd71ddb..7cd42d749ec 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -7359,8 +7359,9 @@ def select_dtypes(self, include=None, exclude=None): # category handling if is_categorical_dtype(i_dtype): include_subtypes.add(i_dtype) - elif issubclass(dtype.type, i_dtype): - include_subtypes.add(dtype.type) + elif inspect.isclass(dtype.type): + if issubclass(dtype.type, i_dtype): + include_subtypes.add(dtype.type) # exclude all subtypes exclude_subtypes = set() @@ -7369,8 +7370,9 @@ def select_dtypes(self, include=None, exclude=None): # category handling if is_categorical_dtype(e_dtype): exclude_subtypes.add(e_dtype) - elif issubclass(dtype.type, e_dtype): - exclude_subtypes.add(dtype.type) + elif inspect.isclass(dtype.type): + if issubclass(dtype.type, e_dtype): + exclude_subtypes.add(dtype.type) include_all = set( [cudf_dtype_from_pydata_dtype(d) for d in self.dtypes] diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index 4214ca46b3d..ecd31afd9e8 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -3079,6 +3079,14 @@ def test_select_dtype(): gdf.select_dtypes(include=["int"], exclude=["object"]), ) + gdf = cudf.DataFrame( + {"int_col": [0, 1, 2], "list_col": [[1, 2], [3, 4], [5, 6]]} + ) + pdf = gdf.to_pandas() + assert_eq( + pdf.select_dtypes("int64"), gdf.select_dtypes("int64"), + ) + def test_select_dtype_datetime(): gdf = cudf.datasets.timeseries(