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

Align parquet filtering behavior with dask.dataframe #795

Merged
merged 4 commits into from
Jan 29, 2024
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
18 changes: 10 additions & 8 deletions dask_expr/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ParquetFunctionWrapper,
ToParquetFunctionWrapper,
aggregate_row_groups,
apply_filters,
get_engine,
set_index_columns,
sorted_columns,
Expand Down Expand Up @@ -555,6 +556,7 @@ def _dataset_info(self):
dataset_info["base_meta"] = meta
dataset_info["index"] = index
dataset_info["all_columns"] = all_columns
dataset_info["calculate_divisions"] = self.calculate_divisions

return dataset_info

Expand Down Expand Up @@ -600,10 +602,12 @@ def _plan(self):
# Use statistics to aggregate partitions
parts, stats = _aggregate_row_groups(parts, stats, dataset_info)

# Drop filtered partitions (aligns with `dask.dataframe` behavior)
if self.filters and stats:
parts, stats = apply_filters(parts, stats, self.filters)

# Use statistics to calculate divisions
divisions = _calculate_divisions(
stats, dataset_info, len(parts), self.filters
)
divisions = _calculate_divisions(stats, dataset_info, len(parts))

empty = False
if len(divisions) < 2:
Expand Down Expand Up @@ -726,15 +730,13 @@ def _aggregate_row_groups(parts, statistics, dataset_info):
return parts, statistics


def _calculate_divisions(statistics, dataset_info, npartitions, filters):
def _calculate_divisions(statistics, dataset_info, npartitions):
# Use statistics to define divisions
divisions = None
if statistics:
calculate_divisions = dataset_info["kwargs"].get("calculate_divisions", None)
if statistics and dataset_info.get("gather_statistics", False):
calculate_divisions = dataset_info.get("calculate_divisions", None)
index = dataset_info["index"]
process_columns = index if index and len(index) == 1 else None
if filters:
process_columns = None
if (calculate_divisions is not False) and process_columns:
for sorted_column_info in sorted_columns(
statistics, columns=process_columns
Expand Down
Loading