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

feat: Allow subtraction of time dtype columns #20300

Merged
merged 6 commits into from
Dec 15, 2024
Merged

Conversation

ptiza
Copy link
Contributor

@ptiza ptiza commented Dec 14, 2024

Closes #19720

Since the documentation specifies the Time dtype as

The underlying representation of this type is a 64-bit signed integer. The integer indicates the number of nanoseconds since midnight.

we can specify the result of a substraction as a duration with nanosecond time unit.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Dec 14, 2024
Copy link

codecov bot commented Dec 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.59%. Comparing base (bcca075) to head (32a2475).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20300      +/-   ##
==========================================
- Coverage   79.60%   79.59%   -0.02%     
==========================================
  Files        1565     1566       +1     
  Lines      218396   218322      -74     
  Branches     2477     2465      -12     
==========================================
- Hits       173860   173778      -82     
- Misses      43970    43975       +5     
- Partials      566      569       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ptiza ptiza marked this pull request as ready for review December 14, 2024 20:12
@ritchie46 ritchie46 merged commit 0c2eb01 into pola-rs:main Dec 15, 2024
24 checks passed
@ptiza ptiza deleted the timedev branch December 15, 2024 10:41
@alexander-beedie alexander-beedie changed the title feat: Allow substraction of time dtype columns feat: Allow subtraction of time dtype columns Dec 24, 2024
@mcrumiller
Copy link
Contributor

What about the inverse? If we have t2 - t1 = d, how about t1 + d = t2, i.e. time + duration?

@ptiza
Copy link
Contributor Author

ptiza commented Dec 24, 2024

What about the inverse? If we have t2 - t1 = d, how about t1 + d = t2, i.e. time + duration?

I considered implementing it within this PR but thought it's ultimately another feature.

It also needs to be discussed which behavior we want if d > 24h. Should we even allow it?
If d is the result of a substraction of two Time objects, then the resulting duration is always within 24h.

@mcrumiller
Copy link
Contributor

I recall a while back during some AnyValue conversion that @stinodego came up with a set of rules regarding what temporal ops are allowed.

t2 - t1 will always be a well-defined duration value <= 24hr, but t + d may be out-out-bounds and so perhaps is not as well-defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can´t subtract two time columns
3 participants