paleolimbot commented on code in PR #378:
URL: https://github.com/apache/arrow-nanoarrow/pull/378#discussion_r1491520158
##########
python/src/nanoarrow/c_lib.py:
##########
@@ -257,7 +413,60 @@ def c_array_view(obj, requested_schema=None) -> CArrayView:
return CArrayView.from_cpu_array(c_array(obj, requested_schema))
-def allocate_c_schema():
+def c_buffer(obj, requested_schema=None) -> CBuffer:
+ """Owning, read-only ArrowBuffer wrapper
+
+ If obj implement the Python buffer protocol, ``c_buffer()`` Wraps
+ obj in nanoarrow's owning buffer structure, the ArrowBuffer,
+ such that it can be used to construct arrays. The ownership of the
+ underlying buffer is handled by the Python buffer protocol
+ (i.e., ``PyObject_GetBuffer()`` and ``PyBuffer_Release()``).
+
+ If obj is iterable, a buffer will be allocated and populated with
+ the contents of obj according to ``requested_schema``. The
+ ``requested_schema`` parameter is required to create a buffer from
+ a Python iterable. The ``struct`` module is currently used to encode
+ values from obj into binary form.
+
+ Unlike with :func:`c_array`, ``requested_schema`` is explicitly
+ honoured (or an error will be raised).
Review Comment:
I changed this to error if `schema` is passed with a buffer for now, which
would force being explicit for now (e.g., c_buffer(iter(some_array),
na.int32())`.
##########
python/src/nanoarrow/c_lib.py:
##########
@@ -257,7 +413,60 @@ def c_array_view(obj, requested_schema=None) -> CArrayView:
return CArrayView.from_cpu_array(c_array(obj, requested_schema))
-def allocate_c_schema():
+def c_buffer(obj, requested_schema=None) -> CBuffer:
+ """Owning, read-only ArrowBuffer wrapper
+
+ If obj implement the Python buffer protocol, ``c_buffer()`` Wraps
+ obj in nanoarrow's owning buffer structure, the ArrowBuffer,
+ such that it can be used to construct arrays. The ownership of the
+ underlying buffer is handled by the Python buffer protocol
+ (i.e., ``PyObject_GetBuffer()`` and ``PyBuffer_Release()``).
+
+ If obj is iterable, a buffer will be allocated and populated with
+ the contents of obj according to ``requested_schema``. The
+ ``requested_schema`` parameter is required to create a buffer from
+ a Python iterable. The ``struct`` module is currently used to encode
+ values from obj into binary form.
+
+ Unlike with :func:`c_array`, ``requested_schema`` is explicitly
+ honoured (or an error will be raised).
Review Comment:
I changed this to error if `schema` is passed with a buffer for now, which
would force being explicit for now (e.g., `c_buffer(iter(some_array),
na.int32())`.
--
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]