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 for multi-index columns support. #662

Merged
merged 1 commit into from
Aug 21, 2019
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
20 changes: 11 additions & 9 deletions databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3979,7 +3979,6 @@ def select_dtypes(self, include=None, exclude=None):
inc_ex=set(include).intersection(set(exclude))))

# Handle Spark types
columns = []
include_spark_type = []
for inc in include:
try:
Expand Down Expand Up @@ -4009,23 +4008,26 @@ def select_dtypes(self, include=None, exclude=None):
except:
pass

for col in self._internal.data_columns:
columns = []
column_index = []
for idx, col in zip(self._internal.column_index, self._internal.data_columns):
if len(include) > 0:
should_include = (
infer_dtype_from_object(self[col].dtype.name) in include_numpy_type or
self._sdf.schema[col].dataType in include_spark_type)
infer_dtype_from_object(self[idx].dtype.name) in include_numpy_type or
self._internal.spark_type_for(col) in include_spark_type)
else:
should_include = not (
infer_dtype_from_object(self[col].dtype.name) in exclude_numpy_type or
self._sdf.schema[col].dataType in exclude_spark_type)
infer_dtype_from_object(self[idx].dtype.name) in exclude_numpy_type or
self._internal.spark_type_for(col) in exclude_spark_type)

if should_include:
columns += col
columns.append(col)
column_index.append(idx)

return DataFrame(self._internal.copy(
sdf=self._sdf.select(self._internal.index_scols +
[scol_for(self._sdf, col) for col in columns]),
data_columns=columns))
[self._internal.scol_for(col) for col in columns]),
data_columns=columns, column_index=column_index))

def count(self, axis=None):
"""
Expand Down