anjakefala commented on code in PR #40565:
URL: https://github.com/apache/arrow/pull/40565#discussion_r1530452024
##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -620,37 +620,42 @@ inline Status ConvertAsPyObjects(const PandasOptions&
options, const ChunkedArra
using ArrayType = typename TypeTraits<Type>::ArrayType;
using Scalar = typename MemoizationTraits<Type>::Scalar;
- ::arrow::internal::ScalarMemoTable<Scalar> memo_table(options.pool);
- std::vector<PyObject*> unique_values;
- int32_t memo_size = 0;
-
- auto WrapMemoized = [&](const Scalar& value, PyObject** out_values) {
- int32_t memo_index;
- RETURN_NOT_OK(memo_table.GetOrInsert(value, &memo_index));
- if (memo_index == memo_size) {
- // New entry
- RETURN_NOT_OK(wrap_func(value, out_values));
- unique_values.push_back(*out_values);
- ++memo_size;
- } else {
- // Duplicate entry
- Py_INCREF(unique_values[memo_index]);
- *out_values = unique_values[memo_index];
- }
- return Status::OK();
- };
-
- auto WrapUnmemoized = [&](const Scalar& value, PyObject** out_values) {
- return wrap_func(value, out_values);
- };
+ std::shared_ptr<::arrow::internal::ScalarMemoTable<Scalar>> memo_table =
nullptr;
+ std::shared_ptr<std::vector<PyObject*>> unique_values = nullptr;
+ std::shared_ptr<int32_t> memo_size = std::make_shared<int32_t>(0);
+
+ std::function<Status(const typename MemoizationTraits<Type>::Scalar&,
PyObject**)>
Review Comment:
I had a lot of challenges with building and/or running the program without
the shared pointers. Without them, the lambda function at run-time or
build-time declared things were out of scope or not declared. I can share with
you what I had previously, and how it froze when I ran it. You are much more
experienced with C++ than I am and you might have a better idea how to approach
it.
If I keep the `WrapMemoized` and `WrapUnmemoized`, then I would need an
additional `if statement` later on, but maybe that is fine.
--
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]