Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: fsl to list with validity #2729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions src/daft-core/src/array/ops/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,16 +1631,7 @@ impl FixedSizeListArray {
DataType::List(child_dtype) => {
let element_size = self.fixed_element_len();
let casted_child = self.flat_child.cast(child_dtype.as_ref())?;
let offsets: Offsets<i64> = match self.validity() {
None => Offsets::try_from_iter(repeat(element_size).take(self.len()))?,
Some(validity) => Offsets::try_from_iter(validity.iter().map(|v| {
if v {
element_size
} else {
0
}
}))?,
};
let offsets = Offsets::try_from_iter(repeat(element_size).take(self.len()))?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't use the validity to create the offsets as we also pass in the validity bitmap separately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch...

Ok(ListArray::new(
Field::new(self.name().to_string(), dtype.clone()),
casted_child,
Expand Down
30 changes: 30 additions & 0 deletions src/daft-core/src/array/ops/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,34 @@ mod tests {

Ok(())
}

#[test]
fn test_list_get_some_valid() -> DaftResult<()> {
let field = Field::new("foo", DataType::FixedSizeList(Box::new(DataType::Int32), 3));
let flat_child = Int32Array::from(("foo", (0..9).collect::<Vec<i32>>()));
let raw_validity = vec![true, false, true];
let validity = Some(arrow2::bitmap::Bitmap::from(raw_validity.as_slice()));
let arr = FixedSizeListArray::new(field, flat_child.into_series(), validity);
let list_dtype = DataType::List(Box::new(DataType::Int32));
let list_arr = arr.cast(&list_dtype)?;
let l = list_arr.list()?;
let element = l.get(0).unwrap();
let element = element.i32()?;
let data = element
.into_iter()
.map(|x| x.copied())
.collect::<Vec<Option<i32>>>();
let expected = vec![Some(0), Some(1), Some(2)];
assert_eq!(data, expected);
let element = l.get(2).unwrap();
let element = element.i32()?;
let data = element
.into_iter()
.map(|x| x.copied())
.collect::<Vec<Option<i32>>>();
let expected = vec![Some(6), Some(7), Some(8)];
assert_eq!(data, expected);

Ok(())
}
}
Loading