Skip to content

Commit f0646f8

Browse files
authored
Rewrite doc example of ListArray and LargeListArray (#1447)
1 parent 717216f commit f0646f8

File tree

1 file changed

+38
-48
lines changed

1 file changed

+38
-48
lines changed

arrow/src/array/array_list.rs

+38-48
Original file line numberDiff line numberDiff line change
@@ -281,30 +281,25 @@ impl<OffsetSize: OffsetSizeTrait> fmt::Debug for GenericListArray<OffsetSize> {
281281
/// # Example
282282
///
283283
/// ```
284-
/// # use arrow::array::{Array, ListArray, Int32Array};
285-
/// # use arrow::datatypes::{DataType, Int32Type};
286-
/// let data = vec![
287-
/// Some(vec![Some(0), Some(1), Some(2)]),
288-
/// None,
289-
/// Some(vec![Some(3), None, Some(5), Some(19)]),
290-
/// Some(vec![Some(6), Some(7)]),
291-
/// ];
292-
/// let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(data);
293-
/// assert_eq!(DataType::Int32, list_array.value_type());
294-
/// assert_eq!(4, list_array.len());
295-
/// assert_eq!(1, list_array.null_count());
296-
/// assert_eq!(3, list_array.value_length(0));
297-
/// assert_eq!(0, list_array.value_length(1));
298-
/// assert_eq!(4, list_array.value_length(2));
299-
/// assert_eq!(
300-
/// 19,
301-
/// list_array
302-
/// .value(2)
303-
/// .as_any()
304-
/// .downcast_ref::<Int32Array>()
305-
/// .unwrap()
306-
/// .value(3)
307-
/// )
284+
/// # use arrow::array::{Array, ListArray, Int32Array};
285+
/// # use arrow::datatypes::{DataType, Int32Type};
286+
/// let data = vec![
287+
/// Some(vec![]),
288+
/// None,
289+
/// Some(vec![Some(3), None, Some(5), Some(19)]),
290+
/// Some(vec![Some(6), Some(7)]),
291+
/// ];
292+
/// let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(data);
293+
///
294+
/// assert_eq!(false, list_array.is_valid(1));
295+
///
296+
/// let list0 = list_array.value(0);
297+
/// let list2 = list_array.value(2);
298+
/// let list3 = list_array.value(3);
299+
///
300+
/// assert_eq!(&[] as &[i32], list0.as_any().downcast_ref::<Int32Array>().unwrap().values());
301+
/// assert_eq!(false, list2.as_any().downcast_ref::<Int32Array>().unwrap().is_valid(1));
302+
/// assert_eq!(&[6, 7], list3.as_any().downcast_ref::<Int32Array>().unwrap().values());
308303
/// ```
309304
pub type ListArray = GenericListArray<i32>;
310305

@@ -313,30 +308,25 @@ pub type ListArray = GenericListArray<i32>;
313308
/// # Example
314309
///
315310
/// ```
316-
/// # use arrow::array::{Array, LargeListArray, Int64Array};
317-
/// # use arrow::datatypes::{DataType, Int64Type};
318-
/// let data = vec![
319-
/// Some(vec![Some(0), Some(1), Some(2)]),
320-
/// None,
321-
/// Some(vec![Some(3), None, Some(5), Some(19)]),
322-
/// Some(vec![Some(6), Some(7)]),
323-
/// ];
324-
/// let list_array = LargeListArray::from_iter_primitive::<Int64Type, _, _>(data);
325-
/// assert_eq!(DataType::Int64, list_array.value_type());
326-
/// assert_eq!(4, list_array.len());
327-
/// assert_eq!(1, list_array.null_count());
328-
/// assert_eq!(3, list_array.value_length(0));
329-
/// assert_eq!(0, list_array.value_length(1));
330-
/// assert_eq!(4, list_array.value_length(2));
331-
/// assert_eq!(
332-
/// 19,
333-
/// list_array
334-
/// .value(2)
335-
/// .as_any()
336-
/// .downcast_ref::<Int64Array>()
337-
/// .unwrap()
338-
/// .value(3)
339-
/// )
311+
/// # use arrow::array::{Array, LargeListArray, Int32Array};
312+
/// # use arrow::datatypes::{DataType, Int32Type};
313+
/// let data = vec![
314+
/// Some(vec![]),
315+
/// None,
316+
/// Some(vec![Some(3), None, Some(5), Some(19)]),
317+
/// Some(vec![Some(6), Some(7)]),
318+
/// ];
319+
/// let list_array = LargeListArray::from_iter_primitive::<Int32Type, _, _>(data);
320+
///
321+
/// assert_eq!(false, list_array.is_valid(1));
322+
///
323+
/// let list0 = list_array.value(0);
324+
/// let list2 = list_array.value(2);
325+
/// let list3 = list_array.value(3);
326+
///
327+
/// assert_eq!(&[] as &[i32], list0.as_any().downcast_ref::<Int32Array>().unwrap().values());
328+
/// assert_eq!(false, list2.as_any().downcast_ref::<Int32Array>().unwrap().is_valid(1));
329+
/// assert_eq!(&[6, 7], list3.as_any().downcast_ref::<Int32Array>().unwrap().values());
340330
/// ```
341331
pub type LargeListArray = GenericListArray<i64>;
342332

0 commit comments

Comments
 (0)