|
5 | 5 | from typing import TYPE_CHECKING, Any |
6 | 6 |
|
7 | 7 | import numpy as np |
8 | | -from arro3.core import ( |
9 | | - Array, |
10 | | - ChunkedArray, |
11 | | - DataType, |
12 | | - fixed_size_list_array, |
13 | | -) |
| 8 | +from arro3.core import Array, ChunkedArray, DataType, Field, fixed_size_list_array |
14 | 9 |
|
| 10 | +from lonboard._geoarrow.extension_types import CoordinateDimension, coord_storage_type |
15 | 11 | from lonboard._geoarrow.ops.coord_layout import convert_struct_column_to_interleaved |
16 | | -from lonboard._serialization import ( |
17 | | - ACCESSOR_SERIALIZATION, |
18 | | -) |
| 12 | +from lonboard._serialization import ACCESSOR_SERIALIZATION |
19 | 13 | from lonboard.traits._base import FixedErrorTraitType |
20 | 14 |
|
21 | 15 | if TYPE_CHECKING: |
@@ -63,8 +57,27 @@ def _numpy_to_arrow(self, obj: BaseArrowLayer, value: np.ndarray) -> ChunkedArra |
63 | 57 | info="Point array to have 2 or 3 as its second dimension", |
64 | 58 | ) |
65 | 59 |
|
66 | | - assert np.issubdtype(value.dtype, np.float64) |
67 | | - array = fixed_size_list_array(value.ravel("C"), list_size) |
| 60 | + if not np.issubdtype(value.dtype, np.float64): |
| 61 | + self.error(obj, value, info="Point array to have float64 type.") |
| 62 | + |
| 63 | + # Set geoarrow extension metadata |
| 64 | + field = Field( |
| 65 | + "", |
| 66 | + coord_storage_type( |
| 67 | + interleaved=True, |
| 68 | + dims=CoordinateDimension.XY |
| 69 | + if list_size == 2 |
| 70 | + else CoordinateDimension.XYZ, |
| 71 | + ), |
| 72 | + nullable=True, |
| 73 | + metadata={"ARROW:extension:name": "geoarrow.point"}, |
| 74 | + ) |
| 75 | + array = fixed_size_list_array( |
| 76 | + value.ravel("C"), |
| 77 | + list_size, |
| 78 | + type=field, |
| 79 | + ) |
| 80 | + |
68 | 81 | return ChunkedArray([array]) |
69 | 82 |
|
70 | 83 | def validate( |
|
0 commit comments