Skip to content

Commit

Permalink
Merge 0340088 into f6185ee
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Feb 4, 2022
2 parents f6185ee + 0340088 commit ab0f9ea
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 20 deletions.
1 change: 0 additions & 1 deletion shapely/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .lib import Geometry # NOQA
from .lib import geos_version, geos_version_string # NOQA
from .lib import geos_capi_version, geos_capi_version_string # NOQA
from .decorators import UnsupportedGEOSOperation # NOQA
from ._geometry import * # NOQA
from .creation import * # NOQA
from .constructive import * # NOQA
Expand Down
7 changes: 2 additions & 5 deletions shapely/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import numpy as np

from . import lib


class UnsupportedGEOSOperation(ImportError):
pass
from .errors import UnsupportedGEOSVersionError


class requires_geos:
Expand Down Expand Up @@ -35,7 +32,7 @@ def wrapped(*args, **kwargs):

@wraps(func)
def wrapped(*args, **kwargs):
raise UnsupportedGEOSOperation(msg)
raise UnsupportedGEOSVersionError(msg)

doc = wrapped.__doc__
if doc:
Expand Down
2 changes: 1 addition & 1 deletion shapely/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ShapelyError(Exception):


class UnsupportedGEOSVersionError(ShapelyError):
"""Raised when the system's GEOS library version is unsupported."""
"""Raised when the GEOS library version does not support a certain operation."""


class ReadingError(ShapelyError):
Expand Down
23 changes: 17 additions & 6 deletions shapely/set_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from . import box # NOQA
from . import Geometry # NOQA
from . import GeometryType, lib
from .decorators import multithreading_enabled, requires_geos, UnsupportedGEOSOperation
from .decorators import multithreading_enabled, requires_geos
from .errors import UnsupportedGEOSVersionError

