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/06/22 10:45:46 UTC

[GitHub] [arrow-rs] alamb commented on a change in pull request #474: Doctest for GenericListArray.

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



##########
File path: arrow/src/array/array_list.rs
##########
@@ -50,6 +50,9 @@ impl OffsetSizeTrait for i64 {
     }
 }
 
+/// Generic struct for a primitive Array
+///
+/// Instead of using `GenericListArray` directly, consider using `ListArray` or `LargeListArray`

Review comment:
       ```suggestion
   /// Instead of using `GenericListArray` directly, consider using [`ListArray`] or [`LargeListArray`]
   ```
   
   If you use ```[`ListArray`]``` instead, the docs will include a hyperlink to the class

##########
File path: arrow/src/array/array_list.rs
##########
@@ -284,10 +287,67 @@ impl<OffsetSize: OffsetSizeTrait> fmt::Debug for GenericListArray<OffsetSize> {
 
 /// A list array where each element is a variable-sized sequence of values with the same
 /// type whose memory offsets between elements are represented by a i32.
+///
+/// # Example
+///
+/// ```
+///     # use arrow::array::{Array, ListArray, Int32Array};
+///     # use arrow::datatypes::{DataType, Int32Type};
+///     let data = vec![
+///        Some(vec![Some(0), Some(1), Some(2)]),
+///        None,
+///        Some(vec![Some(3), None, Some(5), Some(19)]),
+///        Some(vec![Some(6), Some(7)]),
+///     ];
+///     let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(data);
+///     assert_eq!(DataType::Int32, list_array.value_type());
+///     assert_eq!(4, list_array.len());
+///     assert_eq!(1, list_array.null_count());
+///     assert_eq!(3, list_array.value_length(0));
+///     assert_eq!(0, list_array.value_length(1));
+///     assert_eq!(4, list_array.value_length(2));
+///     assert_eq!(
+///         0,
+///         list_array
+///         .value(0)
+///         .as_any()
+///         .downcast_ref::<Int32Array>()
+///         .unwrap()
+///         .value(0)
+///     )

Review comment:
       ```suggestion
   ///     assert_eq!(
   ///         19,
   ///         list_array
   ///         .value(2)
   ///         .as_any()
   ///         .downcast_ref::<Int32Array>()
   ///         .unwrap()
   ///         .value(3)
   ///     )
   ```
   
   
   I suggest picking something other than the first element to use (so readers can more easily figure out what the three different parameters here mean). As written everything is zero so it may be confusing

##########
File path: arrow/src/array/array_list.rs
##########
@@ -284,10 +287,67 @@ impl<OffsetSize: OffsetSizeTrait> fmt::Debug for GenericListArray<OffsetSize> {
 
 /// A list array where each element is a variable-sized sequence of values with the same
 /// type whose memory offsets between elements are represented by a i32.
+///
+/// # Example
+///
+/// ```
+///     # use arrow::array::{Array, ListArray, Int32Array};
+///     # use arrow::datatypes::{DataType, Int32Type};
+///     let data = vec![
+///        Some(vec![Some(0), Some(1), Some(2)]),
+///        None,
+///        Some(vec![Some(3), None, Some(5), Some(19)]),
+///        Some(vec![Some(6), Some(7)]),
+///     ];
+///     let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(data);
+///     assert_eq!(DataType::Int32, list_array.value_type());
+///     assert_eq!(4, list_array.len());
+///     assert_eq!(1, list_array.null_count());
+///     assert_eq!(3, list_array.value_length(0));
+///     assert_eq!(0, list_array.value_length(1));
+///     assert_eq!(4, list_array.value_length(2));
+///     assert_eq!(
+///         0,
+///         list_array
+///         .value(0)
+///         .as_any()
+///         .downcast_ref::<Int32Array>()
+///         .unwrap()
+///         .value(0)
+///     )
+/// ```
 pub type ListArray = GenericListArray<i32>;
 
 /// A list array where each element is a variable-sized sequence of values with the same
 /// type whose memory offsets between elements are represented by a i64.
+/// # Example
+///
+/// ```
+///     # use arrow::array::{Array, LargeListArray, Int64Array};
+///     # use arrow::datatypes::{DataType, Int64Type};
+///     let data = vec![
+///        Some(vec![Some(0), Some(1), Some(2)]),
+///        None,
+///        Some(vec![Some(3), None, Some(5), Some(19)]),
+///        Some(vec![Some(6), Some(7)]),
+///     ];
+///     let list_array = LargeListArray::from_iter_primitive::<Int64Type, _, _>(data);
+///     assert_eq!(DataType::Int64, list_array.value_type());
+///     assert_eq!(4, list_array.len());
+///     assert_eq!(1, list_array.null_count());
+///     assert_eq!(3, list_array.value_length(0));
+///     assert_eq!(0, list_array.value_length(1));
+///     assert_eq!(4, list_array.value_length(2));
+///     assert_eq!(
+///         0,
+///         list_array
+///         .value(0)
+///         .as_any()
+///         .downcast_ref::<Int64Array>()
+///         .unwrap()
+///         .value(0)
+///     )

Review comment:
       ```suggestion
   ///     assert_eq!(
   ///         19,
   ///         list_array
   ///         .value(2)
   ///         .as_any()
   ///         .downcast_ref::<Int64Array>()
   ///         .unwrap()
   ///         .value(3)
   ///     )
   ```




-- 
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.

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