forked from extern/nushell
Allow tables and records as input to math commands (#11496)
# Description The math functions `avg`, `max`, `median`, `min`, `product`, `stddev`, `sum` and `variance` all takes a list as input and return a number. <https://github.com/nushell/nushell/blob/main/crates/nu-command/src/math/utils.rs> contains code that makes these functions work for tables (by running the function on each column), but this functionality has not been accessible because the input types are too strict. This PR remedies this. The functions should also work on records, since a record is basically a one-row table. Most of these functions also make sense for durations and file sizes, except `product` of course. There's an implementation issue with `stddev` and `variance` for durations and file sizes, but they could in principle support it. # User-Facing Changes This PR only adds supported types, and doesn't remove any, so there should be no breaking changes.
This commit is contained in:
@ -17,8 +17,13 @@ impl Command for SubCommand {
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("math min")
|
||||
.input_output_types(vec![
|
||||
(Type::List(Box::new(Type::Number)), Type::Number),
|
||||
(Type::List(Box::new(Type::Duration)), Type::Duration),
|
||||
(Type::List(Box::new(Type::Filesize)), Type::Filesize),
|
||||
(Type::List(Box::new(Type::Any)), Type::Any),
|
||||
(Type::Range, Type::Number),
|
||||
(Type::Table(vec![]), Type::Record(vec![])),
|
||||
(Type::Record(vec![]), Type::Record(vec![])),
|
||||
])
|
||||
.allow_variants_without_examples(true)
|
||||
.category(Category::Math)
|
||||
|
Reference in New Issue
Block a user