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,33 +63,6 @@ fn compute_with_value(
|
|||
op: Span,
|
||||
right: &Value,
|
||||
) -> Result<Value, ShellError> {
|
||||
let rhs_span = right.span();
|
||||
match right {
|
||||
Value::Custom { val: rhs, .. } => {
|
||||
let rhs = rhs.as_any().downcast_ref::<NuExpression>().ok_or_else(|| {
|
||||
ShellError::TypeMismatch {
|
||||
err_message: "Right hand side not a dataframe expression".into(),
|
||||
span: rhs_span,
|
||||
}
|
||||
})?;
|
||||
|
||||
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),
|
||||
|
@ -100,8 +73,6 @@ fn compute_with_value(
|
|||
right.span(),
|
||||
op,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn with_operator(
|
||||
|
|
Loading…
Reference in a new issue