-
Notifications
You must be signed in to change notification settings - Fork 28
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
Sub-day precision Date class must be converted to integer by floor, not trunc #517
Comments
Thanks, confirmed. What behavior would you expect with such dates, given that they can't be properly represented in duckdb (or so it seems)? df1 <- tibble::tibble(
delta = c(-1.1, -0.1, 0, 0.1, 1.1),
d = as.Date(c(-1.1, -0.1, 0, 0.1, 1.1), origin = "1970-01-01"),
dd = d + 0.5,
)
df1
#> # A tibble: 5 × 3
#> delta d dd
#> <dbl> <date> <date>
#> 1 -1.1 1969-12-30 1969-12-31
#> 2 -0.1 1969-12-31 1970-01-01
#> 3 0 1970-01-01 1970-01-01
#> 4 0.1 1970-01-01 1970-01-01
#> 5 1.1 1970-01-02 1970-01-02
duckdb <- asNamespace("duckdb")
drv <- duckdb::duckdb()
con <- DBI::dbConnect(drv)
experimental <- FALSE
"select"
#> [1] "select"
rel1 <- duckdb$rel_from_df(con, df1, experimental = experimental)
"select"
#> [1] "select"
rel2 <- duckdb$rel_project(
rel1,
list(
{
tmp_expr <- duckdb$expr_reference("delta")
duckdb$expr_set_alias(tmp_expr, "delta")
tmp_expr
},
{
tmp_expr <- duckdb$expr_reference("d")
duckdb$expr_set_alias(tmp_expr, "d")
tmp_expr
},
{
tmp_expr <- duckdb$expr_reference("dd")
duckdb$expr_set_alias(tmp_expr, "dd")
tmp_expr
}
)
)
rel2
#> DuckDB Relation:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [delta as delta, d as d, dd as dd]
#> r_dataframe_scan(0x1145c1888)
#>
#> ---------------------
#> -- Result Columns --
#> ---------------------
#> - delta (DOUBLE)
#> - d (DATE)
#> - dd (DATE)
duckdb$rel_to_altrep(rel2)
#> delta d dd
#> 1 -1.1 1969-12-31 1970-01-01
#> 2 -0.1 1970-01-01 1970-01-01
#> 3 0.0 1970-01-01 1970-01-01
#> 4 0.1 1970-01-01 1970-01-01
#> 5 1.1 1970-01-02 1970-01-02 Created on 2024-10-28 with reprex v2.1.1 |
I'm sorry, but I don't understand your question. |
I see that flooring is the more correct operation here. Would you like to contribute? I'm releasing 1.1.2 very soon, but 1.1.3 is imminent. |
Sorry, but I have no experience with C++ and don't know where to fix it. |
Same as apache/arrow#44502 and apache/arrow-nanoarrow#665
Conversion of dates prior to the Posix origin is not correct.
Created on 2024-10-23 with reprex v2.1.1
With duckplyr:
Created on 2024-10-23 with reprex v2.1.1
The text was updated successfully, but these errors were encountered: