pola-rs/polars · error · ValueError
Cannot infer partition value from Parquet metadata for…
Error message
Cannot infer partition value from Parquet metadata for partition field '{field.name}': {lower_value=}, {upper_value=} What it means
_infer_partition_from_statistics tries to derive a partition value from Parquet column statistics (min == max). When lower_value != upper_value the column contains multiple distinct values in one file, so a single partition value cannot be inferred and polars raises ValueError.
Solutions
- Repartition/sort the DataFrame by the partition columns before sinking so each file holds a single partition value (e.g. df.sort(partition_cols) or use sink's own partitioning).
- Disable statistics-based partition inference and supply partition values explicitly in the sink metadata.
- Ensure the upstream pipeline groups data by partition key before writing files.
Example fix
// before
df.sink_iceberg(target, partition_by=["date"]) # files mix dates
// after
df.sort("date").sink_iceberg(target, partition_by=["date"]) Defensive patterns
Strategy: validation
Validate before calling
df = df.sort(partition_cols) # ensure one partition value per output file
Type guard
def files_are_partition_aligned(df, cols: list[str]) -> bool:
return df.select(cols).n_unique() == 1 or False Try / catch
try:
df.sink_iceberg(target, partition_by=cols)
except ValueError as e:
if "Cannot infer partition value" in str(e):
df.sort(cols).sink_iceberg(target, partition_by=cols)
else:
raise Prevention
- Sort or repartition by partition columns so each Parquet file maps to one partition value.
- Don't mix pre-existing heterogeneous files into metadata-driven partition inference.
- Test sink pipelines with data spanning multiple partitions.
When it happens
Trigger: Using the Iceberg sink with partition inference from metadata where a data file's partition-source column has varying values — e.g. rows in one file span multiple partition keys, so parquet min/max differ.
Common situations: Writing non-repartitioned data to a partitioned Iceberg table without sorting, so each output file mixes partition values; pre-existing Parquet files that were not partition-aligned.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Expected Statistics to be
- native sink row count
- partition source field
- schema_mode='overwrite' is not supported for partitioned…
- sink to Iceberg table with partition field
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/1b4a076dabea5154.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/io/iceberg/_sink.py:109
if aggregate is None:
partition_values.append(None)
continue
source_type = schema.find_field(field.source_id).field_type
transform = field.transform.transform(source_type)
lower_value = transform(
partition_record_value(field, aggregate.current_min, schema)
)
upper_value = transform(
partition_record_value(field, aggregate.current_max, schema)
)
# A file can contain different source values in one transformed partition.
if lower_value != upper_value:
msg = (
"Cannot infer partition value from Parquet metadata for partition "
f"field '{field.name}': {lower_value=}, {upper_value=}"
)
raise ValueError(msg)
partition_values.append(lower_value)
return Record(*partition_values)
def _temporal_transform_expr(
expr: pl.Expr, source_type: IcebergType, transform: Transform[Any, Any]
) -> pl.Expr:
from pyiceberg.transforms import DayTransform, MonthTransform, YearTransform
import polars as pl
if type(source_type).__name__ in {"TimestamptzType", "TimestamptzNanoType"}:
expr = expr.dt.convert_time_zone("UTC")
if isinstance(transform, YearTransform):
return expr.dt.year() - 1970
if isinstance(transform, MonthTransform):View on GitHub (pinned to fe841f959e)