refactor(datasets): swap hand-rolled helpers for shapely + python-slugify - #46
Merged
Conversation
…ed helpers - extractors.py: replace custom GeoJSON parsing (_features, _compute_bbox, _iter_coords, _walk) with shapely.geometry.shape().bounds. Drops ~50 LOC of coordinate-walking and edge-case handling. - service.py: delegate slugify() to python-slugify so accented characters transliterate correctly (e.g. "Café" -> "cafe"). The custom regex only stripped non-ASCII. All 54 datasets tests pass.
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.
Summary
modules/datasets/datasets/extractors.pywithshapely.geometry.shape().bounds. Drops_features,_compute_bbox,_iter_coords,_walk.slugify()inmodules/datasets/datasets/service.pytopython-slugifyso accented/unicode names transliterate correctly (e.g."Café"→"cafe"). The previous regex stripped non-ASCII.Net: -30 lines, with two well-maintained deps taking over the edge-case handling.
Why
Exploratory survey of the codebase flagged these as the two highest-value simplification wins against popular OSS libraries where the swap is genuinely additive (fewer LOC, strictly equal-or-better behavior). Other candidates (pagination → fastapi-pagination, login limiter → slowapi, safe_filename → werkzeug) were evaluated and rejected because the lib's semantics didn't match the existing contract.
Explicitly not done
fastapi-pagination: service layer returnstuple[list[T], int]and Inertia endpoints build their own response shape. Migration would break tests without meaningful LOC savings.slowapi: can't expressLoginRateLimiter's failure-gated lockout (successes reset the counter). Would silently start rate-limiting legitimate logins.werkzeug.secure_filename: diverges from existing test expectations (../../etc/passwd→etc_passwdvs.passwd). Not a simplification, a behavior change.Test plan
uv run pytest modules/datasets/tests/— 39 passeduv run pytest modules/users/tests/test_rate_limit.py— 15 passed (limiter left untouched, verifying no incidental breakage)