Fix spatial operator edge cases and expand in-memory tests - #173
Open
sdrichards-bc wants to merge 4 commits into
Open
sdrichards-bc wants to merge 4 commits into
sdrichards-bc wants to merge 4 commits into
Conversation
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
This PR fixes three edge cases found while refactoring the overlay, proximity, and adjacency tests to use shared AOI stubs and controlled in-memory geometry:
"nan"or"<NA>"instead of falling back to the source index.keep_propertiesiterables could be exhausted while building read options, leaving result records without the requested attributes.within_distance()accepted a zero radius at its own validation boundary even though the downstream spatial filter rejected it.The production changes are confined to
overlay.pyandproximity.py. The three test modules provide more explicit checks of measurements, result ordering, attributes, boundary cases, and adapter requests.Operator fixes
Handle missing feature IDs consistently
Both operators now use
pd.notna(value)in_extract_feature_id().None,NaN, andpd.NAfall back to the source row's index label, converted to a string.0remains"0".The fallback uses the original index label, so filtering and sorting do not replace it with a new row position.
Preserve properties supplied through one-shot iterables
intersection(),within_distance(), andnearest()convert a suppliedkeep_propertiesiterable to a tuple before constructing read options.This lets column selection and result construction reuse the same names. Iterators and generators can therefore retain the requested result attributes instead of being consumed during the adapter request. Regression tests exercise both a list and a one-shot iterator and check the requested columns and returned properties together.
Require a positive within-distance radius
within_distance()now rejectsdistance_m <= 0withValueError("distance_m must be positive")before reading from the adapter. This aligns its input validation with the spatial filter's positive-distance requirement, including when callers supply their ownReadOptions.A positive search radius still includes features whose measured distance is zero or exactly equal to that radius.
nearest(max_distance_m=0)remains supported for selecting zero-distance candidates.Test refactoring and coverage
The tests use shared AOI stubs, generated Shapely geometries, and
InMemorySpatialAdapterin place of file-based scenarios. Small fixtures give independently calculable areas, lengths, and distances. Adapter recordings verify request construction without requiring file or database access. Module docstrings explain each suite's purpose and how to extend it.test_overlay.pytest_proximity.pyklimits; zero-distance matches; empty results; ID/property regressions; distances across separated AOI polygons; invalid arguments and CRS rejection before reads; default and explicit read options.test_adjacent.pytouchesversuswithin_distancesearch requests.Files changed
overlay.pykeep_propertiesbefore reuse.proximity.pywithin_distance()radii.test_overlay.pytest_proximity.pywithin_distance()andnearest().test_adjacent.pyCompatibility and dependencies
Public function signatures and result types remain unchanged. Callers using
within_distance(distance_m=0)now receive an immediate operator-levelValueError; use a positive radius for that operation.The test modules import helpers from
ast_engine./tests/helpers/aoi_cases.py,aoi_geometry.py, andspatial_adapters.pyCheck List
Other Comments?
Requires pr/aoi-builder merged to main to allow tests to pass.