`pl.date` over hive keys stops partition pruning when combined with an in-file predicate
Checks
- I have checked that this issue has not already been reported.
- I have confirmed this bug exists on the latest version of Polars.
Reproducible example
import datetime
import pathlib
import tempfile
import polars as pl
root = pathlib.Path(tempfile.mkdtemp())
for month in (1, 2):
path = root / "year=2026" / f"month={month}" / "0.parquet"
path.parent.mkdir(parents=True)
pl.DataFrame({"flag": [True, False]}).write_parquet(path)
# Only an unpruned scan opens this file.
(root / "year=2026" / "month=2" / "0.parquet").write_bytes(b"not parquet")
as_date = pl.date("year", "month", 1) <= datetime.date(2026, 1, 1)
as_int = pl.col("year") * 100 + pl.col("month") <= 202601
in_file = pl.col("flag")
for name, predicates in {
"pl.date alone": [as_date],
"integer + in-file": [as_int, in_file],
"pl.date + in-file": [as_date, in_file],
}.items():
lf = pl.scan_parquet(root / "**/*.parquet", hive_partitioning=True)
try:
lf.filter(*predicates).collect()
print(f"{name}: pruned")
except pl.exceptions.ComputeError as exc:
print(f"{name}: read the excluded file ({exc})")pl.date alone: pruned
integer + in-file: pruned
pl.date + in-file: read the excluded file (parquet: File out of specification: expected parquet magic bytes "PAR1" in footer, got "quet" instead)Log output
With POLARS_VERBOSE=1 and a valid second file. pl.date alone skips the second file by its hive keys:
initialize_scan_predicate: Source filter mask initialization via hive partitions
initialize_scan_predicate: Predicate pushdown allows skipping 1 / 2 files
apply_scan_predicate_to_scan_ir: PredicateFileSkip { no_residual_predicate: true, original_len: 2 }So does the integer form combined with the in-file predicate:
initialize_scan_predicate: Source filter mask initialization via hive partitions
initialize_scan_predicate: Predicate pushdown allows skipping 1 / 2 files
apply_scan_predicate_to_scan_ir: PredicateFileSkip { no_residual_predicate: false, original_len: 2 }
[ParquetFileReader]: Predicate pushdown: reading 1 / 1 row groupspl.date combined with the in-file predicate never initialises the hive filter mask, and decodes both files:
[MultiScanTaskInit]: predicate: Some("<predicate>"), deletion_files: None, skip files mask: None, predicate to reader: Some("<predicate>")
[ParquetFileReader]: Predicate pushdown: reading 1 / 1 row groups
[ParquetFileReader]: Predicate pushdown: reading 1 / 1 row groupsIssue description
A predicate that builds a date from hive keys with pl.date(...) prunes files on its own, but not once it is combined with a predicate on an in-file column. Polars then opens every file in the dataset, and where row-group statistics cannot exclude the rows, as with flag here, it decodes them too. Spelling the same bound as integer arithmetic over the keys prunes in both cases.
The combination is the common one: a hive bound written by a library function and a filter the caller adds downstream.
This looks like #21472, where str.ends_with in the second filter had the same effect. There the cause was an expression missing from SkipBatchPredicate; pl.date may be missing in the same way.
Expected behavior
pl.date(...) <= d combined with an in-file predicate skips the partitions the hive keys exclude, as it does alone and as the integer form does in combination.
Installed versions
--------Version info---------
Polars: 1.44.2
Index type: UInt32
Platform: macOS-26.6.2-arm64-arm-64bit-Mach-O
Python: 3.14.7 | packaged by conda-forge | (main, Sep 2 2026, 21:04:32) [Clang 20.1.8 ]
Runtime: rt32The issue text and minimal example were drafted with the help of an LLM; the example output and logs above come from running it on the versions listed.
Source: pola-rs/polars