Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow register_type to match subclasses #1269

Closed
dhirschfeld opened this issue Oct 30, 2017 · 1 comment
Closed

Allow register_type to match subclasses #1269

dhirschfeld opened this issue Oct 30, 2017 · 1 comment

Comments

@dhirschfeld
Copy link

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.

It might be possible with a simple change to _serialize_callback:

def _serialize_callback(self, obj):
if type(obj) not in self.type_to_type_id:
raise SerializationCallbackError(
"pyarrow does not know how to "
"serialize objects of type {}.".format(type(obj)), obj)
type_id = self.type_to_type_id[type(obj)]

def _serialize_callback(self, obj):
    FOUND = False
    for type_ in type(obj).mro():
        if type_ in self.type_to_type_id:
            FOUND = True
            break
    
    if not FOUND:
        raise SerializationCallbackError(
            "pyarrow does not know how to "
            "serialize objects of type {}.".format(type(obj)), obj
        )

    # use the closest match to type(obj)
    type_id = self.type_to_type_id[type_]
@wesm
Copy link
Member

wesm commented Oct 30, 2017

I opened https://issues.apache.org/jira/browse/ARROW-1753 for the feature request. Would you like to write a patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants