MCPcopy Create free account
hub / github.com/apache/arrow / ConvertAsPyObjects

Function ConvertAsPyObjects

python/pyarrow/src/arrow/python/arrow_to_pandas.cc:623–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621// requested
622template <typename Type, typename WrapFunction>
623inline 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
664Status ConvertStruct(PandasOptions options, const ChunkedArray& data,
665 PyObject** out_values) {

Callers

nothing calls this directly

Calls 6

WriteArrayObjectsFunction · 0.85
push_backMethod · 0.80
OKFunction · 0.50
num_chunksMethod · 0.45
lengthMethod · 0.45
GetOrInsertMethod · 0.45

Tested by

no test coverage detected