You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/02/07 17:42:01 UTC

[GitHub] [arrow] pitrou commented on a change in pull request #12348: ARROW-15080: [Python][C++] Enable tuples conversion to interval

pitrou commented on a change in pull request #12348:
URL: https://github.com/apache/arrow/pull/12348#discussion_r800901189



##########
File path: cpp/src/arrow/python/python_to_arrow.cc
##########
@@ -416,8 +416,18 @@ class PyValue {
     }
     RETURN_NOT_OK(PopulateMonthDayNano<MonthDayNanoField::kNanoseconds>::Field(
         obj, &output.nanoseconds, &found_attrs));
-
     if (ARROW_PREDICT_FALSE(!found_attrs) && !is_date_offset) {
+      if (PyTuple_Check(obj) && PyTuple_Size(obj) == 3) {
+        RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 0), &output.months,
+                                               "Months (Index 0) index to large"));
+        RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 1), &output.days,
+                                               "Days (Index 1) index to large"));
+        RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 2),
+                                               &output.nanoseconds,
+                                               "Nanoseconds (Index 2) index to large"));
+        return output;
+      }
+
       // date_offset can have zero fields.

Review comment:
       Move this comment before the enclosing `if`?

##########
File path: cpp/src/arrow/python/python_to_arrow.cc
##########
@@ -416,8 +416,18 @@ class PyValue {
     }
     RETURN_NOT_OK(PopulateMonthDayNano<MonthDayNanoField::kNanoseconds>::Field(
         obj, &output.nanoseconds, &found_attrs));
-
     if (ARROW_PREDICT_FALSE(!found_attrs) && !is_date_offset) {
+      if (PyTuple_Check(obj) && PyTuple_Size(obj) == 3) {
+        RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 0), &output.months,
+                                               "Months (Index 0) index to large"));
+        RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 1), &output.days,
+                                               "Days (Index 1) index to large"));
+        RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 2),
+                                               &output.nanoseconds,
+                                               "Nanoseconds (Index 2) index to large"));

Review comment:
       Wording suggestion:
   ```suggestion
           RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 0), &output.months,
                                                  "Months (tuple item #0) too large"));
           RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 1), &output.days,
                                                  "Days (tuple item #1) too large"));
           RETURN_NOT_OK(internal::CIntFromPython(PyTuple_GET_ITEM(obj, 2),
                                                  &output.nanoseconds,
                                                  "Nanoseconds (tuple item #2) too large"));
   ```




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org