Skip to content

Commit

Permalink
ARROW-2065: [Python] Fix bug in SerializationContext.clone().
Browse files Browse the repository at this point in the history
One issue is that I don't think the test fails on the current master.

Author: Robert Nishihara <robertnishihara@gmail.com>

Closes apache#1539 from robertnishihara/fixclonebug and squashes the following commits:

61534b8 [Robert Nishihara] Fix test.
35a559a [Robert Nishihara] Fix bug in which SerializationContext.clone() doesn't copy a field.
  • Loading branch information
robertnishihara authored and pcmoritz committed Feb 1, 2018
1 parent c1d77a1 commit f84af8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/pyarrow/serialization.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ cdef class SerializationContext:
result = SerializationContext()
result.type_to_type_id = self.type_to_type_id.copy()
result.whitelisted_types = self.whitelisted_types.copy()
result.types_to_pickle = self.types_to_pickle.copy()
result.custom_serializers = self.custom_serializers.copy()
result.custom_deserializers = self.custom_deserializers.copy()
result.pickle_serializer = self.pickle_serializer
Expand Down
27 changes: 27 additions & 0 deletions python/pyarrow/tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,33 @@ def large_memory_map(tmpdir_factory, size=100*1024*1024):
return path


def test_clone():
context = pa.SerializationContext()

class Foo(object):
pass

def custom_serializer(obj):
return 0

def custom_deserializer(serialized_obj):
return (serialized_obj, 'a')

context.register_type(Foo, 'Foo', custom_serializer=custom_serializer,
custom_deserializer=custom_deserializer)

new_context = context.clone()

f = Foo()
serialized = pa.serialize(f, context=context)
deserialized = serialized.deserialize(context=context)
assert deserialized == (0, 'a')

serialized = pa.serialize(f, context=new_context)
deserialized = serialized.deserialize(context=new_context)
assert deserialized == (0, 'a')


def test_primitive_serialization(large_buffer):
for obj in PRIMITIVE_OBJECTS:
serialization_roundtrip(obj, large_buffer)
Expand Down

0 comments on commit f84af8f

Please sign in to comment.