Skip to content

Commit

Permalink
Doctests for FixedSizeBinaryArray (#378)
Browse files Browse the repository at this point in the history
* Doctests for BooleanArray.

* Update arrow/src/array/array_boolean.rs

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>

* Doctests for FixedSizeBinaryArray.

* Fix formatting.

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
  • Loading branch information
Navin and alamb authored May 29, 2021
1 parent e801d4b commit d9017ee
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions arrow/src/array/array_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -449,7 +472,7 @@ impl FixedSizeBinaryArray {

/// Create an array from an iterable argument of byte slices.
///
/// # Examles
/// # Examples
///
/// ```
/// use arrow::array::FixedSizeBinaryArray;
Expand Down Expand Up @@ -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())
}
}

0 comments on commit d9017ee

Please sign in to comment.