forked from extern/nushell
Math Documentation (#1982)
* Adding math docs * Add some comments to calculate * Remove redudant message Message already shows up in subcommands list * Added not working example Accidentantly * Remove table
This commit is contained in:
@ -16,11 +16,7 @@ impl WholeStreamCommand for Command {
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
r#"Use mathematical functions (average, min, max) to aggregate list of numbers or tables
|
||||
math average
|
||||
math min
|
||||
math max
|
||||
"#
|
||||
"Use mathematical functions as aggregate functions on a list of numbers or tables"
|
||||
}
|
||||
|
||||
async fn run(
|
||||
@ -97,6 +93,17 @@ mod tests {
|
||||
expected_err: None,
|
||||
expected_res: vec![Ok(decimal(-5)), Ok(decimal(-13.5)), Ok(int(10))],
|
||||
},
|
||||
// TODO-Uncomment once I figure out how to structure tables
|
||||
// TestCase {
|
||||
// description: "Tables",
|
||||
// values: vec![
|
||||
// table(&vec![int(3), int(4), int(4)]),
|
||||
// table(&vec![int(3), int(4), int(4)]),
|
||||
// table(&vec![int(3), int(4), int(4)]),
|
||||
// ],
|
||||
// expected_err: None,
|
||||
// expected_res: vec![Ok(decimal(-5)), Ok(decimal(-13.5)), Ok(int(10))],
|
||||
// },
|
||||
// TODO-Uncomment once Issue: https://github.com/nushell/nushell/issues/1883 is resolved
|
||||
// TestCase {
|
||||
// description: "Invalid Mixed Values",
|
||||
|
@ -20,6 +20,8 @@ pub async fn calculate(
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
} else {
|
||||
// If we are not dealing with Primitives, then perhaps we are dealing with a table
|
||||
// Create a key for each column name
|
||||
let mut column_values = IndexMap::new();
|
||||
for value in values {
|
||||
if let UntaggedValue::Row(row_dict) = value.value {
|
||||
@ -31,7 +33,7 @@ pub async fn calculate(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The mathematical function operates over the columns of the table
|
||||
let mut column_totals = IndexMap::new();
|
||||
for (col_name, col_vals) in column_values {
|
||||
match mf(&col_vals, &name) {
|
||||
|
Reference in New Issue
Block a user