__all__ = [
"difference",
Expand Down Expand Up @@ -65,7 +66,9 @@ def difference(a, b, grid_size=None, **kwargs):

if grid_size is not None:
if lib.geos_version < (3, 9, 0):
raise UnsupportedGEOSOperation("grid_size parameter requires GEOS >= 3.9.0")
raise UnsupportedGEOSVersionError(
"grid_size parameter requires GEOS >= 3.9.0"
)

if not np.isscalar(grid_size):
raise ValueError("grid_size parameter only accepts scalar values")
Expand Down Expand Up @@ -119,7 +122,9 @@ def intersection(a, b, grid_size=None, **kwargs):

if grid_size is not None:
if lib.geos_version < (3, 9, 0):
raise UnsupportedGEOSOperation("grid_size parameter requires GEOS >= 3.9.0")
raise UnsupportedGEOSVersionError(
"grid_size parameter requires GEOS >= 3.9.0"
)

if not np.isscalar(grid_size):
raise ValueError("grid_size parameter only accepts scalar values")
Expand Down Expand Up @@ -209,7 +214,9 @@ def symmetric_difference(a, b, grid_size=None, **kwargs):

if grid_size is not None:
if lib.geos_version < (3, 9, 0):
raise UnsupportedGEOSOperation("grid_size parameter requires GEOS >= 3.9.0")
raise UnsupportedGEOSVersionError(
"grid_size parameter requires GEOS >= 3.9.0"
)

if not np.isscalar(grid_size):
raise ValueError("grid_size parameter only accepts scalar values")
Expand Down Expand Up @@ -300,7 +307,9 @@ def union(a, b, grid_size=None, **kwargs):

if grid_size is not None:
if lib.geos_version < (3, 9, 0):
raise UnsupportedGEOSOperation("grid_size parameter requires GEOS >= 3.9.0")
raise UnsupportedGEOSVersionError(
"grid_size parameter requires GEOS >= 3.9.0"
)

if not np.isscalar(grid_size):
raise ValueError("grid_size parameter only accepts scalar values")
Expand Down Expand Up @@ -377,7 +386,9 @@ def union_all(geometries, grid_size=None, axis=None, **kwargs):

if grid_size is not None:
if lib.geos_version < (3, 9, 0):
raise UnsupportedGEOSOperation("grid_size parameter requires GEOS >= 3.9.0")
raise UnsupportedGEOSVersionError(
"grid_size parameter requires GEOS >= 3.9.0"
)

if not np.isscalar(grid_size):
raise ValueError("grid_size parameter only accepts scalar values")
Expand Down
2 changes: 1 addition & 1 deletion shapely/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_requires_geos_ok(version, mocked_geos_version):
@pytest.mark.parametrize("version", ["3.7.2", "3.8.0", "3.8.1"])
def test_requires_geos_not_ok(version, mocked_geos_version):
wrapped = requires_geos(version)(func)
with pytest.raises(shapely.UnsupportedGEOSOperation):
with pytest.raises(shapely.errors.UnsupportedGEOSVersionError):
wrapped()

assert wrapped.__doc__ == expected_docstring.format(version=version, indent=" " * 4)
Expand Down
6 changes: 3 additions & 3 deletions shapely/tests/test_set_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import shapely
from shapely import Geometry
from shapely.decorators import UnsupportedGEOSOperation
from shapely.errors import UnsupportedGEOSVersionError
from shapely.testing import assert_geometries_equal

from .common import all_types, multi_polygon, point, polygon
Expand Down Expand Up @@ -57,7 +57,7 @@ def test_set_operation_array(a, func):
@pytest.mark.parametrize("grid_size", [0, 1])
def test_set_operations_prec_not_supported(func, grid_size):
with pytest.raises(
UnsupportedGEOSOperation, match="grid_size parameter requires GEOS >= 3.9.0"
UnsupportedGEOSVersionError, match="grid_size parameter requires GEOS >= 3.9.0"
):
func(point, point, grid_size)

Expand Down Expand Up @@ -158,7 +158,7 @@ def test_set_operation_reduce_all_none_arr(n, func, related_func):
@pytest.mark.parametrize("grid_size", [0, 1])
def test_set_operation_prec_reduce_not_supported(func, related_func, grid_size):
with pytest.raises(
UnsupportedGEOSOperation, match="grid_size parameter requires GEOS >= 3.9.0"
UnsupportedGEOSVersionError, match="grid_size parameter requires GEOS >= 3.9.0"
):
func([point, point], grid_size)

Expand Down
7 changes: 4 additions & 3 deletions shapely/tests/test_strtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from numpy.testing import assert_array_equal

import shapely
from shapely import box, UnsupportedGEOSOperation
from shapely import box
from shapely.errors import UnsupportedGEOSVersionError

from .common import (
assert_decreases_refcount,
Expand Down Expand Up @@ -1002,7 +1003,7 @@ def test_query_contains_properly_polygons(poly_tree, geometry, expected):

@pytest.mark.skipif(shapely.geos_version >= (3, 10, 0), reason="GEOS >= 3.10")
def test_query_dwithin_geos_version(tree):
with pytest.raises(UnsupportedGEOSOperation, match="requires GEOS >= 3.10"):
with pytest.raises(UnsupportedGEOSVersionError, match="requires GEOS >= 3.10"):
tree.query(shapely.points(0, 0), predicate="dwithin", distance=1)


Expand Down Expand Up @@ -1377,7 +1378,7 @@ def test_query_bulk_predicate_errors(tree):

@pytest.mark.skipif(shapely.geos_version >= (3, 10, 0), reason="GEOS >= 3.10")
def test_query_bulk_dwithin_geos_version(tree):
with pytest.raises(UnsupportedGEOSOperation, match="requires GEOS >= 3.10"):
with pytest.raises(UnsupportedGEOSVersionError, match="requires GEOS >= 3.10"):
tree.query_bulk(shapely.points(0, 0), predicate="dwithin", distance=1)


Expand Down

0 comments on commit ab0f9ea

Please sign in to comment.