You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/05/29 10:54:20 UTC

[arrow-rs] branch master updated: Doctests for FixedSizeBinaryArray (#378)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new d9017ee  Doctests for FixedSizeBinaryArray (#378)
d9017ee is described below

commit d9017ee9693727f039336a782c17b0533063b46d
Author: Navin <na...@cogent.co>
AuthorDate: Sat May 29 20:54:13 2021 +1000

    Doctests for FixedSizeBinaryArray (#378)
    
    * Doctests for BooleanArray.
    
    * Update arrow/src/array/array_boolean.rs
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
    
    * Doctests for FixedSizeBinaryArray.
    
    * Fix formatting.
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
 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 bd04afa..0cb4db4 100644
--- a/arrow/src/array/array_binary.rs
+++ b/arrow/src/array/array_binary.rs
@@ -316,6 +316,29 @@ impl<T: BinaryOffsetSizeTrait> From<GenericListArray<T>> 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<u8>,
@@ -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())
+    }
 }