Skip to content

Commit

Permalink
perf: Postpone bokeh.models import (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Dec 16, 2024
1 parent ee088ab commit b0618a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions geoviews/element/geo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys

import numpy as np
import param
from bokeh.models import MercatorTileSource
from cartopy import crs as ccrs
from cartopy.feature import Feature as cFeature
from cartopy.io.img_tiles import GoogleTiles
Expand Down Expand Up @@ -80,6 +81,12 @@ class HvImageStack: ...

geographic_types = (GoogleTiles, cFeature, BaseGeometry)

def _check_bokeh_mercator(data) -> bool:
if "bokeh.models" in sys.modules:
from bokeh.models import MercatorTileSource
return isinstance(data, MercatorTileSource)
return False

def is_geographic(element, kdims=None):
"""
Utility to determine whether the supplied element optionally
Expand Down Expand Up @@ -267,8 +274,7 @@ class WMTS(_GeoFeature):
layer = param.String(doc="The layer on the tile service")

def __init__(self, data, kdims=None, vdims=None, **params):
if ((MercatorTileSource and isinstance(data, MercatorTileSource)) or
(GoogleTiles and isinstance(data, GoogleTiles))):
if _check_bokeh_mercator(data) or isinstance(data, GoogleTiles):
data = data.url
elif WebMapTileService and isinstance(data, WebMapTileService):
pass
Expand Down
2 changes: 1 addition & 1 deletion geoviews/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_no_blocklist_imports():
import sys
import geoviews as gv
blocklist = {"panel", "IPython", "datashader", "iris", "dask"}
blocklist = {"panel", "IPython", "datashader", "iris", "dask", "bokeh.models"}
mods = blocklist & set(sys.modules)
if mods:
Expand Down

0 comments on commit b0618a3

Please sign in to comment.