pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
30.39k stars 1.97k forks source link

Multiplying or dividing pl.duration converts to float #16514

Open thomasaarholt opened 5 months ago

thomasaarholt commented 5 months ago

Checks

Reproducible example

print(
    pl.DataFrame({"minutes": [2]})
    .with_columns(
        duration=pl.duration(minutes="minutes"),
    )
    .with_columns(
        twiceduration=pl.col("duration") * 2.0, # <-- These become float columns
        halfduration=pl.col("duration") / 2.0, # <-- These become float columns
    )
    .with_columns(
        twiceduration_from_us=pl.duration(microseconds="twiceduration"),
        halfduration_from_us=pl.duration(microseconds="halfduration"),
    )
)

# shape: (1, 6)
# ┌─────────┬──────────────┬───────────────┬──────────────┬─────────────────────┬────────────────────┐
# │ minutes ┆ duration     ┆ twiceduration ┆ halfduration ┆ twiceduration_from_ ┆ halfduration_from_ │
# │ ---     ┆ ---          ┆ ---           ┆ ---          ┆ ns                  ┆ ns                 │
# │ i64     ┆ duration[μs] ┆ f64           ┆ f64          ┆ ---                 ┆ ---                │
# │         ┆              ┆               ┆              ┆ duration[μs]        ┆ duration[μs]       │
# ╞═════════╪══════════════╪═══════════════╪══════════════╪═════════════════════╪════════════════════╡
# │ 2       ┆ 2m           ┆ 2.4e8         ┆ 6e7          ┆ 4m                  ┆ 1m                 │
# └─────────┴──────────────┴───────────────┴──────────────┴─────────────────────┴────────────────────┘

Log output

No response

Issue description

When I divide or multiply a duration column, it converts it to a float in milliseconds.

Expected behavior

A duration type of the correct length

Installed versions

``` Replace this line with the output of pl.show_versions(). Leave the backticks in place. ```
thomasaarholt commented 5 months ago

This issue became apparent to me when I tried to add half of a duration column to a datetime column, so as to create a midpoint between a start and and end datetime.

ritchie46 commented 5 months ago

Will change the priority of this one, as we never supported this properly.