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
2 changes: 1 addition & 1 deletion docs/api/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
::: lonboard.traits.FilterValueAccessor
::: lonboard.traits.NormalAccessor
::: lonboard.traits.PointAccessor
::: lonboard.traits.PyarrowTableTrait
::: lonboard.traits.ArrowTableTrait
9 changes: 8 additions & 1 deletion lonboard/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Dict, List, Optional

import click
import pyarrow.parquet as pq
from arro3.core import Table
from pyproj import CRS

Expand Down Expand Up @@ -65,6 +64,14 @@ def read_geoparquet(path: Path) -> Table:
Args:
path: Path to GeoParquet file
"""
try:
import pyarrow.parquet as pq
except ImportError as e:
raise ImportError(
"pyarrow currently required for reading GeoParquet files.\n"
"Run `pip install pyarrow`."
) from e

file = pq.ParquetFile(path)
geo_meta = file.metadata.metadata.get(b"geo")
if not geo_meta:
Expand Down
8 changes: 7 additions & 1 deletion lonboard/_geoarrow/geopandas_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ def geopandas_to_geoarrow(
columns: Optional[List[str]] = None,
preserve_index: Optional[bool] = None,
) -> Table:
import pyarrow
try:
import pyarrow
except ImportError as e:
raise ImportError(
"pyarrow required for converting GeoPandas to arrow.\n"
"Run `pip install pyarrow`."
) from e

df_attr = gdf.drop(columns=[gdf._geometry_column_name])

Expand Down
20 changes: 10 additions & 10 deletions lonboard/_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import ipywidgets
import traitlets
from arro3.core import Table
from arro3.core.types import ArrowStreamExportable

from lonboard._base import BaseExtension, BaseWidget
from lonboard._constants import EXTENSION_NAME, OGC_84
Expand All @@ -38,12 +39,11 @@
from lonboard._utils import auto_downcast as _auto_downcast
from lonboard._utils import get_geometry_column_index, remove_extension_kwargs
from lonboard.traits import (
ArrowTableTrait,
ColorAccessor,
FloatAccessor,
NormalAccessor,
PyarrowTableTrait,
)
from lonboard.types.arrow import ArrowStreamExportable

if TYPE_CHECKING:
import geopandas as gpd
Expand Down Expand Up @@ -283,7 +283,7 @@ class BaseArrowLayer(BaseLayer):

# The following traitlets **are** serialized to JS

table: traitlets.TraitType
table: ArrowTableTrait

def __init__(
self,
Expand Down Expand Up @@ -714,7 +714,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("column").tag(sync=True)

table = PyarrowTableTrait(allowed_geometry_types={EXTENSION_NAME.POINT})
table = ArrowTableTrait(allowed_geometry_types={EXTENSION_NAME.POINT})
"""A GeoArrow table with a Point or MultiPoint column.

This is the fastest way to plot data from an existing GeoArrow source, such as
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("polygon").tag(sync=True)

