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

Strict cast of Duration/Datetime to higher precision may overflow #14655

Open
2 tasks done
stinodego opened this issue Feb 23, 2024 · 0 comments
Open
2 tasks done

Strict cast of Duration/Datetime to higher precision may overflow #14655

stinodego opened this issue Feb 23, 2024 · 0 comments
Labels
A-arithmetic Area: arithmetic A-timeseries Area: date/time functionality bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@stinodego
Copy link
Member

stinodego commented Feb 23, 2024

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

import polars as pl

s = pl.Series([2**63 - 1], dtype=pl.Duration)
r = s.cast(pl.Duration("ns"))
print(r)

Log output

shape: (1,)
Series: '' [duration[ns]]
[
        -1µs
]

Issue description

Strict casting should protect against overflows, but it doesn't in this case.

The issue is that this cast multiplies the underlying physical value by 1000. Since our arithmetic currently does not do overflow checks, we have no way to enforce a strict cast here.

Expected behavior

An error (ComputeError?).

Non-strict cast should result in null.

Installed versions

main

@stinodego stinodego added bug Something isn't working python Related to Python Polars A-timeseries Area: date/time functionality P-low Priority: low A-arithmetic Area: arithmetic labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-arithmetic Area: arithmetic A-timeseries Area: date/time functionality bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

1 participant