You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

rust-polars 0.35.4中fill_null致datetime转i64?疑似Bug

Rust-Polars 0.35.4:fill_null导致日期类型转为i64的疑问

我运行了以下基于Rust-Polars 0.35.4版本的代码:

use polars::prelude::*;
use chrono::prelude::*;

let df = df!(
        "date" => date_range("date",
            NaiveDate::from_ymd_opt(2022, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(), NaiveDate::from_ymd_opt(2022, 1, 5).unwrap().and_hms_opt(0, 0, 0).unwrap(), Duration::parse("1d"),ClosedWindow::Both, TimeUnit::Milliseconds, None)?,
        "sales" => &[1, 2, 3, 4,5],
)?;

let period:usize = 3;
let duration_str = format!("{}{}",period.to_string().as_str(),"i");
let rolling_options = RollingOptions {
    window_size : Duration::parse(duration_str.as_str()),
    min_periods : period,
    ..Default::default()
};

let period = 3;

let mut lf = df.lazy().with_column(concat_expr([col("sales").slice(0,period).rolling_mean(rolling_options), 
    col("sales").slice(period,lit(Null {}))], false)?.alias("con"));

println!("{}", lf.clone().collect().unwrap());

lf = lf.clone().fill_null(0);

println!("{}", lf.clone().collect().unwrap());

实际输出

第一次打印结果(fill_null前):

shape: (5, 3)
┌─────────────────────┬───────┬──────┐
│ date                ┆ sales ┆ con  │
│ ---                 ┆ ---   ┆ ---  │
│ datetime[ms]        ┆ i32   ┆ f64  │
╞═════════════════════╪═══════╪══════╡
│ 2022-01-01 00:00:00 ┆ 1     ┆ null │
│ 2022-01-02 00:00:00 ┆ 2     ┆ null │
│ 2022-01-03 00:00:00 ┆ 3     ┆ 2.0  │
│ 2022-01-04 00:00:00 ┆ 4     ┆ 4.0  │
│ 2022-01-05 00:00:00 ┆ 5     ┆ 5.0  │
└─────────────────────┴───────┴──────┘

第二次打印结果(fill_null后):

shape: (5, 3)
┌───────────────┬───────┬─────┐
│ date          ┆ sales ┆ con │
│ ---           ┆ ---   ┆ --- │
│ i64           ┆ i32   ┆ f64 │
╞═══════════════╪═══════╪═════╡
│ 1640995200000 ┆ 1     ┆ 0.0 │
│ 1641081600000 ┆ 2     ┆ 0.0 │
│ 1641168000000 ┆ 3     ┆ 2.0 │
│ 1641254400000 ┆ 4     ┆ 4.0 │
│ 1641340800000 ┆ 5     ┆ 5.0 │
└───────────────┴───────┴─────┘

预期输出

我预期调用fill_null后,仅con列的null值被填充为0.0,date列保持原有的datetime[ms]类型:

shape: (5, 3)
┌─────────────────────┬───────┬──────┐
│ date                ┆ sales ┆ con  │
│ ---                 ┆ ---   ┆ ---  │
│ datetime[ms]        ┆ i32   ┆ f64  │
╞═════════════════════╪═══════╪══════╡
│ 2022-01-01 00:00:00 ┆ 1     ┆ 0.0  │
│ 2022-01-02 00:00:00 ┆ 2     ┆ 0.0  │
│ 2022-01-03 00:00:00 ┆ 3     ┆ 2.0  │
│ 2022-01-04 00:00:00 ┆ 4     ┆ 4.0  │
│ 2022-01-05 00:00:00 ┆ 5     ┆ 5.0  │
└─────────────────────┴───────┴──────┘

想确认这是我的操作失误,还是Rust-Polars存在疑似Bug?


内容的提问来源于stack exchange,提问作者Akash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:42:33