Skip to content

Commit

Permalink
Remove the DeprecationWarning from STRtree constructor (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Aug 23, 2021
1 parent c047f49 commit 822bf1c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
7 changes: 0 additions & 7 deletions shapely/strtree.py
Expand Up @@ -22,9 +22,7 @@
import logging
from typing import Any, ItemsView, Iterable, Iterator, Optional, Sequence, Tuple, Union
import sys
from warnings import warn

from shapely.errors import ShapelyDeprecationWarning
from shapely.geometry.base import BaseGeometry
from shapely.geos import lgeos

Expand Down Expand Up @@ -99,11 +97,6 @@ def __init__(
items: Iterable[Any] = None,
node_capacity: int = 10,
):
warn(
"STRtree will be changed in 2.0.0. The exact API is not yet decided, but will be documented before 1.8.0",
ShapelyDeprecationWarning,
stacklevel=2,
)
self.node_capacity = node_capacity

# Keep references to geoms
Expand Down
43 changes: 14 additions & 29 deletions tests/test_strtree.py
Expand Up @@ -6,7 +6,6 @@

import pytest

from shapely.errors import ShapelyDeprecationWarning
from shapely.geometry import Point, Polygon, box
from shapely.geos import geos_version
from shapely import strtree
Expand All @@ -27,8 +26,7 @@
[(Point(2, 2).buffer(0.99), 1), (Point(2, 2).buffer(1.0), 3)],
)
def test_query(geoms, query_geom, num_results):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms)
tree = STRtree(geoms)
results = tree.query(query_geom)
assert len(results) == num_results

Expand All @@ -41,8 +39,7 @@ def test_query(geoms, query_geom, num_results):
)
def test_query_enumeration_idx(geoms, query_geom, expected):
"""Store enumeration idx"""
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, range(len(geoms)))
tree = STRtree(geoms, range(len(geoms)))
results = tree.query_items(query_geom)
assert sorted(results) == sorted(expected)

Expand All @@ -56,8 +53,7 @@ def test_query_enumeration_idx(geoms, query_geom, expected):
)
def test_query_items(geoms, items, query_geom, expected):
"""Store enumeration idx"""
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, items)
tree = STRtree(geoms, items)
results = tree.query_items(query_geom)
expected = [items[idx] for idx in expected] if items is not None else expected
assert sorted(results) == sorted(expected)
Expand All @@ -74,8 +70,7 @@ def test_query_items(geoms, items, query_geom, expected):
],
)
def test_query_items_with_empty(tree_geometry, geometry, expected):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(tree_geometry)
tree = STRtree(tree_geometry)
assert tree.query_items(geometry) == expected


Expand All @@ -87,8 +82,7 @@ def test_insert_empty_geometry():
"""
empty = Polygon()
geoms = [empty]
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms)
tree = STRtree(geoms)
query = Polygon([(0, 0), (1, 1), (2, 0), (0, 0)])
results = tree.query(query)
assert len(results) == 0
Expand All @@ -103,8 +97,7 @@ def test_query_empty_geometry():
empty = Polygon()
point = Point(1, 0.5)
geoms = [empty, point]
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms)
tree = STRtree(geoms)
query = Polygon([(0, 0), (1, 1), (2, 0), (0, 0)])
results = tree.query(query)
assert len(results) == 1
Expand All @@ -117,8 +110,7 @@ def test_references():
empty = Polygon()
point = Point(1, 0.5)
geoms = [empty, point]
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms)
tree = STRtree(geoms)

empty = None
point = None
Expand All @@ -132,8 +124,7 @@ def test_references():

@requires_geos_342
def test_safe_delete():
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree([])
tree = STRtree([])

_lgeos = strtree.lgeos
strtree.lgeos = None
Expand All @@ -148,8 +139,7 @@ def test_pickle_persistence():
"""
Don't crash trying to use unpickled GEOS handle.
"""
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree([Point(i, i).buffer(0.1) for i in range(3)], range(3))
tree = STRtree([Point(i, i).buffer(0.1) for i in range(3)], range(3))

pickled_strtree = pickle.dumps(tree)
unpickle_script_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "unpickle-strtree.py")
Expand All @@ -175,8 +165,7 @@ def test_pickle_persistence():
)
@pytest.mark.parametrize("query_geom", [Point(0, 0.4)])
def test_nearest_geom(geoms, query_geom):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms)
tree = STRtree(geoms)
result = tree.nearest(query_geom)
assert result.geom_type == "Point"
assert result.x == 0.0
Expand All @@ -197,22 +186,19 @@ def test_nearest_geom(geoms, query_geom):
@pytest.mark.parametrize("items", [list(range(1, 4)), list("abc")])
@pytest.mark.parametrize("query_geom", [Point(0, 0.4)])
def test_nearest_item(geoms, items, query_geom):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, items)
tree = STRtree(geoms, items)
assert tree.nearest_item(query_geom) == items[0]


@pytest.mark.parametrize(["geoms", "items"], [([], None), ([], [])])
def test_nearest_empty(geoms, items):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, items)
tree = STRtree(geoms, items)
assert tree.nearest_item(None) is None


@pytest.mark.parametrize(["geoms", "items"], [([], None), ([], [])])
def test_nearest_items(geoms, items):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, items)
tree = STRtree(geoms, items)
assert tree.nearest_item(None) is None


Expand All @@ -230,6 +216,5 @@ def test_nearest_items(geoms, items):
@pytest.mark.parametrize("items", [list(range(1, 4)), list("abc")])
@pytest.mark.parametrize("query_geom", [Point(0, 0.5)])
def test_nearest_item_exclusive(geoms, items, query_geom):
with pytest.warns(ShapelyDeprecationWarning):
tree = STRtree(geoms, items)
tree = STRtree(geoms, items)
assert tree.nearest_item(query_geom, exclusive=True) != items[0]

0 comments on commit 822bf1c

Please sign in to comment.