Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions geoarrow-pyarrow/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ description = ""
authors = [{name = "Dewey Dunnington", email = "[email protected]"}]
license = {text = "Apache-2.0"}
requires-python = ">=3.8"
dependencies = ["geoarrow-c", "pyarrow", "pyarrow_hotfix"]
dependencies = ["pyarrow", "pyarrow_hotfix", "geoarrow-types"]

[project.optional-dependencies]
test = ["pytest", "pandas", "numpy", "geopandas", "pyogrio", "pyproj"]
test = ["pytest", "pandas", "numpy", "geopandas", "pyogrio", "pyproj", "geoarrow-c"]
compute = ["geoarrow-c"]

[project.urls]
homepage = "https://geoarrow.org"
Expand Down
16 changes: 13 additions & 3 deletions geoarrow-pyarrow/src/geoarrow/pyarrow/_array.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pyarrow as pa
import pyarrow_hotfix as _ # noqa: F401

from geoarrow.c import lib

from geoarrow.pyarrow._kernel import Kernel
from geoarrow.pyarrow._kernel import Kernel, _geoarrow_c
from geoarrow.pyarrow._type import (
GeometryExtensionType,
wkb,
Expand All @@ -17,6 +15,8 @@ class GeometryExtensionArray(pa.ExtensionArray):
def geobuffers(self):
import numpy as np

lib = _geoarrow_c()

cschema = lib.SchemaHolder()
self.type._export_to_c(cschema._addr())
carray = lib.ArrayHolder()
Expand All @@ -27,6 +27,16 @@ def geobuffers(self):
return [np.array(b) if b is not None else None for b in buffers]

def __repr__(self):
# Pretty WKT printing needs geoarrow-c
try:
from geoarrow import c # noqa: F401
except ImportError:
return (
super().__repr__()
+ "\n"
+ "* pip install geoarrow-c for prettier printing of geometry arrays"
)

n_values_to_show = 10
max_width = 70

Expand Down
4 changes: 2 additions & 2 deletions geoarrow-pyarrow/src/geoarrow/pyarrow/_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from geoarrow.pyarrow import _type
from geoarrow.pyarrow._array import array
from geoarrow.pyarrow._kernel import Kernel
from geoarrow.pyarrow._kernel import Kernel, _geoarrow_c


def obj_as_array_or_chunked(obj_in):
Expand Down Expand Up @@ -264,7 +264,7 @@ def as_geoarrow(obj, type=None, coord_type=None, promote_multi=False):
if obj.type.spec == type.spec:
return obj

from geoarrow.c import lib
lib = _geoarrow_c()

cschema = lib.SchemaHolder()
type._export_to_c(cschema._addr())
Expand Down
22 changes: 18 additions & 4 deletions geoarrow-pyarrow/src/geoarrow/pyarrow/_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@

import pyarrow as pa
import pyarrow_hotfix as _ # noqa: F401
from geoarrow.c import lib
from geoarrow.pyarrow._type import GeometryExtensionType


_lazy_lib = None


def _geoarrow_c():
global _lazy_lib
if _lazy_lib is None:
try:
from geoarrow.c import lib
except ImportError as e:
raise ImportError("Requested operation requires geoarrow-c") from e

_lazy_lib = lib
return _lazy_lib


class Kernel:
def __init__(self, name, type_in, **kwargs) -> None:
if not isinstance(type_in, pa.DataType):
raise TypeError("Expected `type_in` to inherit from pyarrow.DataType")

self._name = str(name)
self._kernel = lib.CKernel(self._name.encode("UTF-8"))
self._kernel = _geoarrow_c().CKernel(self._name.encode("UTF-8"))
# True for all the kernels that currently exist
self._is_agg = self._name.endswith("_agg")

type_in_schema = lib.SchemaHolder()
type_in_schema = _geoarrow_c().SchemaHolder()
type_in._export_to_c(type_in_schema._addr())

options = Kernel._pack_options(kwargs)
Expand All @@ -40,7 +54,7 @@ def push(self, arr):
f"Expected pyarrow.Array or pyarrow.ChunkedArray but got {type(arr)}"
)

array_in = lib.ArrayHolder()
array_in = _geoarrow_c().ArrayHolder()
arr._export_to_c(array_in._addr())

if self._is_agg:
Expand Down
2 changes: 2 additions & 0 deletions geoarrow-types/src/geoarrow/types/type_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def __arrow_ext_deserialize__(cls, storage_type, serialized):
)

def to_pandas_dtype(self):
# Note that returning geopandas.array.GeometryDtype() here
# doesn't result in a GeoSeries or GeoDataFrame.
from pandas import ArrowDtype

return ArrowDtype(self)
Expand Down
Loading