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

Fix select_dtypes to work when non-class dtypes present in dataframe #8849

Merged
merged 5 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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: 6 additions & 4 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
beckernick marked this conversation as resolved.
Show resolved Hide resolved
if issubclass(dtype.type, i_dtype):
include_subtypes.add(dtype.type)

# exclude all subtypes
exclude_subtypes = set()
Expand All @@ -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]
Expand Down
8 changes: 8 additions & 0 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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").columns, gdf.select_dtypes("int64").columns,
sarahyurick marked this conversation as resolved.
Show resolved Hide resolved
)


def test_select_dtype_datetime():
gdf = cudf.datasets.timeseries(
Expand Down