Repository navigation
Closed
Milestone
Description
Describe the bug, including details regarding any error messages, version, and platform.
https://github.com/apache/arrow/actions/runs/7760862085/job/21168058007#step:6:32228
Details
══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-python-flight.R:32:5'): flight_put ─────────────────────────────
<python.builtin.ValueError/python.builtin.Exception/python.builtin.BaseException/python.builtin.object/error/condition>
Error in `py_call_impl(callable, call_args$unnamed, call_args$named)`: ValueError: PyCapsule_GetPointer called with incorrect name
Run `reticulate::py_last_error()` for details.
Backtrace:
▆
1. └─arrow::flight_put(client, example_data, path = flight_obj) at test-python-flight.R:32:5
2. ├─reticulate::r_to_py(data)
3. └─arrow:::r_to_py.Table(data)
4. ├─reticulate::r_to_py(as_record_batch_reader(x), convert = FALSE)
5. └─arrow:::r_to_py.RecordBatchReader(...)
6. └─pa$lib$RecordBatchReader$`_import_from_c`(pyarrow_compatible_pointer(stream_ptr))
7. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
── Error ('test-python-flight.R:42:5'): flight_put with max_chunksize ──────────
<python.builtin.ValueError/python.builtin.Exception/python.builtin.BaseException/python.builtin.object/error/condition>
Error in `py_call_impl(callable, call_args$unnamed, call_args$named)`: ValueError: PyCapsule_GetPointer called with incorrect name
Run `reticulate::py_last_error()` for details.
Backtrace:
▆
1. └─arrow::flight_put(client, example_data, path = flight_obj, max_chunksize = 1) at test-python-flight.R:42:5
2. ├─reticulate::r_to_py(data)
3. └─arrow:::r_to_py.Table(data)
3. └─pa$Field$`_import_from_c`(pyarrow_compatible_pointer(schema_ptr))
4. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
── Error ('test-python.R:157:3'): RecordBatchReader to python ──────────────────
<python.builtin.ValueError/python.builtin.Exception/python.builtin.BaseException/python.builtin.object/error/condition>
Error in `py_call_impl(callable, call_args$unnamed, call_args$named)`: ValueError: PyCapsule_GetPointer called with incorrect name
Run `reticulate::py_last_error()` for details.
Backtrace:
▆
1. ├─reticulate::r_to_py(reader) at test-python.R:157:3
2. └─arrow:::r_to_py.RecordBatchReader(reader)
3. └─pa$lib$RecordBatchReader$`_import_from_c`(pyarrow_compatible_pointer(stream_ptr))
4. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
── Error ('test-python.R:177:3'): RecordBatchReader from python ────────────────
<python.builtin.ValueError/python.builtin.Exception/python.builtin.BaseException/python.builtin.object/error/condition>
Error in `py_call_impl(callable, call_args$unnamed, call_args$named)`: ValueError: PyCapsule_GetPointer called with incorrect name
Run `reticulate::py_last_error()` for details.
Backtrace:
▆
1. ├─reticulate::r_to_py(reader) at test-python.R:177:3
2. └─arrow:::r_to_py.RecordBatchReader(reader)
3. └─pa$lib$RecordBatchReader$`_import_from_c`(pyarrow_compatible_pointer(stream_ptr))
4. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
The last success commit: 2721134
The first failed commit: b684028
Commits between them:
@jorisvandenbossche Could you take a look at this PyCapsule related error messages?
Component(s)
Continuous Integration, Python, R
Activity
kou commentedon Feb 5, 2024
#39942 may be happen by the same cause.
amoeba commentedon Feb 6, 2024
The timing of this failure starting to show up is around the time version 1.35.0 of reticulate came out and it looks like 1.35.0 was used in during the above failures.
kou commentedon Feb 6, 2024
Can we pin reticulate for now?
Could you report this to reticulate?
amoeba commentedon Feb 6, 2024
Let me verify my guess, I'll report back.
amoeba commentedon Feb 6, 2024
I ran the tests in
./r/tests/testthat/test-python-flight.Rwith reticulate 1.34.0 and 1.35.0 and get different failures so I think this needs a deeper investigation.reticulate 1.34.0
reticulate 1.35.0
paleolimbot commentedon Feb 6, 2024
I believe reticulate 1.35.0 changed the "name" of the capsule. I am not sure what it was before and I am not sure what it is now...we started using external pointers on the R side in Arrow 7.0.0, which converted to Python capsules automatically, because it felt better than converting the pointer to an R
double(), sending that to Python, then static casting that to auintptr_tand calling it a pointer again.One of the errors is along the lines of
PyCapsule_GetPointer() called with incorrect name, so perhaps the name check was made stricter on the Python side when capsules started being used there.On the R side, we could go back to calling
_import_from_cwith a floating-point value (although I would rather not). We also have the ability to call it with a string representation of the address, which is also lossless, but this is rejected by pyarrow (I just checked). I also just checked passing a floating point value and that results in the test passing for me.The code on the R side that could change is here:
arrow/r/R/python.R
Lines 341 to 353 in 672238f
amoeba commentedon Feb 6, 2024
Thanks @paleolimbot. I just checked the diff between 1.34.0 and 1.35.0 and I think you're right on both counts. In rstudio/reticulate@9b2c8d4 the name changed from "NULL" to "r_extptr" and code was added to validate against the name (by calling
PyCapsule_IsValid).jorisvandenbossche commentedon Feb 6, 2024
FWIW, the python.R code is not yet using capsules (it's still using
_import_from_c(..)with raw pointers, as can also be seen in the error traceback), so this "name check" is happening somewhere in reticulate itself?(just want to say that AFAIU this is not related to the capsule work on the python side)
paleolimbot commentedon Feb 6, 2024
Got it!
It looks like capsules with a null name are accepted...perhaps it should be updated to accept a capsule with NULL or r_extptr?
arrow/python/pyarrow/types.pxi
Lines 104 to 105 in cd5faaf
paleolimbot commentedon Feb 6, 2024
Or, alternatively, we could fix in R by generating the Python integer there:
Created on 2024-02-06 with reprex v2.0.2
pitrou commentedon Feb 6, 2024
This seems to be about storing R objects inside capsules. This is not what the R-PyArrow bridge is doing, is it?
Also, if the name is not
r_extptr, this code doesn't seem to actually change anything.1 remaining item
pitrou commentedon Feb 6, 2024
Ahah, I see. Then I guess it makes sense to make the check more tolerant on the PyArrow side.
paleolimbot commentedon Feb 6, 2024
I will also submit a fix on the R side...it didn't occur to me at the time to convert to a Python integer using reticulate to work around the fact that R doesn't have 64-bit integers. If it's easy, it would probably also be a good idea to fix it in Python (or remove the ability to pass a pointer in that way, or fix the comment to reflect the new nature of how an external pointer gets converted using reticulate).
pitrou commentedon Feb 6, 2024
We should do both, because ideally one can use an older R-Arrow with a newer PyArrow and vice-versa.
GH-39933: [R] Fix pointer conversion to Python for latest reticulate (#…
apacheGH-39933: [R] Fix pointer conversion to Python for latest retic…
GH-39933: [R] Fix pointer conversion to Python for latest reticulate (#…
GH-39933: [R] Fix pointer conversion to Python for latest reticulate (#…
GH-39933: [R] Fix pointer conversion to Python for latest reticulate (#…