| 621 | // requested |
| 622 | template <typename Type, typename WrapFunction> |
| 623 | inline Status ConvertAsPyObjects(const PandasOptions& options, const ChunkedArray& data, |
| 624 | WrapFunction&& wrap_func, PyObject** out_values) { |
| 625 | using ArrayType = typename TypeTraits<Type>::ArrayType; |
| 626 | using Scalar = typename MemoizationTraits<Type>::Scalar; |
| 627 | |
| 628 | auto convert_chunks = [&](auto&& wrap_func) -> Status { |
| 629 | for (int c = 0; c < data.num_chunks(); c++) { |
| 630 | const auto& arr = arrow::internal::checked_cast<const ArrayType&>(*data.chunk(c)); |
| 631 | RETURN_NOT_OK(internal::WriteArrayObjects(arr, wrap_func, out_values)); |
| 632 | out_values += arr.length(); |
| 633 | } |
| 634 | return Status::OK(); |
| 635 | }; |
| 636 | |
| 637 | if (options.deduplicate_objects) { |
| 638 | // GH-40316: only allocate a memo table if deduplication is enabled. |
| 639 | ::arrow::internal::ScalarMemoTable<Scalar> memo_table(options.pool); |
| 640 | std::vector<PyObject*> unique_values; |
| 641 | int32_t memo_size = 0; |
| 642 | |
| 643 | auto WrapMemoized = [&](const Scalar& value, PyObject** out_values) { |
| 644 | int32_t memo_index; |
| 645 | RETURN_NOT_OK(memo_table.GetOrInsert(value, &memo_index)); |
| 646 | if (memo_index == memo_size) { |
| 647 | // New entry |
| 648 | RETURN_NOT_OK(wrap_func(value, out_values)); |
| 649 | unique_values.push_back(*out_values); |
| 650 | ++memo_size; |
| 651 | } else { |
| 652 | // Duplicate entry |
| 653 | Py_INCREF(unique_values[memo_index]); |
| 654 | *out_values = unique_values[memo_index]; |
| 655 | } |
| 656 | return Status::OK(); |
| 657 | }; |
| 658 | return convert_chunks(std::move(WrapMemoized)); |
| 659 | } else { |
| 660 | return convert_chunks(std::forward<WrapFunction>(wrap_func)); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | Status ConvertStruct(PandasOptions options, const ChunkedArray& data, |
| 665 | PyObject** out_values) { |
nothing calls this directly
no test coverage detected