[ https://issues.apache.org/jira/browse/ARROW-2033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16344147#comment-16344147 ]
ASF GitHub Bot commented on ARROW-2033: --------------------------------------- wesm commented on a change in pull request #1513: ARROW-2033: [Python] Fix pa.array() with iterator input URL: https://github.com/apache/arrow/pull/1513#discussion_r164589586 ########## File path: cpp/src/arrow/python/builtin_convert.cc ########## @@ -830,38 +821,51 @@ Status AppendPySequence(PyObject* obj, int64_t size, return converter->AppendData(obj, size); } -Status ConvertPySequence(PyObject* obj, MemoryPool* pool, std::shared_ptr<Array>* out) { +static Status ConvertPySequenceReal(PyObject* obj, MemoryPool* pool, + std::shared_ptr<Array>* out, + const std::shared_ptr<DataType>* type, int64_t size) { PyAcquireGIL lock; - std::shared_ptr<DataType> type; - int64_t size; - RETURN_NOT_OK(InferArrowTypeAndSize(obj, &size, &type)); - return ConvertPySequence(obj, pool, out, type, size); -} + ScopedRef seqref; + std::shared_ptr<DataType> real_type; + + RETURN_NOT_OK(ConvertToSequenceAndInferSize(obj, seqref.ref(), &size)); Review comment: I think `seqref.ref()` is only writable on account of `const PyObject*` being unwieldy -- it might be less awkward to pass a mutable pointer to `seqref` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > pa.array() doesn't work with iterators > -------------------------------------- > > Key: ARROW-2033 > URL: https://issues.apache.org/jira/browse/ARROW-2033 > Project: Apache Arrow > Issue Type: Bug > Components: Python > Affects Versions: 0.8.0 > Reporter: Antoine Pitrou > Assignee: Antoine Pitrou > Priority: Minor > Labels: pull-request-available > Fix For: 0.9.0 > > > pa.array handles iterables fine, but not iterators if size isn't passed: > {code:java} > >>> arr = pa.array(range(5)) > >>> arr > <pyarrow.lib.Int64Array object at 0x7f4652a05318> > [ > 0, > 1, > 2, > 3, > 4 > ] > >>> arr = pa.array(iter(range(5))) > >>> arr > <pyarrow.lib.NullArray object at 0x7f4633c1d638> > [ > NA, > NA, > NA, > NA, > NA > ] > {code} > This is because InferArrowSize() first exhausts the iterator. -- This message was sent by Atlassian JIRA (v7.6.3#76005)