mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Fix the use of right hand expressions in operations (#13096)
As reported by @maxim-uvarov and pyz in the dataframes discord channel: ```nushell [[a b]; [1 1] [1 2] [2 1] [2 2] [3 1] [3 2]] | polars into-df | polars with-column ((polars col a) / (polars col b)) --name c × Type mismatch. ╭─[entry #45:1:102] 1 │ [[a b]; [1 1] [1 2] [2 1] [2 2] [3 1] [3 2]] | polars into-df | polars with-column ((polars col a) / (polars col b)) --name c · ───────┬────── · ╰── Right hand side not a dataframe expression ╰──── ``` This pull request corrects the type casting on the right hand side and allows more than just polars literal expressions.
This commit is contained in:
parent
dc76183cd5
commit
650ae537c3
1 changed files with 10 additions and 39 deletions
|
@ -63,45 +63,16 @@ fn compute_with_value(
|
||||||
op: Span,
|
op: Span,
|
||||||
right: &Value,
|
right: &Value,
|
||||||
) -> Result<Value, ShellError> {
|
) -> Result<Value, ShellError> {
|
||||||
let rhs_span = right.span();
|
let rhs = NuExpression::try_from_value(plugin, right)?;
|
||||||
match right {
|
with_operator(
|
||||||
Value::Custom { val: rhs, .. } => {
|
(plugin, engine),
|
||||||
let rhs = rhs.as_any().downcast_ref::<NuExpression>().ok_or_else(|| {
|
operator,
|
||||||
ShellError::TypeMismatch {
|
left,
|
||||||
err_message: "Right hand side not a dataframe expression".into(),
|
&rhs,
|
||||||
span: rhs_span,
|
lhs_span,
|
||||||
}
|
right.span(),
|
||||||
})?;
|
op,
|
||||||
|
)
|
||||||
match rhs.as_ref() {
|
|
||||||
polars::prelude::Expr::Literal(..) => with_operator(
|
|
||||||
(plugin, engine),
|
|
||||||
operator,
|
|
||||||
left,
|
|
||||||
rhs,
|
|
||||||
lhs_span,
|
|
||||||
right.span(),
|
|
||||||
op,
|
|
||||||
),
|
|
||||||
_ => Err(ShellError::TypeMismatch {
|
|
||||||
err_message: "Only literal expressions or number".into(),
|
|
||||||
span: right.span(),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let rhs = NuExpression::try_from_value(plugin, right)?;
|
|
||||||
with_operator(
|
|
||||||
(plugin, engine),
|
|
||||||
operator,
|
|
||||||
left,
|
|
||||||
&rhs,
|
|
||||||
lhs_span,
|
|
||||||
right.span(),
|
|
||||||
op,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_operator(
|
fn with_operator(
|
||||||
|
|
Loading…
Reference in a new issue