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/08/19 20:45:59 UTC

[arrow-rs] branch master updated: Doctest for PrimitiveArray using from_iter_values. (#694)

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 38e5d22  Doctest for PrimitiveArray using from_iter_values. (#694)
38e5d22 is described below

commit 38e5d22898fe300224b0bb310f2e73245e77efc0
Author: Navin <na...@novemberkilo.com>
AuthorDate: Fri Aug 20 06:45:54 2021 +1000

    Doctest for PrimitiveArray using from_iter_values. (#694)
    
    * Doctest for PrimitiveArray using from_iter_values.
    
    * Better example for building a PrimitiveArray.
---
 arrow/src/array/array_primitive.rs | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arrow/src/array/array_primitive.rs b/arrow/src/array/array_primitive.rs
index 9c14f88..5777a03 100644
--- a/arrow/src/array/array_primitive.rs
+++ b/arrow/src/array/array_primitive.rs
@@ -44,6 +44,19 @@ const MICROSECONDS: i64 = 1_000_000;
 const NANOSECONDS: i64 = 1_000_000_000;
 
 /// Array whose elements are of primitive types.
+///
+/// # Example: From an iterator of values
+///
+/// ```
+/// use arrow::array::{Array, PrimitiveArray};
+/// use arrow::datatypes::Int32Type;
+/// let arr: PrimitiveArray<Int32Type> = PrimitiveArray::from_iter_values((0..10).map(|x| x + 1));
+/// assert_eq!(10, arr.len());
+/// assert_eq!(0, arr.null_count());
+/// for i in 0..10i32 {
+///     assert_eq!(i + 1, arr.value(i as usize));
+/// }
+/// ```
 pub struct PrimitiveArray<T: ArrowPrimitiveType> {
     /// Underlying ArrayData
     /// # Safety