Skip to content

Add a popup argument to TopoJson - #2307

Draft
adarshsm wants to merge 1 commit into
python-visualization:mainfrom
adarshsm:topojson-popup
Draft

adarshsm wants to merge 1 commit 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 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
pypi — 1c6e0926 Deployed Oct 18, 2026 by adarshsm via packages #1984
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

1 participant