[ 
https://issues.apache.org/jira/browse/ARROW-1753?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16226603#comment-16226603
 ] 

ASF GitHub Bot commented on ARROW-1753:
---------------------------------------

dhirschfeld commented on a change in pull request #1272: ARROW-1753 [Python] 
Provide for matching subclasses with register_type in serialization context
URL: https://github.com/apache/arrow/pull/1272#discussion_r147954573
 
 

 ##########
 File path: python/pyarrow/tests/test_serialization.py
 ##########
 @@ -416,3 +416,22 @@ class TempClass(object):
     with pytest.raises(pa.DeserializationCallbackError) as err:
         serialized_object.deserialize(deserialization_context)
     assert err.value.type_id == 20*b"\x00"
+
+
+def test_match_subclasses():
+    # should be able to serialize/deserialize an instance
+    # if a base class has been registered
+    serialization_context = pa.SerializationContext()
+    context.register_type(Foo, "Foo")
+    context.register_type(Bar, "Bar")
+    context.register_type(Baz, "Baz")
+    context.register_type(Qux, "Quz")
+
+    subqux = SubQux()
+    # should fallbact to Qux serializer
+    serialized_object = pa.serialize(subqux, serialization_context)
+
+    reconstructed_object = serialized_object.deserialize(
+        serialization_context
+    )
+    assert type(reconstructed_object) == Qux
 
 Review comment:
   IIUC, without any special handling in 
[`_deserialize_callback`](https://github.com/dhirschfeld/arrow/blob/1fc2479cdd60493ebf5a8a4a8c556a63d121257f/python/pyarrow/serialization.pxi#L121)
 you'll lose the information about the particular subclass.
   
   I've punted on this for now because I'm not entirely sure how you could do 
this robustly in a generic fashion.
   
   In my own code I'm thinking of providing a custom deserializer and storing 
the subclass information in the serialized object but I'm not sure this is a 
good *general* solution.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> [Python] Provide for matching subclasses with register_type in serialization 
> context
> ------------------------------------------------------------------------------------
>
>                 Key: ARROW-1753
>                 URL: https://issues.apache.org/jira/browse/ARROW-1753
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: Python
>            Reporter: Wes McKinney
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> Copied from https://github.com/apache/arrow/issues/1269
> To allow factoring out serialization code to a common base class it would be 
> useful if register_type matches all subclasses rather than simply an exact 
> match on the specific type.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to