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

Add casts and string to datetime conversion #27

Merged
merged 25 commits into from
Oct 1, 2024
Merged

Add casts and string to datetime conversion #27

merged 25 commits into from
Oct 1, 2024

Conversation

finn-rudolph
Copy link
Contributor

We have casts for the following pairs of types now:

(dtypes.String, dtypes.Int),
(dtypes.String, dtypes.Float64),
(dtypes.Float64, dtypes.Int),
(dtypes.DateTime, dtypes.Date),
(dtypes.Int, dtypes.String),
(dtypes.Float64, dtypes.String),
(dtypes.DateTime, dtypes.String),
(dtypes.Date, dtypes.String),

We do not consider string to datetime conversion a cast (polars also does not do this), but have .str.to_datetime() and .str.to_date() methods instead. These will support a format parameter in the future. Currently they accept YY-MM-DD HH:MM:SS:MILLIS only. For float to string, we only guarantee equivalence up to trailing zeros. Float to int conversion throws on inf / nan, except for Sqlite (it does not throw on itself, and transform cannot do this).

disallow string to bool casts
we always truncate, like in C
polars does not write them properly to the database
we do not guarantte equivalence here (e.g. 0.0 vs 0), but we guarantee that a
sequence of casts Float64 -> String -> Float64 is the identity (up to some
epsilon).
so that e.g. mssql can return DATETIME2 instead of DATETIME
we currently only guarantee this to work for datetimes of the form
YYYY-MM-DD HH:MM:SS.MILLIS (yes, exactly six digits after the comma, which makes
sense since we guarantee all operations on datetimes on millisecond precision)
we allow __eq__ between a dtype instance and a dtype class. When comparing with
a class, const and vararg are ignored.
@finn-rudolph finn-rudolph requested a review from a team as a code owner September 30, 2024 13:59
@finn-rudolph finn-rudolph merged commit 46ed4fe into main Oct 1, 2024
3 of 6 checks passed
@finn-rudolph finn-rudolph deleted the cast branch October 1, 2024 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant