-
Notifications
You must be signed in to change notification settings - Fork 125
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
Initial timezone support #903
Conversation
The main issue is that the new Before we were able to list literally every non-recursive dtype. That's no longer possible. Also, as discussed on slack, I'll try to make |
raise( | ||
ArgumentError, | ||
"Explorer.Series.#{function} not implemented for dtype #{inspect(dtype)}. " <> | ||
"Valid " <> Shared.inspect_dtypes(valid_dtypes, with_prefix: true) | ||
"Valid dtypes are any subtype of #{inspect(valid_super_dtypes)}" |
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.
My attempt to handle the fact that we can't list all the dtypes easily anymore. Open to ideas on this.
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 simplification makes sense to me 👍
In my opinion it is fine to nuke it. It is a very easy change for folks to update in their own apps. Alternatively, keep it as a shortcut for {:datetime |
native/explorer/src/datatypes.rs
Outdated
// TODO-BILLY: finish this. | ||
impl<'a> From<DateTime<Tz>> for ExDateTime<'a> { | ||
fn from(dt_tz: DateTime<Tz>) -> ExDateTime<'a> { | ||
let & time_zone = dt_tz.offset().tz_id(); | ||
let & zone_abbr = dt_tz.offset().abbreviation(); |
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.
@philss (or anyone!) I've hit the limit of my ability to cargo cult Rust code 😭.
The ExDateTime
struct currently looks like this:
#[derive(NifStruct, Copy, Clone, Debug)]
#[module = "DateTime"]
pub struct ExDateTime<'a> {
// ...
pub time_zone: &'a str,
// ...
pub zone_abbr: &'a str,
}
I need to derive these fields from the DateTime
object, so they're not known at compile time. AFAICT I've got two options: they can have type &'a str
or String
. I can implement this if they have type String
, but then we can no longer #[derive(Copy)]
. So I've tried to implement it with &'a str
, but I haven't figured out how yet.
Any pointers would be appreciated!
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.
Oh man, I really don't know how to solve this easily. Sorry :/
Do we need to support Copy
? I would try to use String
if we don't need this.
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.
Do we need to support
Copy
?
I dunno! I don't know what a lot of this code does... 😅
I'm gonna switch to String
. If we end up needing Copy
for some reason we can try a different approach.
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.
Ok, so we did end up needing Copy
because of how I wrote s_from_list_datetime
. Specifically, this breaks:
val: Vec<Option<ExDateTime>>
// ...
val.iter()
.map(|dt| dt.map(|dt| dt.into()))
// ^^^^^^^^^^^^^^^^^^^^^^ this implicitly requires Copy
.collect::<Vec<Option<i64>>>(),
I've reverted to &'a str
for now since all the tests pass. I suspect something we try with %DateTime{}
will eventually break because of this, but I say let's address it then.
Thoughts?
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.
No thoughts for now :/
Let's go with this version, and we improve in the future :D
raise( | ||
ArgumentError, | ||
"Explorer.Series.#{function} not implemented for dtype #{inspect(dtype)}. " <> | ||
"Valid " <> Shared.inspect_dtypes(valid_dtypes, with_prefix: true) | ||
"Valid dtypes are any subtype of #{inspect(valid_super_dtypes)}" |
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 simplification makes sense to me 👍
"temporal", | ||
"timezones", |
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.
Can we guarantee that the timezones are the same between Elixir and Rust?
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.
Great call out! No, largely because Elixir's Calendar
module is configurable. This is something which I think we'll want to be very clear about in the docs.
It also presents a validation challenge. As written, we aren't able to check that a time-zone string is valid on the Elixir side. We essentially have to assume it's fine and wait for Rust to tell us it didn't work.
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.
No problem. Yeah, I agree that if we document that, this is fine :)
native/explorer/src/datatypes.rs
Outdated
// TODO-BILLY: finish this. | ||
impl<'a> From<DateTime<Tz>> for ExDateTime<'a> { | ||
fn from(dt_tz: DateTime<Tz>) -> ExDateTime<'a> { | ||
let & time_zone = dt_tz.offset().tz_id(); | ||
let & zone_abbr = dt_tz.offset().abbreviation(); |
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.
Oh man, I really don't know how to solve this easily. Sorry :/
Do we need to support Copy
? I would try to use String
if we don't need this.
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 great addition! 🚀
Decided to go with what José suggested and nuke |
Description
Adds timezone support.
Dtype changes
New dtype:
{:datetime, precision, time_zone}
And the old naive datetime dtype has become:
{:naive_datetime, precision}
See discussion below.
To-do
%DateTime{}
literals in macrosBackward-compatibility: alias{:datetime, _}
for{:naive_datetime, _}