Fix "math sum doesn't support streams" (#301)

* MathEval Variance and Stddev

* Fix tests and linting

* Typo

* Deal with streams when they are not tables
This commit is contained in:
Luccas Mateus 2021-11-06 22:20:58 -03:00 committed by GitHub
parent 573cb38bab
commit 7e070e2e5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,7 @@ pub fn run_with_function(
} }
fn helper_for_tables( fn helper_for_tables(
values: PipelineData, values: &[Value],
name: Span, name: Span,
mf: impl Fn(&[Value], &Span) -> Result<Value, ShellError>, mf: impl Fn(&[Value], &Span) -> Result<Value, ShellError>,
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
@ -31,6 +31,9 @@ fn helper_for_tables(
.and_modify(|v: &mut Vec<Value>| v.push(value.clone())) .and_modify(|v: &mut Vec<Value>| v.push(value.clone()))
.or_insert_with(|| vec![value.clone()]); .or_insert_with(|| vec![value.clone()]);
} }
} else {
//Turns out we are not dealing with a table
return mf(values, &name);
} }
} }
// The mathematical function operates over the columns of the table // The mathematical function operates over the columns of the table
@ -67,9 +70,9 @@ pub fn calculate(
mf: impl Fn(&[Value], &Span) -> Result<Value, ShellError>, mf: impl Fn(&[Value], &Span) -> Result<Value, ShellError>,
) -> Result<Value, ShellError> { ) -> Result<Value, ShellError> {
match values { match values {
PipelineData::Stream(_) => helper_for_tables(values, name, mf), PipelineData::Stream(s) => helper_for_tables(&s.collect::<Vec<Value>>(), name, mf),
PipelineData::Value(Value::List { ref vals, .. }) => match &vals[..] { PipelineData::Value(Value::List { ref vals, .. }) => match &vals[..] {
[Value::Record { .. }, _end @ ..] => helper_for_tables(values, name, mf), [Value::Record { .. }, _end @ ..] => helper_for_tables(vals, name, mf),
_ => mf(vals, &name), _ => mf(vals, &name),
}, },
PipelineData::Value(Value::Record { vals, cols, span }) => { PipelineData::Value(Value::Record { vals, cols, span }) => {