You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/08/16 20:49:19 UTC

[GitHub] [arrow-rs] alamb commented on a change in pull request #694: Doctest for PrimitiveArray using from_iter_values.

alamb commented on a change in pull request #694:
URL: https://github.com/apache/arrow-rs/pull/694#discussion_r689849598



##########
File path: 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));
+/// }
+/// ```

Review comment:
       I am also hoping we could document creating an array using `collect` such as 
   
   ```
   let arr : Int32Array = [Some(1), Some(2)].into_iter().collect();
   ```
   
   I am not sure if that is already documented but this documentation on PrimitiveArray is already much better than nothing @novemberkilo 👍 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org