felipecrv commented on code in PR #40482:
URL: https://github.com/apache/arrow/pull/40482#discussion_r1525648974


##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -826,6 +830,37 @@ Status ConvertListsLike(PandasOptions options, const 
ChunkedArray& data,
   return Status::OK();
 }
 
+template <class T>
+struct ListViewConversionType;
+
+template <>
+struct ListViewConversionType<ListViewType> {
+  using type = ListType;
+};
+
+template <>
+struct ListViewConversionType<LargeListViewType> {
+  using type = LargeListType;
+};
+
+template <typename T>
+enable_if_list_view<T, Status> ConvertListsLike(PandasOptions options,
+                                                const ChunkedArray& data,
+                                                PyObject** out_values) {
+  using ListViewArrayType = typename TypeTraits<T>::ArrayType;
+  using ConversionType = typename ListViewConversionType<T>::type;
+  using ConversionClass = typename TypeTraits<ConversionType>::ArrayType;
+  ArrayVector list_arrays;
+  for (int c = 0; c < data.num_chunks(); c++) {
+    const auto& arr = checked_cast<const ListViewArrayType&>(*data.chunk(c));
+    ARROW_ASSIGN_OR_RAISE(auto converted_array,
+                          ConversionClass::FromListView(arr, options.pool));
+    list_arrays.emplace_back(converted_array);
+  }
+  auto chunked_array = std::make_shared<ChunkedArray>(list_arrays);
+  return ConvertListsLike<ConversionType>(options, *chunked_array, out_values);

Review Comment:
   Can you create an issue about making this conversion more efficient and 
mention it here? I could pick that later and adapt the list-conversion code to 
also work with list-views (that's tricky enough that I don't really know how to 
do it without actually writing the code myself).



##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -1342,16 +1377,14 @@ struct ObjectWriterVisitor {
   }
 
   template <typename T>
-  enable_if_t<is_fixed_size_list_type<T>::value || 
is_var_length_list_type<T>::value,
-              Status>
-  Visit(const T& type) {
-    using ArrayType = typename TypeTraits<T>::ArrayType;
+  enable_if_t<is_list_like_type<T>::value || is_list_view_type<T>::value, 
Status> Visit(
+      const T& type) {

Review Comment:
   You can use `is_var_length_list_like_type` here [1]. I wrote it, but found 
it by looking at this image [2] to suggest it to you :)
   
   <img width="851" alt="Screenshot 2024-03-14 at 22 20 53" 
src="https://github.com/apache/arrow/assets/207795/d8089775-3a43-4b22-a060-dbca7971f2b2";>
   
   [1] 
https://github.com/apache/arrow/blob/main/cpp/src/arrow/type_traits.h#L795
   [2] https://gist.github.com/felipecrv/3c02f3784221d946dec1b031c6d400db



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