-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: .dt.time() was panicking for datetimes prior to unix epoch #13812
Conversation
assert result.flags["SORTED_ASC"] is False | ||
assert result.flags["SORTED_DESC"] is False | ||
assert result.flags["SORTED_ASC"] | ||
assert not result.flags["SORTED_DESC"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one should've been sorted to begin with, but that's already being dealt with in #13808
.into_time() | ||
.into_series()), | ||
TimeUnit::Nanoseconds => { | ||
let ca = self.0.apply_values(|v| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I timed this separately, and apply_values
is faster here than apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit more concise (I'm always looking to reduce code length) and possibly faster since it removes the if
branch (although maybe a premature optimization). Also I think we're already at i64
so we can remove the extra .cast(&Int64).unwrap()
.
#[cfg(feature = "dtype-time")]
(Datetime(tu, _), Time) => Ok({
let (modder, multiplier) = match tu {
TimeUnit::Nanoseconds => (NS_IN_DAY, 1i64),
TimeUnit::Microseconds => (US_IN_DAY, 1_000i64),
TimeUnit::Milliseconds => (MS_IN_DAY, 1_000_000i64),
};
self.0
.apply_values(|v| (v % modder * multiplier) + (NS_IN_DAY * (v < 0) as i64))
.into_time()
.into_series()
}),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thinks this is a nice improvement. @mcrumiller 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup - @mcrumiller fancy opening a PR to my PR, so you're included in the commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure (although I don't care about the cred)--need to figure out how to check out a branch on another fork first.
Edit: I used git remote add <Marco's fork url>
followed by a checkout of his branch. Not sure if that's the best way to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good learning experience then :) but yes, that's how I'd have done it
alternatively,
git checkout -b pr/marcogorelli/man-on-the-moon
git fetch marcogorelli
git reset --hard marcogorelli/man-on-the-moon
<do your changes>
git push -U marcogorelli HEAD:man-on-the-moon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: w00t
@@ -81,21 +81,39 @@ impl LogicalType for DatetimeChunked { | |||
}, | |||
#[cfg(feature = "dtype-time")] | |||
(Datetime(tu, _), Time) => match tu { | |||
TimeUnit::Nanoseconds => Ok((self.0.as_ref() % NS_IN_DAY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue with the current implementation is that self.0.as_ref() % NS_IN_DAY
might return a negative value
fix(rust): simplify impl of datetime cast
…-rs#13812) Co-authored-by: Marshall Crumiller <mcrumiller@gmail.com>
closes #13801