Skip to content

Commit

Permalink
fix callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmoritz committed Aug 18, 2017
1 parent 389bfc6 commit aeafd82
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
5 changes: 5 additions & 0 deletions cpp/src/arrow/python/arrow_to_python.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include "arrow/python/helpers.h"
#include "arrow/python/numpy_convert.h"

extern "C" {
extern PyObject* pyarrow_serialize_callback;
extern PyObject* pyarrow_deserialize_callback;
}

namespace arrow {
namespace py {

Expand Down
7 changes: 0 additions & 7 deletions cpp/src/arrow/python/arrow_to_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@

#include <vector>

extern "C" {
extern PyObject* pyarrow_serialize_callback;
extern PyObject* pyarrow_deserialize_callback;
}

namespace arrow {
namespace py {

Status CallCustomCallback(PyObject* callback, PyObject* elem, PyObject** result);

Status ReadSerializedPythonSequence(std::shared_ptr<io::RandomAccessFile> src,
std::shared_ptr<RecordBatch>* batch_out,
std::vector<std::shared_ptr<Tensor>>* tensors_out);
Expand Down
6 changes: 6 additions & 0 deletions cpp/src/arrow/python/python_to_arrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ Status CallCustomCallback(PyObject* callback, PyObject* elem, PyObject** result)
return Status::OK();
}

void set_serialization_callbacks(PyObject* serialize_callback,
PyObject* deserialize_callback) {
pyarrow_serialize_callback = serialize_callback;
pyarrow_deserialize_callback = deserialize_callback;
}

Status CallCustomSerializationCallback(PyObject* elem, PyObject** serialized_object) {
RETURN_NOT_OK(CallCustomCallback(pyarrow_serialize_callback, elem, serialized_object));
if (!PyDict_Check(*serialized_object)) {
Expand Down
8 changes: 3 additions & 5 deletions cpp/src/arrow/python/python_to_arrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@

#include <vector>

extern "C" {
extern PyObject* pyarrow_serialize_callback;
extern PyObject* pyarrow_deserialize_callback;
}

namespace arrow {
namespace py {

void set_serialization_callbacks(PyObject* serialize_callback,
PyObject* deserialize_callback);

Status SerializePythonSequence(PyObject* sequence,
std::shared_ptr<RecordBatch>* batch_out,
std::vector<std::shared_ptr<Tensor>>* tensors_out);
Expand Down
15 changes: 5 additions & 10 deletions python/pyarrow/serialization.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,14 @@ cdef extern from "arrow/python/api.h" namespace 'arrow::py' nogil:
shared_ptr[CRecordBatch] batch,
c_vector[shared_ptr[CTensor]] tensors,
OutputStream* dst)

cdef CStatus ReadSerializedPythonSequence(
shared_ptr[RandomAccessFile] src,
shared_ptr[CRecordBatch]* batch_out,
c_vector[shared_ptr[CTensor]]* tensors_out)

cdef extern from "arrow/python/python_to_arrow.h":

cdef extern PyObject *pyarrow_serialize_callback

cdef extern PyObject *pyarrow_deserialize_callback

void set_serialization_callbacks(PyObject* serialize_callback,
PyObject* deserialize_callback);

def is_named_tuple(cls):
"""Return True if cls is a namedtuple and False otherwise."""
Expand Down Expand Up @@ -157,9 +153,8 @@ def _deserialization_callback(serialized_obj):
obj.__dict__.update(serialized_obj)
return obj

pyarrow_serialize_callback = <PyObject*> _serialization_callback

pyarrow_deserialize_callback = <PyObject*> _deserialization_callback
set_serialization_callbacks(<PyObject*> _serialization_callback,
<PyObject*> _deserialization_callback)

def serialize_sequence(object value, NativeFile sink):
"""Serialize a Python sequence to a file.
Expand Down

0 comments on commit aeafd82

Please sign in to comment.