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


##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -908,13 +908,33 @@ 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: variable-sized lists only accept 1-dimensional values, and
+      // 0-dimensional arrays are still rejected.
+      if (PyArray_NDIM(ndarray) < 2) {
+        return Status::Invalid("Can only convert 1-dimensional array values");
+      }

Review Comment:
   You're effectively rejecting `ndim == 0` here. [As per 
docs](https://numpy.org/devdocs/reference/c-api/types-and-structures.html#c.NPY_AO.nd)
 ndim is always between 0 and 64. Do we need to reject `ndim == 0`? If 
`FixedShapeTensor` and numpy both allow it, we should allow it too if we can. 
   ```python
   import pyarrow as pa
   pa.fixed_shape_tensor(pa.int8(), ())
   >>> pa.fixed_shape_tensor(pa.int8(), ())
   ```



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