Repository navigation
Fix Search on TopoJson objects that are a single geometry - #2395
Open
shashank11yadav wants to merge 1 commit into
Open
shashank11yadav wants to merge 1 commit into
shashank11yadav wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Search.render read the property keys of a TopoJson layer with
data["objects"][name]["geometries"][0]. That raisesKeyError: 'geometries'when the selected object is a single geometry, such as a Polygon.folium.TopoJsonaccepts that form, so addingSearchto 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, butGeoJsonDetailalready calls it the same way on its TopoJson parent inGeoJsonDetail.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 wholeobject_path, where the old code used only its last segment. For the usualobjects.<name>form both select the same object. The new tests cover only that form.Two new tests in
tests/plugins/test_search.pyuse a bare-geometry TopoJson with a valid label and with an unknown label. The unknown-label case checks the existingAssertionErrorfromtest_params.Fixes #2394
How it was tested:
tests/plugins/test_search.pyandtests/test_features.py: 51 passed.KeyError: 'geometries'atfolium/plugins/search.py:149) and pass with it.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.