From 5d94b16d71c2e8bf8a98312ae92a7a78f5236804 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Sun, 13 Aug 2023 20:29:17 +0200 Subject: [PATCH] Improve I/O types of `into decimal`(/float) (#9998) # Description - Add identity cast to `into decimal` (float->float) - Correct `into decimal` output to concrete float # User-Facing Changes `1.23 | into decimal` will now work. By fixing the output type it can now be used in conjunction with commands that expect `float`/`list` # Tests + Formatting Adapts example to do identity cast and heterogeneous cast --- .../src/conversions/into/decimal.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/conversions/into/decimal.rs b/crates/nu-command/src/conversions/into/decimal.rs index 73176c4fb..77aabaa47 100644 --- a/crates/nu-command/src/conversions/into/decimal.rs +++ b/crates/nu-command/src/conversions/into/decimal.rs @@ -17,14 +17,15 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("into decimal") .input_output_types(vec![ - (Type::Int, Type::Number), - (Type::String, Type::Number), - (Type::Bool, Type::Number), + (Type::Int, Type::Float), + (Type::String, Type::Float), + (Type::Bool, Type::Float), + (Type::Float, Type::Float), (Type::Table(vec![]), Type::Table(vec![])), (Type::Record(vec![]), Type::Record(vec![])), ( Type::List(Box::new(Type::Any)), - Type::List(Box::new(Type::Number)), + Type::List(Box::new(Type::Float)), ), ]) .rest( @@ -76,9 +77,12 @@ impl Command for SubCommand { result: Some(Value::test_float(1.345)), }, Example { - description: "Convert decimal to decimal", - example: "'-5.9' | into decimal", - result: Some(Value::test_float(-5.9)), + description: "Coerce list of ints and floats to float", + example: "[4 -5.9] | into decimal", + result: Some(Value::test_list(vec![ + Value::test_float(4.0), + Value::test_float(-5.9), + ])), }, Example { description: "Convert boolean to decimal", @@ -91,6 +95,7 @@ impl Command for SubCommand { fn action(input: &Value, _args: &CellPathOnlyArgs, head: Span) -> Value { match input { + Value::Float { .. } => input.clone(), Value::String { val: s, span } => { let other = s.trim();