table = PyarrowTableTrait(
table = ArrowTableTrait(
allowed_geometry_types={EXTENSION_NAME.POLYGON, EXTENSION_NAME.MULTIPOLYGON}
)
"""A GeoArrow table with a Polygon or MultiPolygon column.
Expand Down Expand Up @@ -1246,7 +1246,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("scatterplot").tag(sync=True)

table = PyarrowTableTrait(
table = ArrowTableTrait(
allowed_geometry_types={EXTENSION_NAME.POINT, EXTENSION_NAME.MULTIPOINT}
)
"""A GeoArrow table with a Point or MultiPoint column.
Expand Down Expand Up @@ -1488,7 +1488,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("path").tag(sync=True)

table = PyarrowTableTrait(
table = ArrowTableTrait(
allowed_geometry_types={
EXTENSION_NAME.LINESTRING,
EXTENSION_NAME.MULTILINESTRING,
Expand Down Expand Up @@ -1659,7 +1659,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("point-cloud").tag(sync=True)

table = PyarrowTableTrait(
table = ArrowTableTrait(
allowed_geometry_types={EXTENSION_NAME.POINT}, allowed_dimensions={3}
)
"""A GeoArrow table with a Point column.
Expand Down Expand Up @@ -1792,7 +1792,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("solid-polygon").tag(sync=True)

table = PyarrowTableTrait(
table = ArrowTableTrait(
allowed_geometry_types={EXTENSION_NAME.POLYGON, EXTENSION_NAME.MULTIPOLYGON}
)
"""A GeoArrow table with a Polygon or MultiPolygon column.
Expand Down Expand Up @@ -1971,7 +1971,7 @@ def from_duckdb(

_layer_type = traitlets.Unicode("heatmap").tag(sync=True)

table = PyarrowTableTrait(allowed_geometry_types={EXTENSION_NAME.POINT})
table = ArrowTableTrait(allowed_geometry_types={EXTENSION_NAME.POINT})
"""A GeoArrow table with a Point column.

This is the fastest way to plot data from an existing GeoArrow source, such as
Expand Down
9 changes: 0 additions & 9 deletions lonboard/_testing.py

This file was deleted.

19 changes: 16 additions & 3 deletions lonboard/_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import pyarrow
import shapely.geometry
import shapely.geometry.base
from arro3.core.types import ArrowArrayExportable, ArrowStreamExportable
from numpy.typing import NDArray

from lonboard.types.arrow import ArrowArrayExportable, ArrowStreamExportable
from lonboard.types.layer import (
PathLayerKwargs,
PolygonLayerKwargs,
Expand Down Expand Up @@ -372,8 +372,21 @@ def _viz_shapely_array(
def _viz_geo_interface(
data: dict, **kwargs
) -> List[Union[ScatterplotLayer, PathLayer, PolygonLayer]]:
import pyarrow as pa
import shapely
try:
import pyarrow as pa
except ImportError as e:
raise ImportError(
"pyarrow required for visualizing __geo_interface__ objects.\n"
"Run `pip install pyarrow`."
) from e

try:
import shapely
except ImportError as e:
raise ImportError(
"shapely required for visualizing __geo_interface__ objects.\n"
"Run `pip install shapely`."
) from e

if data["type"] in [
"Point",
Expand Down
10 changes: 8 additions & 2 deletions lonboard/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,14 @@ def apply_categorical_cmap(
dimension will have a length of either `3` if `alpha` is `None`, or `4` is
each color has an alpha value.
"""
import pyarrow as pa
import pyarrow.compute as pc
try:
import pyarrow as pa
import pyarrow.compute as pc
except ImportError as e:
raise ImportError(
"pyarrow required for apply_categorical_cmap.\n"
"Run `pip install pyarrow`."
) from e

# Import from PyCapsule interface
if hasattr(values, "__arrow_c_array__"):
Expand Down
6 changes: 3 additions & 3 deletions lonboard/experimental/_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from lonboard._constants import EXTENSION_NAME
from lonboard._layer import BaseArrowLayer
from lonboard.traits import (
ArrowTableTrait,
ColorAccessor,
FloatAccessor,
PointAccessor,
PyarrowTableTrait,
TextAccessor,
)

Expand All @@ -23,7 +23,7 @@ class ArcLayer(BaseArrowLayer):

_layer_type = traitlets.Unicode("arc").tag(sync=True)

table = PyarrowTableTrait()
table = ArrowTableTrait()
"""A GeoArrow table.

This is the fastest way to plot data from an existing GeoArrow source, such as
Expand Down Expand Up @@ -128,7 +128,7 @@ class TextLayer(BaseArrowLayer):

_layer_type = traitlets.Unicode("text").tag(sync=True)

table = PyarrowTableTrait(allowed_geometry_types={EXTENSION_NAME.POINT})
table = ArrowTableTrait(allowed_geometry_types={EXTENSION_NAME.POINT})
"""A GeoArrow table with a Point or MultiPoint column.

This is the fastest way to plot data from an existing GeoArrow source, such as
Expand Down
7 changes: 5 additions & 2 deletions lonboard/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def error(
raise TraitError(e)


class PyarrowTableTrait(FixedErrorTraitType):
class ArrowTableTrait(FixedErrorTraitType):
"""A trait to validate input for a geospatial Arrow-backed table

Allowed input includes:
Expand All @@ -152,7 +152,10 @@ class from
"""

default_value = None
info_text = "a pyarrow or GeoArrow Table"
info_text = (
"a table-like Arrow object, such as a pyarrow or arro3 Table or "
"RecordBatchReader"
)

def __init__(
self: TraitType,
Expand Down
13 changes: 0 additions & 13 deletions lonboard/types/arrow.py

This file was deleted.

12 changes: 5 additions & 7 deletions lonboard/types/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import (
List,
Literal,
Protocol,
Sequence,
Tuple,
Union,
Expand All @@ -13,6 +12,7 @@
import numpy as np
import pandas as pd
import pyarrow
from arro3.core.types import ArrowArrayExportable, ArrowStreamExportable
from numpy.typing import NDArray

from lonboard._base import BaseExtension
Expand All @@ -23,12 +23,6 @@
from typing_extensions import TypedDict


class ArrowArrayExportable(Protocol):
def __arrow_c_array__(
self, requested_schema: object | None = None
) -> Tuple[object, object]: ...


IntFloat = Union[int, float]
Units = Literal["meters", "common", "pixels"]

Expand All @@ -41,6 +35,7 @@ def __arrow_c_array__(
pyarrow.FixedSizeListArray,
pyarrow.ChunkedArray,
ArrowArrayExportable,
ArrowStreamExportable,
]
FloatAccessorInput = Union[
int,
Expand All @@ -50,6 +45,7 @@ def __arrow_c_array__(
pyarrow.FloatingPointArray,
pyarrow.ChunkedArray,
ArrowArrayExportable,
ArrowStreamExportable,
]
NormalAccessorInput = Union[
List[int],
Expand All @@ -59,6 +55,7 @@ def __arrow_c_array__(
pyarrow.FixedSizeListArray,
pyarrow.ChunkedArray,
ArrowArrayExportable,
ArrowStreamExportable,
]
TextAccessorInput = Union[
str,
Expand All @@ -68,6 +65,7 @@ def __arrow_c_array__(
pyarrow.LargeStringArray,
pyarrow.ChunkedArray,
ArrowArrayExportable,
ArrowStreamExportable,
]


Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ plugins:
- https://geopy.readthedocs.io/en/stable/objects.inv
- https://ipython.readthedocs.io/en/stable/objects.inv
- https://ipywidgets.readthedocs.io/en/stable/objects.inv
- https://kylebarron.dev/arro3/latest/objects.inv
- https://matplotlib.org/stable/objects.inv
- https://numpy.org/doc/stable/objects.inv
- https://pandas.pydata.org/pandas-docs/stable/objects.inv
Expand Down
4 changes: 2 additions & 2 deletions tests/test_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from lonboard._layer import BaseArrowLayer, BaseLayer
from lonboard.layer_extension import DataFilterExtension
from lonboard.traits import (
ArrowTableTrait,
ColorAccessor,
FloatAccessor,
NormalAccessor,
PyarrowTableTrait,
)


Expand Down Expand Up @@ -176,7 +176,7 @@ class FilterValueAccessorWidget(BaseArrowLayer):
sync=True, **ipywidgets.widget_serialization
)

table = PyarrowTableTrait()
table = ArrowTableTrait()

def __init__(self, *args, **kwargs):
# Any tests that are intended to pass validation checks must also have 3 rows,
Expand Down