Skip to content

Commit e075dd5

Browse files
authored
Restore ignored doctests (#1128)
Closes #1117, closes #1116 Some other various docs updates.
1 parent 7e8517b commit e075dd5

File tree

9 files changed

+227
-212
lines changed

9 files changed

+227
-212
lines changed

rust/geoarrow-array/src/array/mixed.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ use crate::trait_::GeoArrowArray;
6060
/// - 37: GeometryCollection ZM
6161
#[derive(Debug, Clone)]
6262
pub struct MixedGeometryArray {
63-
// We store the coord type and dimension separately because there's no NativeType::Mixed
64-
// variant
6563
pub(crate) coord_type: CoordType,
6664
pub(crate) dim: Dimension,
6765

68-
/// Invariant: every item in `type_ids` is `> 0 && < fields.len()` if `type_ids` are not provided. If `type_ids` exist in the NativeType, then every item in `type_ids` is `> 0 && `
66+
/// Invariant: every item in `type_ids` is `> 0 && < fields.len()` if `type_ids` are not provided.
6967
pub(crate) type_ids: ScalarBuffer<i8>,
7068

7169
/// Invariant: `offsets.len() == type_ids.len()`
@@ -496,7 +494,7 @@ impl MixedGeometryArray {
496494
}
497495
6 => Geometry::MultiPolygon(self.multi_polygons.value(offset).expect(expect_msg)),
498496
7 => {
499-
panic!("nested geometry collections not supported")
497+
panic!("nested geometry collections not supported in GeoArrow")
500498
}
501499
_ => panic!("unknown type_id {}", type_id),
502500
}

rust/geoarrow-array/src/array/wkb.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ use crate::util::{offsets_buffer_i32_to_i64, offsets_buffer_i64_to_i32};
1919

2020
/// An immutable array of WKB geometries.
2121
///
22-
/// This is semantically equivalent to `Vec<Option<Wkb>>` due to the internal validity bitmap.
22+
/// This is stored either as an Arrow [`BinaryArray`] or [`LargeBinaryArray`] and is semantically
23+
/// equivalent to `Vec<Option<Wkb>>` due to the internal validity bitmap.
2324
///
24-
/// This is stored either as an Arrow [`BinaryArray`] or [`LargeBinaryArray`].
25+
/// Refer to [`crate::cast`] for converting this array to other GeoArrow array types.
2526
#[derive(Debug, Clone, PartialEq)]
2627
pub struct GenericWkbArray<O: OffsetSizeTrait> {
2728
pub(crate) data_type: WkbType,

rust/geoarrow-array/src/array/wkb_view.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ use crate::{GeoArrowArray, GeoArrowArrayAccessor, GeoArrowType, IntoArrow};
1414

1515
/// An immutable array of WKB geometries.
1616
///
17-
/// This is semantically equivalent to `Vec<Option<Wkb>>` due to the internal validity bitmap.
17+
/// This is stored as an Arrow [`BinaryViewArray`] and is semantically equivalent to
18+
/// `Vec<Option<Wkb>>` due to the internal validity bitmap.
1819
///
19-
/// This is stored as an Arrow [`BinaryViewArray`]
20+
/// Refer to [`crate::cast`] for converting this array to other GeoArrow array types.
2021
#[derive(Debug, Clone, PartialEq)]
2122
pub struct WkbViewArray {
2223
pub(crate) data_type: WkbType,

rust/geoarrow-array/src/array/wkt.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ use crate::util::{offsets_buffer_i32_to_i64, offsets_buffer_i64_to_i32};
2020

2121
/// An immutable array of WKT geometries using GeoArrow's in-memory representation.
2222
///
23-
/// This is semantically equivalent to `Vec<Option<WKT>>` due to the internal validity bitmap.
23+
/// This is a wrapper around an Arrow [GenericStringArray] and is semantically equivalent to
24+
/// `Vec<Option<WKT>>` due to the internal validity bitmap.
2425
///
25-
/// This is a wrapper around an Arrow [GenericStringArray], but additionally stores an
26-
/// [ArrayMetadata] so that we can persist CRS information about the data.
27-
///
28-
/// Refer to [`crate::io::wkt`] for encoding and decoding this array to the native array types.
26+
/// Refer to [`crate::cast`] for converting this array to other GeoArrow array types.
2927
#[derive(Debug, Clone, PartialEq)]
3028
pub struct GenericWktArray<O: OffsetSizeTrait> {
3129
pub(crate) data_type: WktType,

rust/geoarrow-array/src/array/wkt_view.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ use crate::{GeoArrowArray, GeoArrowArrayAccessor, GeoArrowType, IntoArrow};
1515

1616
/// An immutable array of WKT geometries.
1717
///
18-
/// This is semantically equivalent to `Vec<Option<Wkt>>` due to the internal validity bitmap.
18+
/// This is stored as an Arrow [`StringViewArray`] and is semantically equivalent to
19+
/// `Vec<Option<Wkt>>` due to the internal validity bitmap.
1920
///
20-
/// This is stored as an Arrow [`StringViewArray`].
21+
/// Refer to [`crate::cast`] for converting this array to other GeoArrow array types.
2122
#[derive(Debug, Clone, PartialEq)]
2223
pub struct WktViewArray {
2324
pub(crate) data_type: WktType,

rust/geoarrow-array/src/cast.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! Helper functions for downcasting [`dyn GeoArrowArray`][GeoArrowArray] to concrete types.
1+
//! Helper functions for downcasting [`dyn GeoArrowArray`][GeoArrowArray] to concrete types and for
2+
//! converting between GeoArrow array representations.
23
34
use std::sync::Arc;
45

@@ -303,7 +304,7 @@ impl AsGeoArrowArray for Arc<dyn GeoArrowArray> {
303304
}
304305
}
305306

306-
/// Convert a [GeoArrowArray] to a [GenericWkbArray].
307+
/// Convert a [GeoArrowArray] to a [`GenericWkbArray`].
307308
pub fn to_wkb<O: OffsetSizeTrait>(arr: &dyn GeoArrowArray) -> Result<GenericWkbArray<O>> {
308309
use GeoArrowType::*;
309310
match arr.data_type() {
@@ -371,7 +372,7 @@ fn impl_to_wkb<'a, O: OffsetSizeTrait>(
371372
Ok(WkbBuilder::from_nullable_geometries(geoms.as_slice(), wkb_type).finish())
372373
}
373374

374-
/// Convert a [GeoArrowArray] to a [WkbViewArray].
375+
/// Convert a [GeoArrowArray] to a [`WkbViewArray`].
375376
pub fn to_wkb_view(arr: &dyn GeoArrowArray) -> Result<WkbViewArray> {
376377
use GeoArrowType::*;
377378
match arr.data_type() {
@@ -417,7 +418,8 @@ fn impl_to_wkb_view<'a>(geo_arr: &'a impl GeoArrowArrayAccessor<'a>) -> Result<W
417418
))
418419
}
419420

420-
/// Parse a [GenericWkbArray] to a [GeoArrowArray] with the designated [GeoArrowType].
421+
/// Parse a [`GenericWkbArray`] or [`WkbViewArray`] to a [`GeoArrowArray`] with the designated
422+
/// [`GeoArrowType`].
421423
///
422424
/// Note that the GeoArrow metadata on the new array is taken from `to_type` **not** the original
423425
/// array. Ensure you construct the [GeoArrowType] with the correct metadata.
@@ -493,7 +495,7 @@ pub fn from_wkb<'a, A: GenericWkbArrayType<'a>>(
493495
Ok(result)
494496
}
495497

496-
/// Convert a [GeoArrowArray] to a [GenericWktArray].
498+
/// Convert a [GeoArrowArray] to a [`GenericWktArray`].
497499
pub fn to_wkt<O: OffsetSizeTrait>(arr: &dyn GeoArrowArray) -> Result<GenericWktArray<O>> {
498500
use GeoArrowType::*;
499501
match arr.data_type() {
@@ -559,7 +561,7 @@ fn impl_to_wkt<'a, O: OffsetSizeTrait>(
559561
Ok(GenericWktArray::new(builder.finish(), metadata))
560562
}
561563

562-
/// Convert a [GeoArrowArray] to a [WktViewArray].
564+
/// Convert a [GeoArrowArray] to a [`WktViewArray`].
563565
pub fn to_wkt_view(arr: &dyn GeoArrowArray) -> Result<WktViewArray> {
564566
use GeoArrowType::*;
565567
match arr.data_type() {
@@ -598,7 +600,8 @@ fn impl_to_wkt_view<'a>(geo_arr: &'a impl GeoArrowArrayAccessor<'a>) -> Result<W
598600
Ok(WktViewArray::new(builder.finish(), metadata))
599601
}
600602

601-
/// Parse a [GenericWktArray] to a [GeoArrowArray] with the designated [GeoArrowType].
603+
/// Parse a [`GenericWktArray`] or [`WktViewArray`] to a [`GeoArrowArray`] with the designated
604+
/// [`GeoArrowType`].
602605
///
603606
/// Note that the GeoArrow metadata on the new array is taken from `to_type` **not** the original
604607
/// array. Ensure you construct the [GeoArrowType] with the correct metadata.

rust/geoarrow-array/src/datatypes.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ impl GeoArrowType {
9696

9797
/// Get the [`Dimension`] of this data type, if it has one.
9898
///
99-
/// "Unknown" native arrays can hold all dimensions.
100-
///
101-
/// WKB and WKT arrays will return `None`.
99+
/// [`GeometryArray``], WKB and WKT arrays will return `None`.
102100
pub fn dimension(&self) -> Option<Dimension> {
103101
use GeoArrowType::*;
104102
match self {
@@ -140,11 +138,13 @@ impl GeoArrowType {
140138
///
141139
/// # Examples
142140
///
143-
/// ```ignore
144-
/// use geoarrow::{array::CoordType, datatypes::{GeoArrowType, Dimension}};
145-
/// use arrow_schema::DataType;
146-
///
147-
/// let data_type = GeoArrowType::Point(CoordType::Interleaved, Dimension::XY).to_data_type();
141+
/// ```
142+
/// # use arrow_schema::DataType;
143+
/// # use geoarrow_array::GeoArrowType;
144+
/// # use geoarrow_schema::{CoordType, Dimension, PointType};
145+
/// #
146+
/// let point_type = PointType::new(CoordType::Interleaved, Dimension::XY, Default::default());
147+
/// let data_type = GeoArrowType::Point(point_type).to_data_type();
148148
/// assert!(matches!(data_type, DataType::FixedSizeList(_, _)));
149149
/// ```
150150
pub fn to_data_type(&self) -> DataType {
@@ -173,13 +173,15 @@ impl GeoArrowType {
173173
///
174174
/// # Examples
175175
///
176-
/// ```ignore
177-
/// use geoarrow::datatypes::GeoArrowType;
178-
///
179-
/// let geo_data_type = GeoArrowType::Point(Default::default(), 2.try_into().unwrap());
180-
/// let field = geo_data_type.to_field("geometry", false);
176+
/// ```
177+
/// # use geoarrow_array::GeoArrowType;
178+
/// # use geoarrow_schema::{CoordType, Dimension, PointType};
179+
/// #
180+
/// let point_type = PointType::new(CoordType::Interleaved, Dimension::XY, Default::default());
181+
/// let geoarrow_type = GeoArrowType::Point(point_type);
182+
/// let field = geoarrow_type.to_field("geometry", true);
181183
/// assert_eq!(field.name(), "geometry");
182-
/// assert!(!field.is_nullable());
184+
/// assert!(field.is_nullable());
183185
/// assert_eq!(field.metadata()["ARROW:extension:name"], "geoarrow.point");
184186
/// ```
185187
pub fn to_field<N: Into<String>>(&self, name: N, nullable: bool) -> Field {
@@ -209,11 +211,15 @@ impl GeoArrowType {
209211
///
210212
/// # Examples
211213
///
212-
/// ```ignore
213-
/// use geoarrow::{array::CoordType, datatypes::GeoArrowType};
214+
/// ```
215+
/// # use geoarrow_array::GeoArrowType;
216+
/// # use geoarrow_schema::{CoordType, Dimension, PointType};
217+
/// #
218+
/// let point_type = PointType::new(CoordType::Interleaved, Dimension::XY, Default::default());
219+
/// let geoarrow_type = GeoArrowType::Point(point_type);
220+
/// let new_type = geoarrow_type.with_coord_type(CoordType::Separated);
214221
///
215-
/// let geo_data_type = GeoArrowType::Point(CoordType::Interleaved, 2.try_into().unwrap());
216-
/// let separated_geo_data_type = geo_data_type.with_coord_type(CoordType::Separated);
222+
/// assert_eq!(new_type.coord_type(), Some(CoordType::Separated));
217223
/// ```
218224
pub fn with_coord_type(self, coord_type: CoordType) -> GeoArrowType {
219225
use GeoArrowType::*;
@@ -237,11 +243,15 @@ impl GeoArrowType {
237243
///
238244
/// # Examples
239245
///
240-
/// ```ignore
241-
/// use geoarrow::datatypes::GeoArrowType;
246+
/// ```
247+
/// # use geoarrow_array::GeoArrowType;
248+
/// # use geoarrow_schema::{CoordType, Dimension, PointType};
249+
/// #
250+
/// let point_type = PointType::new(CoordType::Interleaved, Dimension::XY, Default::default());
251+
/// let geoarrow_type = GeoArrowType::Point(point_type);
252+
/// let new_type = geoarrow_type.with_dimension(Dimension::XYZ);
242253
///
243-
/// let geo_data_type = GeoArrowType::Point(Default::default(), 2.try_into().unwrap());
244-
/// let geo_data_type_3d = geo_data_type.with_dimension(3.try_into().unwrap());
254+
/// assert_eq!(new_type.dimension(), Some(Dimension::XYZ));
245255
/// ```
246256
pub fn with_dimension(self, dim: Dimension) -> GeoArrowType {
247257
use GeoArrowType::*;
@@ -357,7 +367,7 @@ impl TryFrom<&Field> for GeoArrowType {
357367
},
358368
name => {
359369
return Err(GeoArrowError::General(format!(
360-
"Expected GeoArrow native type, got '{}'.\nIf you're passing a serialized GeoArrow type like 'geoarrow.wkb' or 'geoarrow.wkt', you need to parse to a native representation.",
370+
"Expected GeoArrow type, got '{}'.",
361371
name
362372
)));
363373
}
@@ -392,9 +402,11 @@ impl TryFrom<&Field> for GeoArrowType {
392402
},
393403
DataType::Binary => Wkb(WkbType::new(metadata)),
394404
DataType::LargeBinary => LargeWkb(WkbType::new(metadata)),
405+
DataType::BinaryView => WkbView(WkbType::new(metadata)),
395406
DataType::Utf8 => Wkt(WktType::new(metadata)),
396407
DataType::LargeUtf8 => LargeWkt(WktType::new(metadata)),
397-
_ => return Err(GeoArrowError::General("Only FixedSizeList, Struct, Binary, LargeBinary, String, and LargeString arrays are unambigously typed for a GeoArrow type and can be used without extension metadata.\nEnsure your array input has GeoArrow metadata.".to_string())),
408+
DataType::Utf8View => WktView(WktType::new(metadata)),
409+
_ => return Err(GeoArrowError::General("Only FixedSizeList, Struct, Binary, LargeBinary, BinaryView, String, LargeString, and StringView arrays are unambigously typed for a GeoArrow type and can be used without extension metadata.\nEnsure your array input has GeoArrow metadata.".to_string())),
398410
};
399411
Ok(data_type)
400412
}

rust/geoarrow-array/src/scalar/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
//! For all "native" GeoArrow scalar types, (all types defined in this module) it is `O(1)` and
44
//! allocation-free for any coordinate access.
55
//!
6-
//! For "serialized" scalars emitted from the [`GenericWkbArray`][crate::array::GenericWkbArray] and
7-
//! [`GenericWktArray`][crate::array::GenericWktArray], there is an initial parsing step when accessing the
8-
//! scalar from the [`ArrayAccessor`][crate::ArrayAccessor] trait.
6+
//! For "serialized" scalars emitted from the [`GenericWkbArray`][crate::array::GenericWkbArray],
7+
//! [`WkbViewArray`][crate::array::WkbViewArray],
8+
//! [`GenericWktArray`][crate::array::GenericWktArray], and
9+
//! [`WktViewArray`][crate::array::WktViewArray], there is an initial parsing step when accessing
10+
//! the scalar from the [`ArrayAccessor`][crate::ArrayAccessor] trait.
911
//!
1012
//! All scalars implement [`geo_traits`]. You can iterate through geometry parts directly using the
1113
//! APIs exposed by [`geo_traits`]. Or, for simplicity at the cost of a memory copy, you can use
12-
//! the traits defined in [`geo_traits::to_geo`] to convert these scalars to [`geo_types`] objects.
14+
//! the traits defined in [`geo_traits::to_geo`] to convert these scalars to [`geo_types`] objects
15+
//! (though keep in mind [`geo_types`] only supports 2D geometries).
1316
1417
mod coord;
1518
mod geometry;

0 commit comments

Comments
 (0)