Skip to content

Fix Search on TopoJson objects that are a single geometry - #2395

Open
shashank11yadav wants to merge 1 commit into
python-visualization:mainfrom
shashank11yadav:fix/search-topojson-bare-geometry
Open

shashank11yadav wants to merge 1 commit into
python-visualization:mainfrom
shashank11yadav:fix/search-topojson-bare-geometry

Conversation

@shashank11yadav

Copy link
Copy Markdown

Search.render read the property keys of a TopoJson layer with data["objects"][name]["geometries"][0]. That raises KeyError: 'geometries' when the selected object is a single geometry, such as a Polygon. folium.TopoJson accepts that form, so adding Search to such a layer failed at render time, while the layer alone rendered.

This change reads the keys through TopoJson._get_geometries(). It is a private helper, but GeoJsonDetail already calls it the same way on its TopoJson parent in GeoJsonDetail.render (self._parent._get_geometries()[0]["properties"]), so Search now follows that pattern. The GeoJson branch is unchanged.

One side effect: _get_geometries() walks the whole object_path, where the old code used only its last segment. For the usual objects.<name> form both select the same object. The new tests cover only that form.

Two new tests in tests/plugins/test_search.py use a bare-geometry TopoJson with a valid label and with an unknown label. The unknown-label case checks the existing AssertionError from test_params.

Fixes #2394

How it was tested:

  • Test files tests/plugins/test_search.py and tests/test_features.py: 51 passed.
  • The two new tests fail without this change (KeyError: 'geometries' at folium/plugins/search.py:149) and pass with it.
  • Lint on the repo, the format check on the repo, and a spell check on the two changed files all passed.
  • The type check on the folium package found no issues.
  • pre-commit (pre-commit run --all-files) was not run in this environment, so the pre-commit hooks, including blackdoc and the pre-commit-hooks checks, are not verified.

Search.render read the property keys with
data["objects"][name]["geometries"][0], which raises KeyError when the
selected TopoJson object is a bare geometry. Use
TopoJson._get_geometries(), which already handles both cases and is
used the same way by GeoJsonDetail.

This branch has not been deployed

No deployments
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.

Search raises KeyError for a TopoJson whose object is a single geometry

1 participant