Skip to content

Add a popup argument to TopoJson - #2307

Merged
hansthen merged 3 commits into
python-visualization:mainfrom
adarshsm:topojson-popup
Nov 15, 2026
Merged

hansthen merged 3 commits into
python-visualization:mainfrom
adarshsm:topojson-popup

Conversation

@adarshsm

Copy link
Copy Markdown
Contributor

Closes #1461.

The gap

GeoJson takes both tooltip= and popup=, but TopoJson only takes tooltip=. Passing popup= fails with TypeError: TopoJson.__init__() got an unexpected keyword argument 'popup'. That's what the issue asks for: TopoJson renders faster than GeoJson for the reporter's data, but they couldn't find a way to attach per-feature popups.

Per-feature popups on a TopoJson already work at render time. GeoJsonDetail.render() handles a TopoJson parent, and since #2250 test_topojson_non_collection_geometry_detail covers GeoJsonPopup(...).add_to(topojson). So the only missing piece is the constructor argument.

The change

TopoJson.__init__ gets popup=None, handled the same way it already handles tooltip:

  • a GeoJsonPopup or Popup is added as a child
  • a string is wrapped in a Popup

The docstring documents the new parameter. Nothing changes when popup isn't passed.

folium.TopoJson(
    topo_json,
    "objects.shape",
    popup=folium.GeoJsonPopup(fields=["name"]),
).add_to(m)

Tests

  • New test_topojson_popup, parametrized over a GeoJsonPopup, a Popup and a plain string. It checks that the popup is the layer's child and that the rendered map binds it with <topojson>.bindPopup(. All three cases fail on main with the TypeError above and pass with this change.
  • pytest tests (without selenium/playwright/snapshots): 397 passed. 4 failed, and the same 4 fail on unmodified main in my environment: three PNG-export tests (ImportError) and test_timedynamic_geo_json (geodatasets not installed).
  • black --check and ruff check pass on the touched files.

🤖 Generated with Claude Code

TopoJson takes a tooltip but no popup, so per-feature popups need a
separate GeoJsonPopup(...).add_to(topojson) call. Accept popup the same
way tooltip is accepted: a GeoJsonPopup or Popup is added as a child and
a string is wrapped in a Popup.

Closes python-visualization#1461

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hansthen
hansthen marked this pull request as ready for review November 15, 2026 12:29
@hansthen
hansthen merged commit 8fc5e0a into python-visualization:main Nov 15, 2026
14 of 15 checks passed

This branch was previously deployed

1 inactive deployment
pypi — c5d2ca82 Deployed Nov 15, 2026 by hansthen via packages #2086
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement popup option in folium.TopoJson layer

2 participants