apache / arrow-nanoarrow

Helpers for Arrow C Data & Arrow C Stream interfaces
https://arrow.apache.org/nanoarrow
Apache License 2.0
172 stars 37 forks source link

[R] Sub-day precision Date class must be converted to integers by floor, not ceil #665

Open eitsupi opened 2 hours ago

eitsupi commented 2 hours ago

I noticed that the conversion of Date type with sub-day precision is not correct. arrow package has the same problem (apache/arrow#44502).

d <- as.Date(-0.1)
d
#> [1] "1969-12-31"
as.vector(nanoarrow::as_nanoarrow_array(d))
#> [1] "1970-01-01"

Created on 2024-10-22 with reprex v2.1.1

paleolimbot commented 2 hours ago

I didn't know that was possible!

The fix is probably here:

https://github.com/apache/arrow-nanoarrow/blob/4e5cd91b2945a05ec69c8835acaefe2e872de36d/r/R/as-array.R#L262-L282

eitsupi commented 2 hours ago

Thanks for quick response. Yeah, using as.integer() here seems to execute ceil, so it doesn't seem to convert as intended. (I noticed this because the same thing happened when I cast f64 to date32 type in polars)