@@ -20,7 +20,7 @@ from libcpp.vector cimport vector as c_vector
2020from cpython.ref cimport PyObject
2121from cython.operator cimport dereference as deref
2222
23- from pyarrow.lib cimport Buffer, NativeFile, check_status
23+ from pyarrow.lib cimport Buffer, NativeFile, check_status, _RecordBatchFileWriter
2424
2525cdef extern from " arrow/python/python_to_arrow.h" :
2626
@@ -67,3 +67,23 @@ def deserialize_sequence(PythonObject value, object base):
6767 cdef PyObject* result
6868 check_status(DeserializeList(deref(value.batch).column(0 ), 0 , deref(value.batch).num_rows(), < PyObject* > base, value.tensors, & result))
6969 return < object > result
70+
71+ def write_python_object (PythonObject value , NativeFile sink ):
72+ cdef shared_ptr[OutputStream] stream
73+ sink.write_handle(& stream)
74+ cdef shared_ptr[CRecordBatchFileWriter] writer
75+ cdef shared_ptr[CSchema] schema = deref(value.batch).schema()
76+ cdef shared_ptr[CRecordBatch] batch = value.batch
77+ cdef shared_ptr[CTensor] tensor
78+ cdef int32_t metadata_length
79+ cdef int64_t body_length
80+
81+ with nogil:
82+ check_status(CRecordBatchFileWriter.Open(stream.get(), schema, & writer))
83+ check_status(deref(writer).WriteRecordBatch(deref(batch)))
84+ check_status(deref(writer).Close())
85+
86+ for tensor in value.tensors:
87+ check_status(WriteTensor(deref(tensor), stream.get(), & metadata_length, & body_length))
88+
89+ # def read_python_object(NativeFile source):
0 commit comments