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

[REVIEW] ignore list dtypes for select_dtype, similar to pandas #6928

Closed
Closed
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
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6741,7 +6741,7 @@ 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):
elif type(dtype.type) == type and issubclass(dtype.type, i_dtype):
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this change exclude list types specifically?

include_subtypes.add(dtype.type)

# exclude all subtypes
Expand All @@ -6751,7 +6751,7 @@ 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):
elif type(dtype.type) == type and issubclass(dtype.type, e_dtype):
exclude_subtypes.add(dtype.type)

include_all = set(
Expand Down
11 changes: 11 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2972,6 +2972,17 @@ def test_select_dtype():
gdf.select_dtypes(include=["int"], exclude=["object"]),
)

gdf = gd.DataFrame({'int_col': [0, 1, 2], 'list_col': [[1, 2], [3, 4], [5, 6]]})
pdf = gdf.to_pandas()
assert_eq(
pdf.select_dtypes(include=['int64']).columns,
gdf.select_dtypes(include=['int64']).columns
)
assert_eq(
pdf.select_dtypes(exclude=['int64']).columns,
gdf.select_dtypes(exclude=['int64']).columns
)


def test_select_dtype_datetime():
gdf = gd.datasets.timeseries(
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/utils/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def cudf_dtype_from_pydata_dtype(dtype):

if is_categorical_dtype(dtype):
return cudf.core.dtypes.CategoricalDtype
elif dtype in cudf._lib.types.np_to_cudf_types:
elif dtype.__hash__ and dtype in cudf._lib.types.np_to_cudf_types:
return dtype.type

return infer_dtype_from_object(dtype)
Expand Down