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] Misc optimizations in cudf #9203

Merged
merged 7 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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/_lib/parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ cpdef read_parquet(filepaths_or_buffers, columns=None, row_groups=None,
idx = idx[skiprows:]
if num_rows is not None:
idx = idx[:num_rows]
df.index = idx
df._index = idx
elif set(index_col).issubset(column_names):
index_data = df[index_col]
actual_index_names = list(index_col_names.values())
Expand All @@ -250,7 +250,7 @@ cpdef read_parquet(filepaths_or_buffers, columns=None, row_groups=None,
names=actual_index_names
)
df.drop(columns=index_col, inplace=True)
df.index = idx
df._index = idx
else:
if use_pandas_metadata:
df.index.names = index_col
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def _get_column_selection(self, arg):


def _normalize_dtypes(df):
if len(df.columns) > 0:
if df._num_columns > 0:
dtypes = df.dtypes.values.tolist()
normalized_dtype = np.result_type(*dtypes)
for name, col in df._data.items():
Expand Down
29 changes: 15 additions & 14 deletions python/dask_cudf/dask_cudf/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ def read_metadata(*args, **kwargs):
meta, stats, parts, index = ArrowDatasetEngine.read_metadata(
*args, **kwargs
)
new_meta = cudf.from_pandas(meta)
if parts:
# Re-set "object" dtypes align with pa schema
set_object_dtypes_from_pa_schema(
meta, parts[0].get("common_kwargs", {}).get("schema", None),
new_meta,
parts[0].get("common_kwargs", {}).get("schema", None),
)

# If `strings_to_categorical==True`, convert objects to int32
strings_to_cats = kwargs.get("strings_to_categorical", False)

new_meta = cudf.DataFrame(index=meta.index)
for col in meta.columns:
if meta[col].dtype == "O":
new_meta[col] = as_column(
meta[col], dtype="int32" if strings_to_cats else "object"
)
else:
new_meta[col] = as_column(meta[col])
for col in new_meta._data.names:
if (
isinstance(new_meta._data[col], cudf.core.column.StringColumn)
and strings_to_cats
):
new_meta._data[col] = new_meta._data[col].astype("int32")

return (new_meta, stats, parts, index)

Expand Down Expand Up @@ -338,10 +337,12 @@ def set_object_dtypes_from_pa_schema(df, schema):
# "object" dtypes to agree with a specific
# pyarrow schema.
if schema:
for name in df.columns:
if name in schema.names and df[name].dtype == "O":
df[name] = df[name].astype(
cudf_dtype_from_pa_type(schema.field(name).type)
for col_name, col in df._data.items():
if col_name in schema.names and isinstance(
col, cudf.core.column.StringColumn
):
galipremsagar marked this conversation as resolved.
Show resolved Hide resolved
df._data[col_name] = col.astype(
cudf_dtype_from_pa_type(schema.field(col_name).type)
)


Expand Down