Skip to content
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

perf: Postpone bokeh.models import #764

Merged
merged 4 commits into from
Dec 16, 2024
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
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
Loading