Skip to content

Conversation

paleolimbot
Copy link
Contributor

I'm not sure exactly where the issue is here but I suspect it's in geoarrow-pyarrow somewhere given that I was unable to replicate without geoarrow-pyarrow:

import pyarrow as pa
import json

class WkbType(pa.ExtensionType):
    """Minimal geoarrow.wkb implementation"""

    def __init__(self, crs=None, edges=None, *, storage_type=pa.binary(), **kwargs):
        self.crs = crs
        self.edges = edges
        super().__init__(storage_type, "geoarrow.wkb")

    def __arrow_ext_serialize__(self):
        obj = {"crs": self.crs, "edges": self.edges}
        return json.dumps({k: v for k, v in obj.items() if v}).encode()

    @classmethod
    def __arrow_ext_deserialize__(cls, storage_type, serialized):
        obj: dict = json.loads(serialized)
        return WkbType(**obj, storage_type=storage_type)
    
pa.register_extension_type(WkbType())


wkbs = WkbType(storage_type=pa.binary_view()).wrap_array(pa.array([b"abcdefghijkl"], pa.binary_view()))
wkbs.validate(full=True)

schema_capsule, array_capsule = wkbs.__arrow_c_array__()
pa.Array._import_from_c_capsule(schema_capsule, array_capsule).validate(full=True)

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

Successfully merging this pull request may close these issues.

1 participant