diff --git a/src/h3/_h3shape.py b/src/h3/_h3shape.py index 7aa7f628..a8146df0 100644 --- a/src/h3/_h3shape.py +++ b/src/h3/_h3shape.py @@ -301,7 +301,11 @@ def geo_to_h3shape(geo): # get dict geo = geo.__geo_interface__ - assert isinstance(geo, dict) # todo: remove + if not isinstance(geo, dict): + raise ValueError( + 'geo must be a dict or implement __geo_interface__, got: ' + + str(type(geo)) + ) t = geo['type'] coord = geo['coordinates'] diff --git a/tests/test_lib/polyfill/test_h3.py b/tests/test_lib/polyfill/test_h3.py index 72ddd586..fed297f8 100644 --- a/tests/test_lib/polyfill/test_h3.py +++ b/tests/test_lib/polyfill/test_h3.py @@ -302,6 +302,11 @@ def test_geo_to_h3shape_passthrough(): assert h3.geo_to_h3shape(shape) is shape +def test_geo_to_h3shape_rejects_non_dict(): + with pytest.raises(ValueError, match='dict or implement __geo_interface__'): + h3.geo_to_h3shape('not a geo object') + + def test_polyfill_down_under(): sydney = [ (-33.8556, 151.1979),