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

Function ConvertAsPyObjects

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

Source from the content-addressed store, hash-verified

632// requested
633template <typename Type, typename WrapFunction>
634inline Status ConvertAsPyObjects(const PandasOptions& options, const ChunkedArray& data,
635 WrapFunction&& wrap_func, PyObject** out_values) {
636 using ArrayType = typename TypeTraits<Type>::ArrayType;
637 using Scalar = typename MemoizationTraits<Type>::Scalar;
638
639 auto convert_chunks = [&](auto&& wrap_func) -> Status {
640 for (int c = 0; c < data.num_chunks(); c++) {
641 const auto& arr = arrow::internal::checked_cast<const ArrayType&>(*data.chunk(c));
642 RETURN_NOT_OK(internal::WriteArrayObjects(arr, wrap_func, out_values));
643 out_values += arr.length();
644 }
645 return Status::OK();
646 };
647
648 if (options.deduplicate_objects) {
649 // GH-40316: only allocate a memo table if deduplication is enabled.
650 ::arrow::internal::ScalarMemoTable<Scalar> memo_table(options.pool);
651 std::vector<PyObject*> unique_values;
652 int32_t memo_size = 0;
653
654 auto WrapMemoized = [&](const Scalar& value, PyObject** out_values) {
655 int32_t memo_index;
656 RETURN_NOT_OK(memo_table.GetOrInsert(value, &memo_index));
657 if (memo_index == memo_size) {
658 // New entry
659 RETURN_NOT_OK(wrap_func(value, out_values));
660 unique_values.push_back(*out_values);
661 ++memo_size;
662 } else {
663 // Duplicate entry
664 Py_INCREF(unique_values[memo_index]);
665 *out_values = unique_values[memo_index];
666 }
667 return Status::OK();
668 };
669 return convert_chunks(std::move(WrapMemoized));
670 } else {
671 return convert_chunks(std::forward<WrapFunction>(wrap_func));
672 }
673}
674
675Status ConvertStruct(PandasOptions options, const ChunkedArray& data,
676 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