Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick Doctests for FixedSizeBinaryArray to active_release #403

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
}
}