datasets icon indicating copy to clipboard operation
datasets copied to clipboard

Parquet file with an empty row group fails to load: `ArrowInvalid: BatchSize must be greater than 0`

Open Sriram-PR opened this issue 2 months ago • 1 comments

Describe the bug

If a parquet file's first row group has 0 rows, the parquet builder can't read it. pandas writes an empty DataFrame exactly like that (df.iloc[0:0].to_parquet(...) gives one row group with 0 rows), so a single empty shard in a folder of otherwise normal files breaks load_dataset for the whole dataset, in both regular and streaming mode.

It also happens when the empty row group is just the first one and real data follows it in the same file, so that data can't be loaded at all.

The cause is in src/datasets/packaged_modules/parquet/parquet.py:

batch_size = self.config.batch_size or parquet_fragment.row_groups[0].num_rows

That's 0 for these files, and pyarrow rejects to_batches(batch_size=0). folder_based_builder.py has the same line for metadata.parquet files.

Steps to reproduce the bug

import pandas as pd
import pyarrow as pa
import pyarrow.parquet as pq
from datasets import load_dataset

pd.DataFrame({"a": [1, 2, 3]}).to_parquet("full.parquet")
pd.DataFrame({"a": [1]}).iloc[0:0].to_parquet("empty.parquet")  # 1 row group, 0 rows

load_dataset("parquet", data_files=["full.parquet", "empty.parquet"])
# DatasetGenerationError, caused by ArrowInvalid: BatchSize must be greater than 0, got 0

load_dataset("parquet", data_files=["full.parquet", "empty.parquet"], streaming=True)["train"]
# iterating raises ArrowInvalid: BatchSize must be greater than 0, got 0

# empty first row group followed by data
with pq.ParquetWriter("mixed.parquet", pa.schema([("a", pa.int64())])) as w:
    w.write_table(pa.table({"a": pa.array([], type=pa.int64())}))
    w.write_table(pa.table({"a": [7, 8]}))
load_dataset("parquet", data_files="mixed.parquet")
# same ArrowInvalid

The order of the files doesn't matter, the empty one can be first or last.

Expected behavior

Empty row groups are skipped. The first two loads give the 3 rows from full.parquet, and mixed.parquet gives [7, 8].

Environment info

  • datasets version: 5.0.2.dev0 (main at 7f58239), same on 5.0.1
  • Platform: Linux-7.2.8-200.fc44.x86_64-x86_64-with-glibc2.43
  • Python version: 3.11.16
  • huggingface_hub version: 1.33.0
  • PyArrow version: 25.0.1
  • Pandas version: 3.0.6
  • fsspec version: 2026.7.0

Sriram-PR avatar Oct 05 '26 15:10 Sriram-PR

#self-assign

Sriram-PR avatar Oct 05 '26 15:10 Sriram-PR