Skip to content

Commit

Permalink
input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Oct 25, 2024
1 parent 4784c18 commit 1b43efd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/geoarrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ py::array_t<PyObjectGeography> from_geoarrow(py::object input,
bool planar,
float tessellate_tolerance,
py::object geometry_encoding) {
if (!py::hasattr(input, "__arrow_c_array__")) {
throw std::invalid_argument(
"input should be an Arrow-compatible array object (i.e. has an '__arrow_c_array__' "
"method)");
}
py::tuple capsules = input.attr("__arrow_c_array__")();
py::capsule schema_capsule = capsules[0];
py::capsule array_capsule = capsules[1];
Expand Down
6 changes: 6 additions & 0 deletions tests/test_geoarrow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from packaging.version import Version

import numpy as np
import pyarrow as pa
import geoarrow.pyarrow as ga

Expand Down Expand Up @@ -102,3 +103,8 @@ def test_from_geoarrow_invalid_encoding():

with pytest.raises(ValueError, match="'geometry_encoding' should be one"):
spherely.from_geoarrow(arr, geometry_encoding="point")


def test_from_geoarrow_no_arrow_object():
with pytest.raises(ValueError, match="input should be an Arrow-compatible array"):
spherely.from_geoarrow(np.array(["POINT (1 1)"], dtype=object))

0 comments on commit 1b43efd

Please sign in to comment.