-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: Fix STRtree memory leaks #434
Merged
jorisvandenbossche
merged 3 commits into
pygeos:master
from
brendan-ward:fix_strtree_memleak
Nov 29, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -211,9 +211,70 @@ def test_query_unsupported_predicate(tree): | |
tree.query(pygeos.points(1, 1), predicate="disjoint") | ||
|
||
|
||
def test_query_predicate_errors(tree): | ||
@pytest.mark.parametrize( | ||
"predicate,expected", | ||
[ | ||
("intersects", [0, 1, 2]), | ||
("within", []), | ||
("contains", [1]), | ||
("overlaps", []), | ||
("crosses", []), | ||
("covers", [0, 1, 2]), | ||
("covered_by", []), | ||
("contains_properly", [1]), | ||
], | ||
) | ||
def test_query_prepared_inputs(tree, predicate, expected): | ||
geom = box(0, 0, 2, 2) | ||
pygeos.prepare(geom) | ||
assert_array_equal(tree.query(geom, predicate=predicate), expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expanded this test to verify that memory leak occurs for all predicates except |
||
"predicate", | ||
[ | ||
pytest.param( | ||
"intersects", | ||
marks=pytest.mark.xfail(reason="intersects does not raise exception"), | ||
), | ||
pytest.param( | ||
"within", | ||
marks=pytest.mark.xfail( | ||
pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8" | ||
), | ||
), | ||
pytest.param( | ||
"contains", | ||
marks=pytest.mark.xfail( | ||
pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8" | ||
), | ||
), | ||
"overlaps", | ||
"crosses", | ||
"touches", | ||
pytest.param( | ||
"covers", | ||
marks=pytest.mark.xfail( | ||
pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8" | ||
), | ||
), | ||
pytest.param( | ||
"covered_by", | ||
marks=pytest.mark.xfail( | ||
pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8" | ||
), | ||
), | ||
pytest.param( | ||
"contains_properly", | ||
marks=pytest.mark.xfail( | ||
pygeos.geos_version < (3, 8, 0), reason="GEOS < 3.8" | ||
), | ||
), | ||
], | ||
) | ||
def test_query_predicate_errors(tree, predicate): | ||
with pytest.raises(pygeos.GEOSException): | ||
tree.query(pygeos.linestrings([1, 1], [1, float("nan")]), predicate="touches") | ||
tree.query(pygeos.linestrings([1, 1], [1, float("nan")]), predicate=predicate) | ||
|
||
|
||
def test_query_tree_with_none(): | ||
|
@@ -1189,6 +1250,13 @@ def test_query_bulk_intersects_polygons(poly_tree, geometry, expected): | |
assert_array_equal(poly_tree.query_bulk(geometry, predicate="intersects"), expected) | ||
|
||
|
||
def test_query_bulk_predicate_errors(tree): | ||
with pytest.raises(pygeos.GEOSException): | ||
tree.query_bulk( | ||
[pygeos.linestrings([1, 1], [1, float("nan")])], predicate="touches" | ||
) | ||
|
||
|
||
@pytest.mark.skipif(pygeos.geos_version < (3, 6, 0), reason="GEOS < 3.6") | ||
def test_nearest_empty_tree(): | ||
tree = pygeos.STRtree([]) | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this test because we weren't specifically testing prepared inputs here, and wanted to verify those didn't result in memory leaks.