Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

floor_div runtime error for i64, u32 and u64 #17238

Open
2 tasks done
TitouanReal opened this issue Jun 27, 2024 · 2 comments
Open
2 tasks done

floor_div runtime error for i64, u32 and u64 #17238

TitouanReal opened this issue Jun 27, 2024 · 2 comments
Labels
A-arithmetic Area: arithmetic A-panic Area: code that results in panic exceptions bug Something isn't working regression Issue introduced by a new release rust Related to Rust Polars

Comments

@TitouanReal
Copy link

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

use polars::df;
use polars::prelude::*;

fn main() {
    let df = df![
        "seconds" => [0u64],
    ]
    .unwrap();

    let new_df = df
        .lazy()
        .with_column(col("seconds").floor_div(lit(1u64)))
        .collect()
        .unwrap();

    println!("{new_df:?}");
}

Log output

run StackExec
thread 'main' panicked at /home/titouan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-core-0.41.2/src/series/mod.rs:956:13:
implementation error, cannot get ref UInt64 from Int32

Issue description

The example given above worked in version 0.39.2, but it is broken from 0.40.0 and onwards.

Variations of this error appear when using u64 (given example), u32, and i64, with the error becoming:

  • implementation error, cannot get ref UInt64 from Int32,
  • implementation error, cannot get ref UInt32 from Int32,
  • implementation error, cannot get ref Int64 from Int32,

respectively.

Expected behavior

In version 0.39.2, the example works and outputs :

shape: (1, 1)
┌─────────┐
│ seconds │
│ --- │
│ u64 │
╞═════════╡
│ 0 │
└─────────┘

which is the expected output.

Installed versions

[dependencies.polars]
version = "0.41"
default-features = false
features = ["fmt", "lazy", "round_series"]
@TitouanReal TitouanReal added bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars labels Jun 27, 2024
@stinodego stinodego added regression Issue introduced by a new release A-arithmetic Area: arithmetic labels Jun 27, 2024
@TitouanReal
Copy link
Author

A solution to make this work is to use the following code instead:

use polars::df;
use polars::prelude::*;

fn main() {
    let df = df![
        "seconds" => [0u64],
    ]
    .unwrap();

    let new_df = df
        .lazy()
        .with_column((col("seconds") / lit(1u64)).floor().cast(DataType::UInt64))
        .collect()
        .unwrap();

    println!("{new_df:?}");
}

Note that this solution, while working in 0.41, panics in version 0.39.

The performance might be degraded compared to the code proposed in the issue description, but at least it doesn't panic, and it shows the expected behavior.

@coastalwhite coastalwhite added A-panic Area: code that results in panic exceptions and removed needs triage Awaiting prioritization by a maintainer labels Jul 7, 2024
@TitouanReal
Copy link
Author

I can confirm that this panic still occurs in 0.42.0 and 0.43.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-arithmetic Area: arithmetic A-panic Area: code that results in panic exceptions bug Something isn't working regression Issue introduced by a new release rust Related to Rust Polars
Projects
None yet
Development

No branches or pull requests

3 participants