Skip to content

Commit 4f10c26

Browse files
authored
Better cast errors (#4436)
Without this PR it just shows: `Error: Vortex error: Cannot cast array with invalid values to non-nullable type.` - super hard to understand what columns are involved --------- Signed-off-by: blaginin <[email protected]>
1 parent a3cde9c commit 4f10c26

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

vortex-expr/src/exprs/cast.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ impl VTable for CastVTable {
8181

8282
fn evaluate(expr: &Self::Expr, scope: &Scope) -> VortexResult<ArrayRef> {
8383
let array = expr.child.evaluate(scope)?;
84-
compute_cast(&array, &expr.target)
84+
compute_cast(&array, &expr.target).map_err(|e| {
85+
e.with_context(format!(
86+
"Failed to cast array of dtype {} to {}",
87+
array.dtype(),
88+
expr.target
89+
))
90+
})
8591
}
8692

8793
fn return_dtype(expr: &Self::Expr, _scope: &DType) -> VortexResult<DType> {

vortex-expr/src/exprs/pack.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ impl VTable for PackVTable {
107107
let value_arrays = expr
108108
.values
109109
.iter()
110-
.map(|value_expr| value_expr.unchecked_evaluate(scope))
110+
.zip_eq(expr.names.iter())
111+
.map(|(value_expr, name)| {
112+
value_expr
113+
.unchecked_evaluate(scope)
114+
.map_err(|e| e.with_context(format!("Can't evaluate '{name}'")))
115+
})
111116
.process_results(|it| it.collect::<Vec<_>>())?;
112117
let validity = match expr.nullability {
113118
Nullability::NonNullable => Validity::NonNullable,

0 commit comments

Comments
 (0)