danepitkin commented on code in PR #40160:
URL: https://github.com/apache/arrow/pull/40160#discussion_r1498440128
##########
python/pyarrow/src/arrow/python/python_to_arrow.cc:
##########
@@ -836,11 +848,14 @@ class PyListConverter : public ListConverter<T,
PyConverter, PyConverterTrait> {
Status AppendSequence(PyObject* value) {
int64_t size = static_cast<int64_t>(PySequence_Size(value));
+ RETURN_NOT_OK(AppendTo(this->list_type_, size));
RETURN_NOT_OK(this->list_builder_->ValidateOverflow(size));
return this->value_converter_->Extend(value, size);
}
Status AppendIterable(PyObject* value) {
+ auto size = static_cast<int64_t>(PyObject_Size(value));
Review Comment:
At the moment, `AppendIterable()` is only called for Sets and Dictionary
values views. I confirmed generators are routed through `AppendSequence()`
instead. I did give it a try as well:
```
>>> def gen():
... yield [0]
... yield [1]
... yield [2]
...
>>> pa.array(gen(), type=pa.list_view(pa.int32()))
<pyarrow.lib.ListViewArray object at 0x12c96e6e0>
[
[
0
],
[
1
],
[
2
]
]
>>> pa.array([gen()], type=pa.list_view(pa.int32()))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyarrow/array.pxi", line 343, in pyarrow.lib.array
result = _sequence_to_array(obj, mask, size, type, pool, c_from_pandas)
File "pyarrow/array.pxi", line 42, in pyarrow.lib._sequence_to_array
chunked = GetResultValue(
File "pyarrow/error.pxi", line 154, in
pyarrow.lib.pyarrow_internal_check_status
return check_status(status)
File "pyarrow/error.pxi", line 91, in pyarrow.lib.check_status
raise convert_status(status)
pyarrow.lib.ArrowTypeError: Could not convert <generator object gen at
0x12bed75e0> with type generator: was not a sequence or recognized null for
conversion to list type
```
--
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]