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

Multiplying or dividing pl.duration converts to float #16514

Open
2 tasks done
thomasaarholt opened this issue May 27, 2024 · 2 comments
Open
2 tasks done

Multiplying or dividing pl.duration converts to float #16514

thomasaarholt opened this issue May 27, 2024 · 2 comments
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@thomasaarholt
Copy link
Contributor

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

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 thomasaarholt added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels May 27, 2024
@thomasaarholt
Copy link
Contributor Author

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.

@orlp orlp added P-high Priority: high and removed needs triage Awaiting prioritization by a maintainer labels Jun 3, 2024
@ritchie46
Copy link
Member

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

@ritchie46 ritchie46 added P-medium Priority: medium and removed P-high Priority: high labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

3 participants