Skip to content

fix(geoarrow-pyarrow): Fix roundtrip to C and back for WkbView array #72

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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