Skip to content

Commit 2101887

Browse files
authored
test: Test that parsing WKB/WKT works with Arrow view types (#801)
Closes #796
1 parent 98cdfea commit 2101887

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/geoarrow/test_parse_wkb.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from __future__ import annotations
2+
3+
from itertools import product
4+
from typing import TYPE_CHECKING, Literal
5+
6+
import pytest
7+
import shapely
8+
from arro3.core import Array, DataType, Field, Schema, Table
9+
10+
from lonboard import ScatterplotLayer, viz
11+
from lonboard._geoarrow.parse_wkb import parse_serialized_table
12+
13+
if TYPE_CHECKING:
14+
from numpy.typing import NDArray
15+
16+
17+
@pytest.mark.parametrize(
18+
("serialization", "view_type"),
19+
list(product(["wkb", "wkt"], [True, False])),
20+
)
21+
def test_parse_wkb(
22+
serialization: Literal["wkb", "wkt"],
23+
view_type: bool, # noqa: FBT001
24+
):
25+
points = shapely.points([1, 2, 3], [4, 5, 6])
26+
if serialization == "wkb":
27+
serialized_np_arr: NDArray = shapely.to_wkb(points)
28+
geoarrow_type = "geoarrow.wkb"
29+
else:
30+
serialized_np_arr = shapely.to_wkt(points)
31+
geoarrow_type = "geoarrow.wkt"
32+
33+
if serialization == "wkb":
34+
dtype = DataType.binary_view() if view_type else DataType.binary()
35+
else:
36+
dtype = DataType.string_view() if view_type else DataType.string()
37+
38+
arr = Array(list(serialized_np_arr), type=dtype)
39+
schema = Schema(
40+
[
41+
Field(
42+
"geometry",
43+
arr.type,
44+
metadata={"ARROW:extension:name": geoarrow_type},
45+
),
46+
],
47+
)
48+
table = Table.from_arrays([arr], schema=schema)
49+
split_tables = parse_serialized_table(table)
50+
assert len(split_tables) == 1
51+
assert (
52+
split_tables[0].schema.field(0).metadata_str["ARROW:extension:name"]
53+
== "geoarrow.point"
54+
)
55+
56+
m = viz(table)
57+
assert isinstance(m.layers[0], ScatterplotLayer)

0 commit comments

Comments
 (0)