From f77d8284cdbc60ed9929e32e613e8d4445da686a Mon Sep 17 00:00:00 2001 From: Navin Date: Sat, 29 May 2021 20:54:13 +1000 Subject: [PATCH] Doctests for FixedSizeBinaryArray (#378) * Doctests for BooleanArray. * Update arrow/src/array/array_boolean.rs Co-authored-by: Andrew Lamb * Doctests for FixedSizeBinaryArray. * Fix formatting. Co-authored-by: Andrew Lamb --- arrow/src/array/array_binary.rs | 51 +++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/arrow/src/array/array_binary.rs b/arrow/src/array/array_binary.rs index bd04afa4c1fa..0cb4db485239 100644 --- a/arrow/src/array/array_binary.rs +++ b/arrow/src/array/array_binary.rs @@ -316,6 +316,29 @@ impl From> for GenericBinaryArray< } /// A type of `FixedSizeListArray` whose elements are binaries. +/// +/// # Examples +/// +/// Create an array from an iterable argument of byte slices. +/// +/// ``` +/// use arrow::array::{Array, FixedSizeBinaryArray}; +/// let input_arg = vec![ vec![1, 2], vec![3, 4], vec![5, 6] ]; +/// let arr = FixedSizeBinaryArray::try_from_iter(input_arg.into_iter()).unwrap(); +/// +/// assert_eq!(3, arr.len()); +/// +/// ``` +/// Create an array from an iterable argument of sparse byte slices. +/// Sparsity means that the input argument can contain `None` items. +/// ``` +/// use arrow::array::{Array, FixedSizeBinaryArray}; +/// let input_arg = vec![ None, Some(vec![7, 8]), Some(vec![9, 10]), None, Some(vec![13, 14]) ]; +/// let arr = FixedSizeBinaryArray::try_from_sparse_iter(input_arg.into_iter()).unwrap(); +/// assert_eq!(5, arr.len()) +/// +/// ``` +/// pub struct FixedSizeBinaryArray { data: ArrayData, value_data: RawPtrBox, @@ -364,7 +387,7 @@ impl FixedSizeBinaryArray { /// Sparsity means that items returned by the iterator are optional, i.e input argument can /// contain `None` items. /// - /// # Examles + /// # Examples /// /// ``` /// use arrow::array::FixedSizeBinaryArray; @@ -449,7 +472,7 @@ impl FixedSizeBinaryArray { /// Create an array from an iterable argument of byte slices. /// - /// # Examles + /// # Examples /// /// ``` /// use arrow::array::FixedSizeBinaryArray; @@ -1154,4 +1177,28 @@ mod tests { format!("{:?}", arr) ); } + + #[test] + fn test_fixed_size_binary_array_from_iter() { + let input_arg = vec![vec![1, 2], vec![3, 4], vec![5, 6]]; + let arr = FixedSizeBinaryArray::try_from_iter(input_arg.into_iter()).unwrap(); + + assert_eq!(2, arr.value_length()); + assert_eq!(3, arr.len()) + } + + #[test] + fn test_fixed_size_binary_array_from_sparse_iter() { + let input_arg = vec![ + None, + Some(vec![7, 8]), + Some(vec![9, 10]), + None, + Some(vec![13, 14]), + ]; + let arr = + FixedSizeBinaryArray::try_from_sparse_iter(input_arg.into_iter()).unwrap(); + assert_eq!(2, arr.value_length()); + assert_eq!(5, arr.len()) + } }