-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
Describe the bug
When casting a ListArray using the cast kernel, the resulting null count is incorrect
To Reproduce
use std::sync::Arc;
use arrow::{array::{Array, ArrayRef, ListArray}, datatypes::{DataType, Field, Int32Type, UInt32Type}};
fn main() {
// Form the list [[0, -11, -22], null]
let data = vec![
Some(vec![Some(0), Some(-11), Some(-22)]),
None,
];
let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(data);
assert_eq!(DataType::Int32, list_array.value_type());
assert_eq!(2, list_array.len());
assert_eq!(1, list_array.null_count());
let list_array: ArrayRef = Arc::new(list_array);
// Cast to UInt32, resulting in
// the list [[0, null, null], null]
let new_datatype = DataType::List(Box::new(Field::new("item", DataType::UInt32, true)));
let cast_array = arrow::compute::cast(&list_array, &new_datatype).unwrap();
let cast_array = cast_array.as_any().downcast_ref::<ListArray>().unwrap();
let data = vec![
Some(vec![Some(0), None, None]),
None,
];
let expected_array = ListArray::from_iter_primitive::<UInt32Type, _, _>(data);
assert_eq!(expected_array.null_count(), 1);
// currently fails cast_array has a null count of 2 (not 1)
assert_eq!(cast_array.null_count(), 1);
// the expected array should be the same as well
assert_eq!(cast_array, &expected_array);
}Results in this failure:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `2`,
right: `1`', src/main.rs:34:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expected behavior
The test program above should pass
Additional context
Found while adding validation to #810
Reactions are currently unavailable