rok commented on code in PR #50203:
URL: https://github.com/apache/arrow/pull/50203#discussion_r3481145162
##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -908,13 +908,32 @@ 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: a fixed-size list (e.g. fixed-shape-tensor storage) can be
+ // built from a multi-dimensional array, always flattened in C order
+ // regardless of the input's memory layout.
Review Comment:
I missed this comment before. @AlenkaF how do you feel about allowing
0-dimensional cases through? I know they are useless, but allowing them could
be helpful as it removes edge cases.
E.g. your application returns arrays with dynamical array dimensions. And
sometime those just come out as 0 dim which you consider semantically correct.
Instead of having to now fight with PyArrow and introducing a workaround you
just pass 0-dim and you're done. What do you think?
--
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]