eitsupi commented on code in PR #13890:
URL: https://github.com/apache/arrow/pull/13890#discussion_r946962040


##########
r/tests/testthat/test-dplyr-funcs-datetime.R:
##########
@@ -1899,24 +1900,52 @@ test_that("`as_datetime()`", {
         ddate2 = lubridate::as_datetime(date),
         dchar_date_no_tz = as_datetime(char_date),
         dchar_date_with_tz = as_datetime(char_date, tz = "Pacific/Marquesas"),
+        dchar_date_subsec_no_tz = as_datetime(char_date_subsec),
+        dchar_date_subsec_with_tz = as_datetime(char_date_subsec, tz = 
"Pacific/Marquesas"),
         dint_date = as_datetime(int_date, origin = "1970-01-02"),
         dintegerish_date = as_datetime(integerish_date, origin = "1970-01-02"),
-        dintegerish_date2 = as_datetime(integerish_date, origin = "1970-01-01")
+        dintegerish_date2 = as_datetime(integerish_date, origin = 
"1970-01-01"),
+        ddouble_date = as_datetime(double_date)
       ) %>%
       collect(),
     test_df
   )
 
-  # Arrow does not support conversion of double to date
-  # the below should error with an error message originating in the C++ code
+  # Arrow does not support conversion of timestamp to int32
+  # ARROW-17428
   expect_error(
     test_df %>%
       arrow_table() %>%
       mutate(
-        ddouble_date = as_datetime(double_date)
+        ddate = as_datetime(date),
+        ddate_int = as.integer(ddate)
       ) %>%
-      collect(),
-    regexp = "Float value 10.1 was truncated converting to int64"
+      compute(),
+    "Unsupported cast from timestamp\\[ns, tz=UTC\\] to int32 using function 
cast_int32"
+  )
+
+  # Arrow does not support conversion of timestamp to double
+  # ARROW-17428
+  expect_error(
+    test_df %>%
+      arrow_table() %>%
+      mutate(
+        ddate = as_datetime(date),
+        ddate_num = as.numeric(ddate)
+      ) %>%
+      compute(),
+    "Unsupported cast from timestamp\\[ns, tz=UTC\\] to double using function 
cast_double"
+  )
+
+  expect_error(
+    test_df %>%
+      arrow_table() %>%
+      mutate(
+        ddouble_date = as_datetime(double_date),
+        ddouble_date_date32 = as.Date(ddouble_date)
+      ) %>%
+      compute(),
+    "Casting from timestamp\\[ns, tz=UTC\\] to timestamp\\[s, tz=UTC\\] would 
lose data: 10100000000"

Review Comment:
   I think the cause is this line.
   I think the important thing here is the time zone and I don't think the unit 
needs to be fixed to `"s"`.
   
   
https://github.com/apache/arrow/blob/f6ad4bfe9c9e32aca4b688715eaf656a73a5f7c5/r/R/dplyr-funcs-datetime.R#L328-L330
   
   
https://github.com/apache/arrow/blob/f6ad4bfe9c9e32aca4b688715eaf656a73a5f7c5/r/R/dplyr-funcs-datetime.R#L350-L352



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to