Repository navigation
Allow float feature ids when styling GeoJson - #2369
Open
KhadeerBasha1232 wants to merge 1 commit into
Open
KhadeerBasha1232 wants to merge 1 commit into
KhadeerBasha1232 wants to merge 1 commit into
Conversation
RFC 7946 allows any number as a feature id. find_identifier picks feature.id when every feature has a unique id, but get_feature_id then asserted the value was a str or int, so a style_function or highlight_function on data with ids like 1.5 failed with a bare AssertionError. Float ids work fine in the generated Javascript switch, so accept them too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KhadeerBasha1232
temporarily deployed
to
pypi
November 20, 2026 14:22 — with
GitHub Actions
Inactive
This branch was previously 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.
Allow float feature ids when styling GeoJson
The problem
A GeoJSON feature
idcan be a string or any number (RFC 7946, section 3.2). With float ids,GeoJsonfails to render as soon as astyle_functionorhighlight_functionis set:The cause
GeoJson.find_identifier()picksfeature.idwhenever every feature has a unique id, whatever its type.GeoJsonStyleMapper.get_feature_id()then asserts that the id is astrorint, so float ids fail with a bareAssertionErrorthat doesn't say what's wrong.The fix
Accept
floatinget_feature_id, and add it to the type hints. The id is only used as acasevalue in the generatedswitch(feature.id).tojsonwrites floats as plain numbers (case 101.1:), and they match there just like ints do.I relaxed the assertion rather than making
find_identifierskip float ids. Skipping them would fall through to the last option, which overwrites the user's ids with"0","1", ... in the embedded data. That would break anyon_each_featurecode that relies onfeature.id.After
The example above renders. Each zone gets its own color, and in Chrome hovering a zone highlights it (
weight3 → 6) and shows its tooltip, with no console errors:Tests
tests/test_features.py::test_geojson_style_float_feature_idsbuilds astyle_functionandhighlight_functionon features with float ids. It checks the style and highlight maps,case 1.5:in the output, and that the original ids are kept. It fails with theAssertionErrorwithout the change.tests/test_features.py, ruff and black pass.