apache / apache/arrow

[Python][Parquet] pyarrow.parquet.ParquetFile.metadata shows deprecated min/max only not min_value/max_value

Open
#37,604 6 comments 0 reactions 0 assignees View on GitHub
Component: Python Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

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

If I do

```
import polars as pl
import pyarrow.parquet as pq
df=pl.DataFrame({'a':[1,2,3]})
df.write_parquet("blah.parquet", statistics=True)
pq.ParquetFile("blah.parquet").metadata.row_group(0).column(0)
# is_stats_set: True
# statistics:
#
# has_min_max: False
# min: None
# max: None
# null_count: 0
# distinct_count: 0
# num_values: 3
# physical_type: INT64
# logical_type: None
# converted_type (legacy): NONE
```

This is just showing that there is no min/max but I was [under the impression that pyarrow favors min_value/max_value and only uses min/max as a fallback if min_value/max_value are missing](https://github.com/apache/arrow/issues/34180#issuecomment-1431338126). Perhaps it does that in predicate pushdown but the metadata that it reports here should either include both sets of statistics or use the same behavior.

For instance from the cli

```
parquet-tools inspect blah.parquet --detail
■■■■■■■■■■■■■■■■■■■■■■■■statistics = Statistics
■■■■■■■■■■■■■■■■■■■■■■■■■■■■max_value = b'\x03\x00\x00\x00\x00\x00\x00\x00'
■■■■■■■■■■■■■■■■■■■■■■■■■■■■min_value = b'\x01\x00\x00\x00\x00\x00\x00\x00'
```

shows that the file does indeed have its min_value and max_value set.

If I save the file with pyarrow and then use parquet-tools on it...

```
pq.write_table(df.to_arrow(), "blahpa.parquet", compression='zstd')
###then in cli
parquet-tools inspect blahpa.parquet --detail
■■■■■■■■■■■■■■■■■■■■■■■■statistics = Statistics
■■■■■■■■■■■■■■■■■■■■■■■■■■■■max = b'\x03\x00\x00\x00\x00\x00\x00\x00'
■■■■■■■■■■■■■■■■■■■■■■■■■■■■min = b'\x01\x00\x00\x00\x00\x00\x00\x00'
■■■■■■■■■■■■■■■■■■■■■■■■■■■■max_value = b'\x03\x00\x00\x00\x00\x00\x00\x00'
■■■■■■■■■■■■■■■■■■■■■■■■■■■■min_value = b'\x01\x00\x00\x00\x00\x00\x00\x00'
```

so pyarrow is writing both sets of stats and apparently, at least for the purpose of pq.metadata, only reporting the deprecated stats. It probably could/should stop writing the deprecated stats and the metadata reporting tool should show and make use of the new stats.

### Component(s)

Python

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.