pitrou commented on a change in pull request #11076:
URL: https://github.com/apache/arrow/pull/11076#discussion_r702814361



##########
File path: cpp/src/arrow/python/inference.cc
##########
@@ -354,12 +354,17 @@ class TypeInferrer {
       *keep_going = make_unions_;
     } else if (PyArray_CheckAnyScalarExact(obj)) {
       RETURN_NOT_OK(VisitDType(PyArray_DescrFromScalar(obj), keep_going));
-    } else if (PyList_Check(obj)) {
-      RETURN_NOT_OK(VisitList(obj, keep_going));
+    } else if (PySet_Check(obj) || (Py_TYPE(obj) == &PyDictValues_Type)) {
+      RETURN_NOT_OK(VisitSet(obj, keep_going));
     } else if (PyArray_Check(obj)) {
       RETURN_NOT_OK(VisitNdarray(obj, keep_going));
     } else if (PyDict_Check(obj)) {
       RETURN_NOT_OK(VisitDict(obj));
+    } else if (PySequence_Check(obj)) {
+      // Deals with generic sequences. Including list and tuple.

Review comment:
       I'm not fond of allowing generic sequences here, it might allow all 
kinds of types that we don't want to convert implicitly. Explicitly checking 
list and tuple would be better.

##########
File path: cpp/src/arrow/python/python_to_arrow.cc
##########
@@ -650,6 +652,19 @@ class PyListConverter : public ListConverter<T, 
PyConverter, PyConverterTrait> {
     return this->value_converter_->Extend(value, size);
   }
 
+  Status AppendIterable(PyObject* value) {
+    int64_t current_size = 0;
+    PyObject* iterator = PyObject_GetIter(value);
+    OwnedRef iter_ref(iterator);
+    while (PyObject* item = PyIter_Next(iterator)) {
+      current_size += 1;
+      OwnedRef item_ref(item);
+      RETURN_NOT_OK(this->value_converter_->Reserve(current_size));

Review comment:
       Are you sure you are using this right? It seems that 
`Reserve(current_size)` would reserve space for `current_size` elements _in 
addition_ to the elements already present.




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