Copilot commented on code in PR #50203:
URL: https://github.com/apache/arrow/pull/50203#discussion_r3467910828


##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -908,13 +908,30 @@ class PyListConverter : public ListConverter<T, 
PyConverter, PyConverterTrait> {
 
   Status AppendNdarray(PyObject* value) {
     PyArrayObject* ndarray = reinterpret_cast<PyArrayObject*>(value);
-    if (PyArray_NDIM(ndarray) != 1) {
-      return Status::Invalid("Can only convert 1-dimensional array values");
-    }
     if (PyArray_ISBYTESWAPPED(ndarray)) {
       // TODO
       return Status::NotImplemented("Byte-swapped arrays not supported");
     }
+    OwnedRef flattened;
+    if (PyArray_NDIM(ndarray) != 1) {
+      // GH-49644: 0-dimensional arrays and variable-sized lists only accept
+      // 1-dimensional values.
+      if (PyArray_NDIM(ndarray) < 2 || this->list_type_->id() != 
Type::FIXED_SIZE_LIST) {
+        return Status::Invalid(
+            "Can only convert 1-dimensional array values to a variable-sized 
list");
+      }

Review Comment:
   The error message for non-1D ndarrays is now always "...to a variable-sized 
list" when `ndim < 2`, even if the target type is actually a fixed-size list 
(or fixed-size-list-backed tensor). This makes 0-D ndarray errors misleading 
and changes the prior message content for that case. Consider keeping the 
original generic message for 0-D ndarrays, and only using the 
variable-sized-list-specific message for `ndim >= 2` when the list type isn’t 
fixed-size.



-- 
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