Skip to content

Commit 14e8de6

Browse files
vraj2131cursoragent
andcommitted
Fix geopandas legend tests by not clearing figure.html on render
Geopandas explore() adds legend HTML directly to figure.html. Clearing output sections in Figure.render() removed that content. Stable script names for SetIcon and ElementAddToElement are enough for idempotent save(). Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e25a06c commit 14e8de6

1 file changed

Lines changed: 4 additions & 17 deletions

File tree

folium/figure.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,9 @@
22

33
from branca.element import Figure as BrancaFigure
44

5+
# Re-export branca Figure for folium maps. Rendering must not clear
6+
# figure.html children that were added directly (e.g. geopandas legends).
57

6-
class Figure(BrancaFigure):
7-
"""Figure that supports repeated rendering without duplicating output.
8-
9-
Branca elements populate ``header``, ``html``, and ``script`` during
10-
``render()``. Some folium elements create new child nodes on every render
11-
call, which causes repeated ``save()`` calls to accumulate duplicate HTML
12-
and JavaScript. Clearing the rendered sections before each render makes
13-
output idempotent while preserving static header content from ``__init__``.
14-
"""
158

16-
def render(self, **kwargs):
17-
meta = self.header._children.pop("meta_http", None)
18-
self.header._children.clear()
19-
if meta is not None:
20-
self.header._children["meta_http"] = meta
21-
self.html._children.clear()
22-
self.script._children.clear()
23-
return super().render(**kwargs)
9+
class Figure(BrancaFigure):
10+
"""Figure used as the root container for folium maps."""

0 commit comments

Comments
 (0)