Skip to content

Commit 2aa00d0

Browse files
committed
Undo module import
Instead do dynamic import as a workaround
1 parent 1db8558 commit 2aa00d0

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

folium/features.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
)
3535
from branca.utilities import color_brewer
3636

37-
import folium.map
3837
from folium.elements import JSCSSMixin
3938
from folium.folium import Map
39+
from folium.map import FeatureGroup, Icon, Layer, Marker, Popup, Tooltip
4040
from folium.template import Template
4141
from folium.utilities import (
4242
JsCode,
@@ -60,7 +60,7 @@
6060
from folium.vector_layers import Circle, CircleMarker, PolyLine, path_options
6161

6262

63-
class RegularPolygonMarker(JSCSSMixin, folium.map.Marker):
63+
class RegularPolygonMarker(JSCSSMixin, Marker):
6464
"""
6565
Custom markers using the Leaflet Data Vis Framework.
6666
@@ -109,8 +109,8 @@ def __init__(
109109
number_of_sides: int = 4,
110110
rotation: int = 0,
111111
radius: int = 15,
112-
popup: Union[folium.map.Popup, str, None] = None,
113-
tooltip: Union[folium.map.Tooltip, str, None] = None,
112+
popup: Union[Popup, str, None] = None,
113+
tooltip: Union[Tooltip, str, None] = None,
114114
**kwargs: TypePathOptions,
115115
):
116116
super().__init__(location, popup=popup, tooltip=tooltip)
@@ -310,7 +310,7 @@ def __init__(
310310
def render(self, **kwargs):
311311
"""Renders the HTML representation of the element."""
312312
parent = self._parent
313-
if not isinstance(parent, (Figure, Div, folium.map.Popup)):
313+
if not isinstance(parent, (Figure, Div, Popup)):
314314
raise TypeError(
315315
"VegaLite elements can only be added to a Figure, Div, or Popup"
316316
)
@@ -480,7 +480,7 @@ def _embed_vegalite_v1(self, figure: Figure, parent: TypeContainer) -> None:
480480
)
481481

482482

483-
class GeoJson(folium.map.Layer):
483+
class GeoJson(Layer):
484484
"""
485485
Creates a GeoJson object for plotting into a Map.
486486
@@ -696,7 +696,7 @@ def __init__(
696696
control: bool = True,
697697
show: bool = True,
698698
smooth_factor: Optional[float] = None,
699-
tooltip: Union[str, folium.map.Tooltip, "GeoJsonTooltip", None] = None,
699+
tooltip: Union[str, Tooltip, "GeoJsonTooltip", None] = None,
700700
embed: bool = True,
701701
popup: Optional["GeoJsonPopup"] = None,
702702
zoom_on_click: bool = False,
@@ -715,7 +715,7 @@ def __init__(
715715
self.highlight = highlight_function is not None
716716
self.zoom_on_click = zoom_on_click
717717
if marker:
718-
if not isinstance(marker, (Circle, CircleMarker, folium.map.Marker)):
718+
if not isinstance(marker, (Circle, CircleMarker, Marker)):
719719
raise TypeError(
720720
"Only Marker, Circle, and CircleMarker are supported as GeoJson marker types."
721721
)
@@ -744,11 +744,11 @@ def __init__(
744744
self.highlight_map: dict = {}
745745
self.feature_identifier = self.find_identifier()
746746

747-
if isinstance(tooltip, (GeoJsonTooltip, folium.map.Tooltip)):
747+
if isinstance(tooltip, (GeoJsonTooltip, Tooltip)):
748748
self.add_child(tooltip)
749749
elif tooltip is not None:
750-
self.add_child(folium.map.Tooltip(tooltip))
751-
if isinstance(popup, (GeoJsonPopup, folium.map.Popup)):
750+
self.add_child(Tooltip(tooltip))
751+
if isinstance(popup, (GeoJsonPopup, Popup)):
752752
self.add_child(popup)
753753

754754
def process_data(self, data: Any) -> dict:
@@ -939,7 +939,7 @@ def _set_default_key(mapping: TypeStyleMapping) -> None:
939939
del mapping[key_longest]
940940

941941

942-
class TopoJson(JSCSSMixin, folium.map.Layer):
942+
class TopoJson(JSCSSMixin, Layer):
943943
"""
944944
Creates a TopoJson object for plotting into a Map.
945945
@@ -1034,7 +1034,7 @@ def __init__(
10341034
control: bool = True,
10351035
show: bool = True,
10361036
smooth_factor: Optional[float] = None,
1037-
tooltip: Union[str, folium.map.Tooltip, None] = None,
1037+
tooltip: Union[str, Tooltip, None] = None,
10381038
):
10391039
super().__init__(name=name, overlay=overlay, control=control, show=show)
10401040
self._name = "TopoJson"
@@ -1058,10 +1058,10 @@ def __init__(
10581058

10591059
self.smooth_factor = smooth_factor
10601060

1061-
if isinstance(tooltip, (GeoJsonTooltip, folium.map.Tooltip)):
1061+
if isinstance(tooltip, (GeoJsonTooltip, Tooltip)):
10621062
self.add_child(tooltip)
10631063
elif tooltip is not None:
1064-
self.add_child(folium.map.Tooltip(tooltip))
1064+
self.add_child(Tooltip(tooltip))
10651065

10661066
def style_data(self) -> None:
10671067
"""Applies self.style_function to each feature of self.data."""
@@ -1408,7 +1408,7 @@ def __init__(
14081408
self.popup_options = kwargs
14091409

14101410

1411-
class Choropleth(folium.map.FeatureGroup):
1411+
class Choropleth(FeatureGroup):
14121412
"""Apply a GeoJSON overlay to the map.
14131413
14141414
Plot a GeoJSON overlay on the base map. There is no requirement
@@ -1886,7 +1886,7 @@ def __init__(self, format_str: Optional[str] = None, alert: bool = True):
18861886
self.alert = alert
18871887

18881888

1889-
class CustomIcon(folium.map.Icon):
1889+
class CustomIcon(Icon):
18901890
"""
18911891
Create a custom icon, based on an image.
18921892
@@ -1939,7 +1939,7 @@ def __init__(
19391939
shadow_anchor: Optional[Tuple[int, int]] = None,
19401940
popup_anchor: Optional[Tuple[int, int]] = None,
19411941
):
1942-
super(folium.map.Icon, self).__init__()
1942+
super(Icon, self).__init__()
19431943
self._name = "CustomIcon"
19441944
self.options = remove_empty(
19451945
icon_url=image_to_url(icon_image),
@@ -1952,7 +1952,7 @@ def __init__(
19521952
)
19531953

19541954

1955-
class ColorLine(folium.map.FeatureGroup):
1955+
class ColorLine(FeatureGroup):
19561956
"""
19571957
Draw data on a map with specified colors.
19581958

folium/map.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from branca.element import Element, Figure, Html, MacroElement
1111

12-
import folium.features as features
1312
from folium.elements import ElementAddToElement, EventHandler
1413
from folium.template import Template
1514
from folium.utilities import (
@@ -440,6 +439,8 @@ def set_icon(self, icon):
440439
self.icon = icon
441440

442441
def add_child(self, child, name=None, index=None):
442+
import folium.features as features
443+
443444
if isinstance(child, (Icon, features.CustomIcon, features.DivIcon)):
444445
self.set_icon(child)
445446
else:

0 commit comments

Comments
 (0)