Skip to content

Commit e531057

Browse files
committed
Undo module import
Instead do dynamic import as a workaround
1 parent fe2ac44 commit e531057

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

folium/features.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
)
2424
from branca.utilities import color_brewer
2525

26-
import folium.map
2726
from folium.elements import JSCSSMixin
2827
from folium.folium import Map
28+
from folium.map import FeatureGroup, Icon, Layer, Marker, Popup, Tooltip
2929
from folium.template import Template
3030
from folium.utilities import (
3131
TypeBoundsReturn,
@@ -47,7 +47,7 @@
4747
from folium.vector_layers import Circle, CircleMarker, PolyLine, path_options
4848

4949

50-
class RegularPolygonMarker(JSCSSMixin, folium.map.Marker):
50+
class RegularPolygonMarker(JSCSSMixin, Marker):
5151
"""
5252
Custom markers using the Leaflet Data Vis Framework.
5353
@@ -96,8 +96,8 @@ def __init__(
9696
number_of_sides: int = 4,
9797
rotation: int = 0,
9898
radius: int = 15,
99-
popup: Union[folium.map.Popup, str, None] = None,
100-
tooltip: Union[folium.map.Tooltip, str, None] = None,
99+
popup: Union[Popup, str, None] = None,
100+
tooltip: Union[Tooltip, str, None] = None,
101101
**kwargs: TypePathOptions,
102102
):
103103
super().__init__(location, popup=popup, tooltip=tooltip)
@@ -297,7 +297,7 @@ def __init__(
297297
def render(self, **kwargs):
298298
"""Renders the HTML representation of the element."""
299299
parent = self._parent
300-
if not isinstance(parent, (Figure, Div, folium.map.Popup)):
300+
if not isinstance(parent, (Figure, Div, Popup)):
301301
raise TypeError(
302302
"VegaLite elements can only be added to a Figure, Div, or Popup"
303303
)
@@ -467,7 +467,7 @@ def _embed_vegalite_v1(self, figure: Figure, parent: TypeContainer) -> None:
467467
)
468468

469469

470-
class GeoJson(folium.map.Layer):
470+
class GeoJson(Layer):
471471
"""
472472
Creates a GeoJson object for plotting into a Map.
473473
@@ -675,11 +675,11 @@ def __init__(
675675
control: bool = True,
676676
show: bool = True,
677677
smooth_factor: Optional[float] = None,
678-
tooltip: Union[str, folium.map.Tooltip, "GeoJsonTooltip", None] = None,
678+
tooltip: Union[str, Tooltip, "GeoJsonTooltip", None] = None,
679679
embed: bool = True,
680680
popup: Optional["GeoJsonPopup"] = None,
681681
zoom_on_click: bool = False,
682-
marker: Union[Circle, CircleMarker, folium.map.Marker, None] = None,
682+
marker: Union[Circle, CircleMarker, Marker, None] = None,
683683
**kwargs: Any,
684684
):
685685
super().__init__(name=name, overlay=overlay, control=control, show=show)
@@ -693,7 +693,7 @@ def __init__(
693693
self.highlight = highlight_function is not None
694694
self.zoom_on_click = zoom_on_click
695695
if marker:
696-
if not isinstance(marker, (Circle, CircleMarker, folium.map.Marker)):
696+
if not isinstance(marker, (Circle, CircleMarker, Marker)):
697697
raise TypeError(
698698
"Only Marker, Circle, and CircleMarker are supported as GeoJson marker types."
699699
)
@@ -721,11 +721,11 @@ def __init__(
721721
self.highlight_map: dict = {}
722722
self.feature_identifier = self.find_identifier()
723723

724-
if isinstance(tooltip, (GeoJsonTooltip, folium.map.Tooltip)):
724+
if isinstance(tooltip, (GeoJsonTooltip, Tooltip)):
725725
self.add_child(tooltip)
726726
elif tooltip is not None:
727-
self.add_child(folium.map.Tooltip(tooltip))
728-
if isinstance(popup, (GeoJsonPopup, folium.map.Popup)):
727+
self.add_child(Tooltip(tooltip))
728+
if isinstance(popup, (GeoJsonPopup, Popup)):
729729
self.add_child(popup)
730730

731731
def process_data(self, data: Any) -> dict:
@@ -916,7 +916,7 @@ def _set_default_key(mapping: TypeStyleMapping) -> None:
916916
del mapping[key_longest]
917917

918918

919-
class TopoJson(JSCSSMixin, folium.map.Layer):
919+
class TopoJson(JSCSSMixin, Layer):
920920
"""
921921
Creates a TopoJson object for plotting into a Map.
922922
@@ -1011,7 +1011,7 @@ def __init__(
10111011
control: bool = True,
10121012
show: bool = True,
10131013
smooth_factor: Optional[float] = None,
1014-
tooltip: Union[str, folium.map.Tooltip, None] = None,
1014+
tooltip: Union[str, Tooltip, None] = None,
10151015
):
10161016
super().__init__(name=name, overlay=overlay, control=control, show=show)
10171017
self._name = "TopoJson"
@@ -1035,10 +1035,10 @@ def __init__(
10351035

10361036
self.smooth_factor = smooth_factor
10371037

1038-
if isinstance(tooltip, (GeoJsonTooltip, folium.map.Tooltip)):
1038+
if isinstance(tooltip, (GeoJsonTooltip, Tooltip)):
10391039
self.add_child(tooltip)
10401040
elif tooltip is not None:
1041-
self.add_child(folium.map.Tooltip(tooltip))
1041+
self.add_child(Tooltip(tooltip))
10421042

10431043
def style_data(self) -> None:
10441044
"""Applies self.style_function to each feature of self.data."""
@@ -1377,7 +1377,7 @@ def __init__(
13771377
self.popup_options = kwargs
13781378

13791379

1380-
class Choropleth(folium.map.FeatureGroup):
1380+
class Choropleth(FeatureGroup):
13811381
"""Apply a GeoJSON overlay to the map.
13821382
13831383
Plot a GeoJSON overlay on the base map. There is no requirement
@@ -1855,7 +1855,7 @@ def __init__(self, format_str: Optional[str] = None, alert: bool = True):
18551855
self.alert = alert
18561856

18571857

1858-
class CustomIcon(folium.map.Icon):
1858+
class CustomIcon(Icon):
18591859
"""
18601860
Create a custom icon, based on an image.
18611861
@@ -1908,7 +1908,7 @@ def __init__(
19081908
shadow_anchor: Optional[Tuple[int, int]] = None,
19091909
popup_anchor: Optional[Tuple[int, int]] = None,
19101910
):
1911-
super(folium.map.Icon, self).__init__()
1911+
super(Icon, self).__init__()
19121912
self._name = "CustomIcon"
19131913
self.options = remove_empty(
19141914
icon_url=image_to_url(icon_image),
@@ -1921,7 +1921,7 @@ def __init__(
19211921
)
19221922

19231923

1924-
class ColorLine(folium.map.FeatureGroup):
1924+
class ColorLine(FeatureGroup):
19251925
"""
19261926
Draw data on a map with specified colors.
19271927

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 (
@@ -439,6 +438,8 @@ def set_icon(self, icon: Union[Icon, "CustomIcon", "DivIcon"]):
439438
self.icon = icon
440439

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

0 commit comments

Comments
 (0)