From f56201bec3d2d63c73437de23e196d1a2d45d32e Mon Sep 17 00:00:00 2001 From: Dane Pitkin Date: Fri, 15 Mar 2024 11:17:11 -0400 Subject: [PATCH] Simplify getting ListView's non-view type equivalent, add GH issue to optimize conversion --- .../src/arrow/python/arrow_to_pandas.cc | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/python/pyarrow/src/arrow/python/arrow_to_pandas.cc b/python/pyarrow/src/arrow/python/arrow_to_pandas.cc index eaf453dc8a223..cd7811f2aba26 100644 --- a/python/pyarrow/src/arrow/python/arrow_to_pandas.cc +++ b/python/pyarrow/src/arrow/python/arrow_to_pandas.cc @@ -832,35 +832,24 @@ enable_if_list_like ConvertListsLike(PandasOptions options, return Status::OK(); } -template -struct ListViewConversionType; - -template <> -struct ListViewConversionType { - using type = ListType; -}; - -template <> -struct ListViewConversionType { - using type = LargeListType; -}; - +// TODO GH-40579: optimize ListView conversion to avoid unecessary copies template enable_if_list_view ConvertListsLike(PandasOptions options, const ChunkedArray& data, PyObject** out_values) { using ListViewArrayType = typename TypeTraits::ArrayType; - using ConversionType = typename ListViewConversionType::type; - using ConversionClass = typename TypeTraits::ArrayType; + using NonViewType = std::conditional_t; + using NonViewClass = typename TypeTraits::ArrayType; ArrayVector list_arrays; for (int c = 0; c < data.num_chunks(); c++) { const auto& arr = checked_cast(*data.chunk(c)); ARROW_ASSIGN_OR_RAISE(auto converted_array, - ConversionClass::FromListView(arr, options.pool)); + NonViewClass::FromListView(arr, options.pool)); list_arrays.emplace_back(converted_array); } auto chunked_array = std::make_shared(list_arrays); - return ConvertListsLike(options, *chunked_array, out_values); + return ConvertListsLike(options, *chunked_array, out_values); } template