Skip to content

Commit 729b0de

Browse files
committed
avoid imports from optional packages
1 parent 546d478 commit 729b0de

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/spatial_polars/_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
import numpy as np
66
import polars as pl
7-
from palettable.palette import Palette
87
from polars import selectors as cs
9-
from matplotlib.colors import Colormap
8+
109

1110

1211
def validate_col_exists_in_df(df: pl.DataFrame, col: Any):
@@ -49,6 +48,8 @@ def validate_cmap_input(
4948
)
5049

5150
if cmap_type == "continuous":
51+
from palettable.palette import Palette
52+
from matplotlib.colors import Colormap
5253
if isinstance(cmap, (Palette, Colormap)) is False:
5354
# verify continuous cmaps get a cmap or appropriate type.
5455
raise ValueError(

src/spatial_polars/spatialframe.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
import shapely
99
import geoarrow.pyarrow as ga
1010
from geoarrow.pyarrow import io as gaio
11-
from lonboard import viz, PathLayer, PolygonLayer, ScatterplotLayer
12-
from lonboard.colormap import apply_continuous_cmap, apply_categorical_cmap
11+
1312
from polars import col as c
1413

1514
from ._utils import validate_cmap_input, validate_width_and_radius_input
1615

1716
if TYPE_CHECKING:
17+
from lonboard import Map, PathLayer, PolygonLayer, ScatterplotLayer
1818
from lonboard.types.layer import (
1919
PathLayerKwargs,
2020
PolygonLayerKwargs,
2121
ScatterplotLayerKwargs,
2222
)
23-
from lonboard.types.map import Map, MapKwargs
23+
from lonboard.types.map import MapKwargs
2424
from io import BytesIO
2525
from numpy.typing import NDArray
2626
from palettable.palette import Palette
@@ -650,6 +650,7 @@ def viz(
650650
>>> df.spatial.viz()
651651
652652
"""
653+
from lonboard import viz
653654
geoarrow_table = self.to_geoarrow(geometry_name)
654655

655656
return viz(
@@ -808,6 +809,9 @@ def to_scatterplotlayer(
808809
809810
810811
"""
812+
from lonboard import ScatterplotLayer
813+
from lonboard.colormap import apply_continuous_cmap, apply_categorical_cmap
814+
811815
validate_cmap_input(
812816
self._df,
813817
fill_cmap_col,
@@ -1022,6 +1026,10 @@ def to_pathlayer(
10221026
10231027
10241028
"""
1029+
from lonboard import PathLayer
1030+
from lonboard.colormap import apply_continuous_cmap, apply_categorical_cmap
1031+
1032+
10251033
validate_cmap_input(
10261034
self._df, cmap_col, cmap_type, cmap, alpha, normalize_cmap_col
10271035
)
@@ -1217,6 +1225,9 @@ def to_polygonlayer(
12171225
Implementation varies slightly from Lonboard for the setting of color and width to make it easy to use from the SpatialFrame.
12181226
12191227
"""
1228+
from lonboard import PolygonLayer
1229+
from lonboard.colormap import apply_continuous_cmap, apply_categorical_cmap
1230+
12201231
validate_cmap_input(
12211232
self._df,
12221233
fill_cmap_col,

0 commit comments

Comments
 (0)