Skip to content

Avoid casting to list or struct dtypes in dask_cudf.read_parquet - #9314

Merged
rapids-bot[bot] merged 3 commits into
NVIDIA:branch-21.12from
rjzamora:fix-schema-cast
Sep 30, 2021
Merged

rapids-bot[bot] merged 3 commits into
NVIDIA:branch-21.12from
rjzamora:fix-schema-cast

Conversation

@rjzamora

Copy link
Copy Markdown
Contributor

A similar fix for this problem was recently submitted in #9159 and closed in favor of #9203. It seems that the test added in the latter PR was not actually capturing the original problem. However, after dask#8072 is merged, the new test will certainly start failing.

@rjzamora rjzamora added bug Something isn't working 2 - In Progress Currently a work in progress dask Dask issue non-breaking Non-breaking change labels Sep 27, 2021
@rjzamora rjzamora self-assigned this Sep 27, 2021
@rjzamora
rjzamora requested a review from a team as a code owner September 27, 2021 16:59
@github-actions github-actions Bot added the Python Affects Python cuDF API. label Sep 27, 2021

class Index(Series, dd.core.Index):
_partition_type = cudf.Index
_partition_type = cudf.Index # type: ignore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change is not related to the PR, but was added to avoid local mypy failures...

python/dask_cudf/dask_cudf/groupby.py:381: error: Need type annotation for '_global_set' (hint: "_global_set: Set[<type>] = ...")
python/dask_cudf/dask_cudf/core.py:423: error: Incompatible types in assignment (expression has type "Type[Index]", base class "Series" defined the type as "Type[Series]")
Found 2 errors in 2 files (checked 122 source files)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cc: @shwina for the mypy failure

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have previously encountered cases where unrelated changes to the code allow mypy's engine to discover typing errors that it previously couldn't. This mypy error looks real, but I think adding this ignore is fine for now. I assume that making dd.Index inherit from dd.Series was done for convenience at some point, and refactoring the class hierarchy is the only correct way to make this go away but is out of scope for this PR.

@rjzamora

Copy link
Copy Markdown
Contributor Author

cc @galipremsagar

galipremsagar
galipremsagar previously approved these changes Sep 27, 2021
@galipremsagar
galipremsagar dismissed their stale review September 27, 2021 17:05

dismissing review

@codecov

codecov Bot commented Sep 27, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #9314 (28bac23) into branch-21.12 (ab4bfaa) will increase coverage by 0.06%.
The diff coverage is 38.09%.

❗ Current head 28bac23 differs from pull request most recent head caa7c0b. Consider uploading reports for the commit caa7c0b to get more accurate results
Impacted file tree graph

@@               Coverage Diff                @@
##           branch-21.12    #9314      +/-   ##
================================================
+ Coverage         10.79%   10.85%   +0.06%     
================================================
  Files               116      116              
  Lines             18869    19261     +392     
================================================
+ Hits               2036     2090      +54     
- Misses            16833    17171     +338     
Impacted Files Coverage Δ
python/cudf/cudf/core/series.py 0.00% <0.00%> (ø)
python/cudf/cudf/io/orc.py 0.00% <0.00%> (ø)
python/dask_cudf/dask_cudf/core.py 71.02% <100.00%> (+0.16%) ⬆️
python/dask_cudf/dask_cudf/groupby.py 96.29% <100.00%> (+0.01%) ⬆️
python/dask_cudf/dask_cudf/io/parquet.py 89.74% <100.00%> (+0.41%) ⬆️
...ython/dask_cudf/dask_cudf/io/tests/test_parquet.py 100.00% <100.00%> (ø)
python/cudf/cudf/io/hdf.py 0.00% <0.00%> (ø)
python/cudf/cudf/_version.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/abc.py 0.00% <0.00%> (ø)
... and 52 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fd77ca6...caa7c0b. Read the comment docs.

@rjzamora rjzamora added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currently a work in progress labels Sep 27, 2021
@quasiben

Copy link
Copy Markdown
Contributor

@gpucibot merge

@rapids-bot
rapids-bot Bot merged commit 840faf5 into NVIDIA:branch-21.12 Sep 30, 2021

@charlesbluca charlesbluca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Just one question regarding the additional import of pyarrow:

for col_name, col in df._data.items():
if col_name in schema.names and isinstance(
col, cudf.core.column.StringColumn
typ = schema.field(col_name).type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any particular reason we don't opt to call cudf_dtype_from_pa_type up here, and avoid having to import pyarrow?

Suggested change
typ = schema.field(col_name).type
typ = cudf_dtype_from_pa_type(schema.field(col_name).type)

typ = schema.field(col_name).type
if (
col_name in schema.names
and not isinstance(typ, (pa.ListType, pa.StructType))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Continuation of above comment:

Suggested change
and not isinstance(typ, (pa.ListType, pa.StructType))
and not isinstance(typ, (cudf.ListDtype, cudf.StructDtype))

df._data[col_name] = col.astype(
cudf_dtype_from_pa_type(schema.field(col_name).type)
)
df._data[col_name] = col.astype(cudf_dtype_from_pa_type(typ))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Continuation of above comment:

Suggested change
df._data[col_name] = col.astype(cudf_dtype_from_pa_type(typ))
df._data[col_name] = col.astype(typ)

from io import BufferedWriter, BytesIO, IOBase

import numpy as np
import pyarrow as pa

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Continuation of above comment:

Suggested change
import pyarrow as pa

@jakirkham

Copy link
Copy Markdown
Contributor

@charlesbluca, would it make sense to send these changes in a new PR?

@charlesbluca

Copy link
Copy Markdown
Contributor

Thanks for the reminder @jakirkham! Yeah I think this is PR-worthy - I'll open one up now 🙂

@jakirkham

Copy link
Copy Markdown
Contributor

Thanks Charles! 😄

For reference, theses changes are in PR ( #9429 )

rapids-bot Bot pushed a commit that referenced this pull request Oct 14, 2021
Small follow up to #9314, which implements my review comments and removes a seemingly unnecessary import of pyarrow.

cc @rjzamora @jakirkham

Authors:
  - Charles Blackmon-Luca (https://github.com/charlesbluca)

Approvers:
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #9429
@vyasr vyasr added the 4 - Needs Review Waiting for reviewer to review or respond label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team 4 - Needs Review Waiting for reviewer to review or respond bug Something isn't working dask Dask issue non-breaking Non-breaking change Python Affects Python cuDF API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants