`Expr.interpolate` 会引发异常或默默地为非数值 dtype 留下空值
作者: ajohnson5创建于 2026年9月29日更新于 2026年9月30日
标签bugpythonneeds triageA-panic
Panic with expr.interpolate for bool dtype & linear method
lf = pl.LazyFrame({"a":[True, None, False]})
lf.with_columns(pl.col("a").interpolate()).collect(engine="streaming")
# thread '<unnamed>' (4427604) panicked at crates/polars-core/src/frame/mod.rs:708:42:
# should not fail: SchemaMismatch(ErrString("type Boolean is incompatible with expected type Float64"))
[!Note] This example must have a
Nullin. The example below does not panic (however note, the dtype of the output has been cast topl.Float64. I believe this is the reason for the panic.lf = pl.LazyFrame({"a":[True, False]}) lf.with_columns(pl.col("a").interpolate()).collect(engine="streaming")
Panic with expr.interpolate for bool dtype & nearest method
lf = pl.LazyFrame({"a":[True, None, False]})
lf.with_columns(pl.col("a").interpolate("nearest")).collect(engine="streaming")
# thread 'async-executor-5' (4427945) panicked at crates/polars-ops/src/series/ops/interpolation/interpolate.rs:124:23:
# not implemented for BooleanSilently leaves nulls for bool type
df = pl.DataFrame({"a":[True, None, False]})
df.with_columns(pl.col("a").interpolate())
日志输出
thread '<unnamed>' (4427604) panicked at crates/polars-core/src/frame/mod.rs:708:42:
should not fail: SchemaMismatch(ErrString("type Boolean is incompatible with expected type Float64"))问题描述
[!Note] 完全披露我最初使用 AI 找到这个错误,它在流式引擎中找到了 Boolean dtype 的
expr.interpolate()发生崩溃。 我继续"手动"地挖掘,并找到了以下其他不一致的情况。expr.interpolate目前对于非数值 dtype 要么会发生崩溃,要么会默默无声地不做任何事情。 此行为取决于所使用的method、dtype 和引擎。 根据我所了解的,有三种不同的情况如下,我也附上了一个详细说明所有问题的表。
案例
- 由于 schema 不匹配而发生崩溃(流式 Boolean)
- 使用“未实现”错误的“最近”方法而发生崩溃
- 默默的不正确行为
| dtype | interpolate() 内存中 |
interpolate() 流式 |
interpolate("nearest") 内存中 |
interpolate("nearest") 流式 |
|---|---|---|---|---|
| Int8–Int128, UInt8–UInt128 | 正确 | 正确 | 正确 | 正确 |
| Float16 / Float32 / Float64 | 正确 | 正确 | 正确 | 正确 |
| Decimal | 正确 | 正确 | 正确 | 正确 |
| Date / Datetime / Duration / Time | 正确 | 正确 | 正确 | 正确 |
| Boolean | 不正确(未更改) | 发生崩溃(如果列包含 null,则转换为 Float64) |
发生崩溃 | 发生崩溃 |
| String | 不正确(未更改)… |
内容来源: pola-rs/polars