Skip to content

refactor(datasets): swap hand-rolled helpers for shapely + python-slugify - #46

Merged
antosubash merged 2 commits into
mainfrom
feature/infallible-spence-9ab026
Apr 21, 2026
Merged

refactor(datasets): swap hand-rolled helpers for shapely + python-slugify#46
antosubash merged 2 commits into
mainfrom
feature/infallible-spence-9ab026

Conversation

@antosubash

Copy link
Copy Markdown
Owner

Summary

  • Replace ~50 LOC of custom GeoJSON parsing in modules/datasets/datasets/extractors.py with shapely.geometry.shape().bounds. Drops _features, _compute_bbox, _iter_coords, _walk.
  • Delegate slugify() in modules/datasets/datasets/service.py to python-slugify so 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 returns tuple[list[T], int] and Inertia endpoints build their own response shape. Migration would break tests without meaningful LOC savings.
  • slowapi: can't express LoginRateLimiter's failure-gated lockout (successes reset the counter). Would silently start rate-limiting legitimate logins.
  • werkzeug.secure_filename: diverges from existing test expectations (../../etc/passwdetc_passwd vs. passwd). Not a simplification, a behavior change.

Test plan

  • uv run pytest modules/datasets/tests/ — 39 passed
  • uv run pytest modules/users/tests/test_rate_limit.py — 15 passed (limiter left untouched, verifying no incidental breakage)
  • CI passes

…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.
@antosubash
antosubash merged commit e700bd2 into main Apr 21, 2026
10 checks passed
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.

1 participant