mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 17:15:39 +08:00
stubs for handling Series, DataFrame more efficiently by default in serialization code paths
Change-Id: I7f57a0c49d1f2adf7087254a035869e461251a03
This commit is contained in:
1 parent
166f0a8714
commit
5ff10f4096
2 files changed
+23
No files matched your search
@@ -526,3 +526,15 @@ def _add_any_metadata(table, pandas_metadata):
|
||||
return pa.Table.from_arrays(columns)
|
||||
else:
|
||||
return table
|
||||
|
||||
|
||||
_default_serialization_context.register_type(
|
||||
pd.Series, 'pandas.Series',
|
||||
custom_serializer=_serialize_series,
|
||||
custom_deserializer=_deserialize_series)
|
||||
|
||||
|
||||
_default_serialization_context.register_type(
|
||||
pd.DataFrame, 'pandas.DataFrame',
|
||||
custom_serializer=_serialize_dataframe,
|
||||
custom_deserializer=_deserialize_dataframe)
|
||||
@@ -137,6 +137,10 @@ cdef class SerializationContext:
|
||||
obj.__dict__.update(serialized_obj)
|
||||
return obj
|
||||
|
||||
|
||||
_default_serialization_context = SerializationContext()
|
||||
|
||||
|
||||
cdef class SerializedPyObject:
|
||||
"""
|
||||
Arrow-serialized representation of Python object
|
||||
@@ -174,6 +178,9 @@ cdef class SerializedPyObject:
|
||||
"""
|
||||
cdef PyObject* result
|
||||
|
||||
if context is None:
|
||||
context = _default_serialization_context
|
||||
|
||||
with nogil:
|
||||
check_status(DeserializeObject(context, self.data,
|
||||
<PyObject*> self.base, &result))
|
||||
@@ -210,6 +217,10 @@ def serialize(object value, SerializationContext context=None):
|
||||
"""
|
||||
cdef SerializedPyObject serialized = SerializedPyObject()
|
||||
wrapped_value = [value]
|
||||
|
||||
if context is None:
|
||||
context = _default_serialization_context
|
||||
|
||||
with nogil:
|
||||
check_status(SerializeObject(context, wrapped_value, &serialized.data))
|
||||
return serialized
|
||||
|
||||
Reference in new issue
Block a user