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

Avoid passing NativeFileDatasource to pyarrow in read_parquet #9608

Merged
Merged
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
12 changes: 11 additions & 1 deletion python/cudf/cudf/_lib/parquet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,17 @@ cpdef read_parquet(filepaths_or_buffers, columns=None, row_groups=None,
cudf.io.parquet.read_parquet
cudf.io.parquet.to_parquet
"""

# Convert NativeFile buffers to NativeFileDatasource,
# but save original buffers in case we need to use
# pyarrow for metadata processing
# (See: https://github.com/rapidsai/cudf/issues/9599)
pa_buffers = []
for i, datasource in enumerate(filepaths_or_buffers):
if isinstance(datasource, NativeFile):
pa_buffers.append(datasource)
filepaths_or_buffers[i] = NativeFileDatasource(datasource)

cdef cudf_io_types.source_info source = make_source_info(
filepaths_or_buffers)

Expand Down Expand Up @@ -203,7 +211,9 @@ cpdef read_parquet(filepaths_or_buffers, columns=None, row_groups=None,
range_index_meta = index_col[0]
if row_groups is not None:
per_file_metadata = [
pa.parquet.read_metadata(s) for s in filepaths_or_buffers
pa.parquet.read_metadata(s) for s in (
pa_buffers or filepaths_or_buffers
)
]

filtered_idx = []
Expand Down
4 changes: 3 additions & 1 deletion python/cudf/cudf/tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def test_read_parquet_arrow_nativefile(s3_base, s3so, pdf, columns):
assert_eq(expect, got)


def test_read_parquet_filters(s3_base, s3so, pdf):
@pytest.mark.parametrize("python_file", [True, False])
def test_read_parquet_filters(s3_base, s3so, pdf, python_file):
fname = "test_parquet_reader_filters.parquet"
bname = "parquet"
buffer = BytesIO()
Expand All @@ -284,6 +285,7 @@ def test_read_parquet_filters(s3_base, s3so, pdf):
"s3://{}/{}".format(bname, fname),
storage_options=s3so,
filters=filters,
use_python_file_object=python_file,
)

# All row-groups should be filtered out
Expand Down