paleolimbot commented on code in PR #378:
URL: https://github.com/apache/arrow-nanoarrow/pull/378#discussion_r1491544038
##########
python/src/nanoarrow/c_lib.py:
##########
@@ -120,15 +157,134 @@ def c_array(obj=None, requested_schema=None) -> CArray:
*obj.__arrow_c_array__(requested_schema=requested_schema_capsule)
)
- # for pyarrow < 14.0
- if hasattr(obj, "_export_to_c"):
+ # Try buffer protocol (e.g., numpy arrays or a c_buffer())
+ if _obj_is_buffer(obj):
+ return _c_array_from_pybuffer(obj)
+
+ # Try import of bare capsule
+ if _obj_is_capsule(obj, "arrow_array"):
+ if requested_schema is None:
+ requested_schema_capsule = CSchema.allocate()._capsule
Review Comment:
Yes, it will leave you with an invalid schema. Nothing preventing the print
method from working, though! (Or from using `._addr` to safely pass it
somewhere else).
```python
import nanoarrow as na
import pyarrow as pa
na.c_array(pa.array([1, 2, 3]).__arrow_c_array__()[1])
# <nanoarrow.c_lib.CArray [invalid: schema is released]>
# - length: 3
# - offset: 0
# - null_count: 0
# - buffers: (0, 6021410128064)
# - dictionary: NULL
# - children[0]:
```
--
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]