Skip to content

Commit 245ffd2

Browse files
committed
fix sparse array in the no-patches case
1 parent b4b632e commit 245ffd2

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

encodings/sparse/src/compute/take.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use crate::{SparseArray, SparseEncoding};
88
impl TakeFn<SparseArray> for SparseEncoding {
99
fn take(&self, array: &SparseArray, take_indices: &Array) -> VortexResult<Array> {
1010
let Some(new_patches) = array.patches().take(take_indices)? else {
11-
return Ok(ConstantArray::new(array.fill_scalar(), take_indices.len()).into_array());
11+
let result_nullability =
12+
array.dtype().nullability() | take_indices.dtype().nullability();
13+
let result_fill_scalar = array
14+
.fill_scalar()
15+
.cast(&array.dtype().with_nullability(result_nullability))?;
16+
return Ok(ConstantArray::new(result_fill_scalar, take_indices.len()).into_array());
1217
};
1318

1419
SparseArray::try_new_from_patches(new_patches, take_indices.len(), array.fill_scalar())

vortex-array/src/compute/take.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,15 @@ pub fn take(array: impl AsRef<Array>, indices: impl AsRef<Array>) -> VortexResul
113113
#[cfg(debug_assertions)]
114114
{
115115
// If either the indices or the array are nullable, the result should be nullable.
116-
let expected_nullability =
117-
(indices.dtype().is_nullable() || array.dtype().is_nullable()).into();
116+
let expected_nullability = indices.dtype().nullability() | array.dtype().nullability();
118117
assert_eq!(
119118
taken.dtype(),
120119
&array.dtype().with_nullability(expected_nullability),
121-
"Take result should be nullable if either the indices or the array are nullable"
120+
"Take result ({}) should be nullable if either the indices ({}) or the array ({}) are nullable. ({})",
121+
taken.dtype(),
122+
indices.dtype().nullability().verbose_display(),
123+
array.dtype().nullability().verbose_display(),
124+
array.encoding(),
122125
);
123126
}
124127

@@ -140,10 +143,11 @@ pub fn take_into(
140143
assert_eq!(
141144
builder.dtype(),
142145
&array.dtype().with_nullability(expected_nullability),
143-
"Take_into result ({}) should be nullable if, and only if, either the indices ({}) or the array are nullable ({})",
146+
"Take_into result ({}) should be nullable if, and only if, either the indices ({}) or the array ({}) are nullable. ({})",
144147
builder.dtype(),
145148
indices.dtype().nullability().verbose_display(),
146149
array.dtype().nullability().verbose_display(),
150+
array.encoding(),
147151
);
148152
}
149153

0 commit comments

Comments
 (0)