fix: validate bbox input and guard empty geocoder results - #530
fix: validate bbox input and guard empty geocoder results#530eklavya072 wants to merge 3 commits into
Conversation
|
Flagging this in case it slipped past — happy to adjust anything here. This is test-only (
One small extra: I used I think this needs maintainer approval for workflow runs on a first-time fork contribution. I'll rebase onto latest If a regression test around #491 would help, I'm happy to look at that next. |
|
@eklavya072 thank you for submitting this PR. You are spot on with those 6 use cases, all of them are valid. The BboxParamType is very primitive (expects only a sequence of 4 values) . It would be nice to enhance the validation with your edge cases |
convert() rejects non-finite ordinates, lon/lat outside -180/180 and -90/90, and min >= max, which covers the inverted and zero-area cases. nan is checked before the range because it compares False against everything and was going straight through. buffer_bbox clamps latitude so a polar bbox is not pushed past 90. longitude is left alone, a bbox crossing the antimeridian is a valid AOI. get_bbox_label and get_best_semantic_label guard rg.search(...) instead of indexing the first hit blind, so an AOI with no match raises BadParameter rather than IndexError. get_bbox_label's return annotation now matches the dict it returns. the xfail(strict=True) cases from the previous commit are plain tests now.
|
thanks for looking at it. pushed the validation. convert() now rejects non-finite ordinates, lon/lat out of range, and min >= max, also clamped latitude in buffer_bbox so a bbox already at a pole doesn't get pushed heads up this isn't test-only anymore like my earlier comment said, it touches two things i wasn't so sure on: rejecting a zero-area bbox (5,5,5,5) is the only change that's a behaviour call the label functions raise BadParameter, which fits the CLI path but is a bit loose renamed the PR since "test:" doesn't really fit now. |
overview
BboxParamTypeonly checked that it got four numbers, so a fair bit of unusableinput was getting through —
nan, coordinates off the globe, inverted boxes.this adds tests for those cases and the validation to reject them.
what changed
convert()now rejects non-finite ordinates, lon/lat outside -180/180 and-90/90, and
min >= max, which handles the inverted and zero-area cases in onerule. the finite check runs first because
nancompares False against everythingand was slipping straight through the range check. bounds match the ones
cmask.pyalready uses.buffer_bboxclamps latitude to ±90 so a bbox already touching a pole doesn'tget pushed past it. longitude is left alone since a bbox crossing the antimeridian
looks like a legitimate AOI, and
mgrsconvwraps longitude elsewhere anyway.get_bbox_label/get_best_semantic_labelwere indexingrg.search(...)[0]with no guard, so an AOI with no geocoder match came out as an
IndexError. bothraise
BadParameternow.get_bbox_label's-> strannotation is also now-> dict, which is what it actually returns.testing
tests/rapida/test_bbox_param_type.pycovers all four functions. the edge caseswent in as
xfail(strict=True)so they'd flip the moment the behaviour changed —they're plain tests now. 38 passing, and the example in
admin.pystill parses.one thing i'm unsure about: rejecting a zero-area bbox is the only change here
that isn't purely a bug fix. happy to drop it if a degenerate bbox is meaningful
somewhere.
files:
rapida/util/bbox_param_type.pytests/rapida/test_bbox_param_type.py