Skip to content

[C++][Python] iter_batches on a parquet file with zero row groups fails in pyarrow>=18 #45009

Closed

Description

@cedriccuypers

Describe the bug, including details regarding any error messages, version, and platform.

We noticed a bug in pyarrow when we were trying to iterate in batches over parquet files, of which some had zero row groups (output of the AWS S3 Inventory service).

Code snippet to reproduce the issue:

import fastparquet
import pandas as pd
import pyarrow
import pyarrow.parquet as pq

print(f"Using pyarrow version {pyarrow.__version__}")

df = pd.DataFrame({"a": pd.Series(dtype="int"), "b": pd.Series(dtype="str"), "c": pd.Series(dtype="float")})

empty_parquet_file_path = "my_empty_parquet_file.parquet"

fastparquet.write(empty_parquet_file_path, df, row_group_offsets=[])

assert pq.read_metadata(empty_parquet_file_path).num_row_groups == 0

parquet_file = pq.ParquetFile(empty_parquet_file_path)

for batch in parquet_file.iter_batches():
    print(batch)

The following error is raised when using pyarrow 18.0.0 or 18.1.0.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pyarrow/_parquet.pyx", line 1634, in iter_batches
  File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
OSError: The file only has 0 row groups, requested metadata for row group: -1

In pyarrow 17, there is no issue, and an empty parquet file doesn't seem to produce any batches when calling iter_batches, which is the behaviour I would expect.

Component(s)

Python

Activity

  1. brendanyounger commented on Jan 7, 2025

    @brendanyounger

    I would like to second this. This is a bug in the core cpp parquet source code which, as the OP points out, was not present in any previous version.

  2. thras-deepcure commented on Feb 13, 2025

    @thras-deepcure

    This issue persists with pyarrow 19.0.0

  3. mjtieman commented on Feb 13, 2025

    @mjtieman

    +1

  4. binaryaaron commented on Feb 25, 2025

    @binaryaaron
  5. changed the title [-]iter_batches on a parquet file with zero row groups fails in pyarrow>=18[/-] [+][C++][Python] iter_batches on a parquet file with zero row groups fails in pyarrow>=18[/+] on Jun 23, 2026
  6. AlenkaF commented on Jun 23, 2026

    @AlenkaF
    Member

    Confirming this is fixed in newer versions, most probably with #45350.
    I have tested on latest main:

    >>> import pyarrow.parquet as pq
    >>> import pyarrow as pa
    
    >>> pa.__version__
    '25.0.0.dev175+g8f3085e35.d20260623'
    
    >>> table = pa.table({'one': [-1, None, 2.5],
    ...                   'two': ['foo', 'bar', 'baz'],
    ...                   'three': [True, False, True]})
    
    >>> with pq.ParquetWriter('example_empty.parquet', table.schema) as writer:
    ...     pass
    ... 
    
    >>> parquet_file = pq.ParquetFile('example_empty.parquet')
    >>> for batch in parquet_file.iter_batches():
    ...     print(batch)
    ... 
    
    >>> parquet_file.num_row_groups
    0
    >>> list(parquet_file.iter_batches())
    []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions