mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 15:13:01 +01:00
Remove Span::unknown (#525)
This commit is contained in:
parent
b54e9b6bfd
commit
2883d6cd1e
@ -47,7 +47,7 @@ impl Command for SubCommand {
|
|||||||
.to_string()
|
.to_string()
|
||||||
.as_bytes()
|
.as_bytes()
|
||||||
.to_vec(),
|
.to_vec(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -55,7 +55,7 @@ impl Command for SubCommand {
|
|||||||
example: "1 | into binary",
|
example: "1 | into binary",
|
||||||
result: Some(Value::Binary {
|
result: Some(Value::Binary {
|
||||||
val: i64::from(1).to_le_bytes().to_vec(),
|
val: i64::from(1).to_le_bytes().to_vec(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -63,7 +63,7 @@ impl Command for SubCommand {
|
|||||||
example: "$true | into binary",
|
example: "$true | into binary",
|
||||||
result: Some(Value::Binary {
|
result: Some(Value::Binary {
|
||||||
val: i64::from(1).to_le_bytes().to_vec(),
|
val: i64::from(1).to_le_bytes().to_vec(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -81,7 +81,7 @@ impl Command for SubCommand {
|
|||||||
example: "1.234 | into binary",
|
example: "1.234 | into binary",
|
||||||
result: Some(Value::Binary {
|
result: Some(Value::Binary {
|
||||||
val: 1.234f64.to_le_bytes().to_vec(),
|
val: 1.234f64.to_le_bytes().to_vec(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -316,11 +316,11 @@ mod tests {
|
|||||||
fn takes_a_date_format() {
|
fn takes_a_date_format() {
|
||||||
let date_str = Value::test_string("16.11.1984 8:00 am +0000");
|
let date_str = Value::test_string("16.11.1984 8:00 am +0000");
|
||||||
let fmt_options = Some(DatetimeFormat("%d.%m.%Y %H:%M %P %z".to_string()));
|
let fmt_options = Some(DatetimeFormat("%d.%m.%Y %H:%M %P %z".to_string()));
|
||||||
let actual = action(&date_str, &None, &fmt_options, Span::unknown());
|
let actual = action(&date_str, &None, &fmt_options, Span::test_data());
|
||||||
let expected = Value::Date {
|
let expected = Value::Date {
|
||||||
val: DateTime::parse_from_str("16.11.1984 8:00 am +0000", "%d.%m.%Y %H:%M %P %z")
|
val: DateTime::parse_from_str("16.11.1984 8:00 am +0000", "%d.%m.%Y %H:%M %P %z")
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
assert_eq!(actual, expected)
|
assert_eq!(actual, expected)
|
||||||
}
|
}
|
||||||
@ -328,11 +328,11 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn takes_iso8601_date_format() {
|
fn takes_iso8601_date_format() {
|
||||||
let date_str = Value::test_string("2020-08-04T16:39:18+00:00");
|
let date_str = Value::test_string("2020-08-04T16:39:18+00:00");
|
||||||
let actual = action(&date_str, &None, &None, Span::unknown());
|
let actual = action(&date_str, &None, &None, Span::test_data());
|
||||||
let expected = Value::Date {
|
let expected = Value::Date {
|
||||||
val: DateTime::parse_from_str("2020-08-04T16:39:18+00:00", "%Y-%m-%dT%H:%M:%S%z")
|
val: DateTime::parse_from_str("2020-08-04T16:39:18+00:00", "%Y-%m-%dT%H:%M:%S%z")
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
assert_eq!(actual, expected)
|
assert_eq!(actual, expected)
|
||||||
}
|
}
|
||||||
@ -342,13 +342,13 @@ mod tests {
|
|||||||
let date_str = Value::test_string("1614434140");
|
let date_str = Value::test_string("1614434140");
|
||||||
let timezone_option = Some(Spanned {
|
let timezone_option = Some(Spanned {
|
||||||
item: Zone::East(8),
|
item: Zone::East(8),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
});
|
});
|
||||||
let actual = action(&date_str, &timezone_option, &None, Span::unknown());
|
let actual = action(&date_str, &timezone_option, &None, Span::test_data());
|
||||||
let expected = Value::Date {
|
let expected = Value::Date {
|
||||||
val: DateTime::parse_from_str("2021-02-27 21:55:40 +08:00", "%Y-%m-%d %H:%M:%S %z")
|
val: DateTime::parse_from_str("2021-02-27 21:55:40 +08:00", "%Y-%m-%d %H:%M:%S %z")
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(actual, expected)
|
assert_eq!(actual, expected)
|
||||||
@ -359,12 +359,12 @@ mod tests {
|
|||||||
let date_str = Value::test_string("1614434140");
|
let date_str = Value::test_string("1614434140");
|
||||||
let timezone_option = Some(Spanned {
|
let timezone_option = Some(Spanned {
|
||||||
item: Zone::Local,
|
item: Zone::Local,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
});
|
});
|
||||||
let actual = action(&date_str, &timezone_option, &None, Span::unknown());
|
let actual = action(&date_str, &timezone_option, &None, Span::test_data());
|
||||||
let expected = Value::Date {
|
let expected = Value::Date {
|
||||||
val: Local.timestamp(1614434140, 0).into(),
|
val: Local.timestamp(1614434140, 0).into(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(actual, expected)
|
assert_eq!(actual, expected)
|
||||||
@ -375,9 +375,9 @@ mod tests {
|
|||||||
let date_str = Value::test_string("10440970000000");
|
let date_str = Value::test_string("10440970000000");
|
||||||
let timezone_option = Some(Spanned {
|
let timezone_option = Some(Spanned {
|
||||||
item: Zone::Utc,
|
item: Zone::Utc,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
});
|
});
|
||||||
let actual = action(&date_str, &timezone_option, &None, Span::unknown());
|
let actual = action(&date_str, &timezone_option, &None, Span::test_data());
|
||||||
|
|
||||||
assert_eq!(actual.get_type(), Error);
|
assert_eq!(actual.get_type(), Error);
|
||||||
}
|
}
|
||||||
@ -386,7 +386,7 @@ mod tests {
|
|||||||
fn communicates_parsing_error_given_an_invalid_datetimelike_string() {
|
fn communicates_parsing_error_given_an_invalid_datetimelike_string() {
|
||||||
let date_str = Value::test_string("16.11.1984 8:00 am Oops0000");
|
let date_str = Value::test_string("16.11.1984 8:00 am Oops0000");
|
||||||
let fmt_options = Some(DatetimeFormat("%d.%m.%Y %H:%M %P %z".to_string()));
|
let fmt_options = Some(DatetimeFormat("%d.%m.%Y %H:%M %P %z".to_string()));
|
||||||
let actual = action(&date_str, &None, &fmt_options, Span::unknown());
|
let actual = action(&date_str, &None, &fmt_options, Span::test_data());
|
||||||
|
|
||||||
assert_eq!(actual.get_type(), Error);
|
assert_eq!(actual.get_type(), Error);
|
||||||
}
|
}
|
||||||
|
@ -44,9 +44,9 @@ impl Command for SubCommand {
|
|||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["num".to_string()],
|
cols: vec!["num".to_string()],
|
||||||
vals: vec![Value::test_float(5.01)],
|
vals: vec![Value::test_float(5.01)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -142,7 +142,7 @@ mod tests {
|
|||||||
let word = Value::test_string("3.1415");
|
let word = Value::test_string("3.1415");
|
||||||
let expected = Value::test_float(3.1415);
|
let expected = Value::test_float(3.1415);
|
||||||
|
|
||||||
let actual = action(&word, Span::unknown());
|
let actual = action(&word, Span::test_data());
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ mod tests {
|
|||||||
fn communicates_parsing_error_given_an_invalid_decimallike_string() {
|
fn communicates_parsing_error_given_an_invalid_decimallike_string() {
|
||||||
let decimal_str = Value::test_string("11.6anra");
|
let decimal_str = Value::test_string("11.6anra");
|
||||||
|
|
||||||
let actual = action(&decimal_str, Span::unknown());
|
let actual = action(&decimal_str, Span::test_data());
|
||||||
|
|
||||||
assert_eq!(actual.get_type(), Error);
|
assert_eq!(actual.get_type(), Error);
|
||||||
}
|
}
|
||||||
@ -159,7 +159,7 @@ mod tests {
|
|||||||
fn int_to_decimal() {
|
fn int_to_decimal() {
|
||||||
let decimal_str = Value::test_int(10);
|
let decimal_str = Value::test_int(10);
|
||||||
let expected = Value::test_float(10.0);
|
let expected = Value::test_float(10.0);
|
||||||
let actual = action(&decimal_str, Span::unknown());
|
let actual = action(&decimal_str, Span::test_data());
|
||||||
|
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ impl Command for SubCommand {
|
|||||||
example: "'2' | into filesize",
|
example: "'2' | into filesize",
|
||||||
result: Some(Value::Filesize {
|
result: Some(Value::Filesize {
|
||||||
val: 2,
|
val: 2,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -57,7 +57,7 @@ impl Command for SubCommand {
|
|||||||
example: "8.3 | into filesize",
|
example: "8.3 | into filesize",
|
||||||
result: Some(Value::Filesize {
|
result: Some(Value::Filesize {
|
||||||
val: 8,
|
val: 8,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -65,7 +65,7 @@ impl Command for SubCommand {
|
|||||||
example: "5 | into filesize",
|
example: "5 | into filesize",
|
||||||
result: Some(Value::Filesize {
|
result: Some(Value::Filesize {
|
||||||
val: 5,
|
val: 5,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -73,7 +73,7 @@ impl Command for SubCommand {
|
|||||||
example: "4KB | into filesize",
|
example: "4KB | into filesize",
|
||||||
result: Some(Value::Filesize {
|
result: Some(Value::Filesize {
|
||||||
val: 4000,
|
val: 4000,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -70,7 +70,7 @@ impl Command for SubCommand {
|
|||||||
example: "4KB | into int",
|
example: "4KB | into int",
|
||||||
result: Some(Value::Int {
|
result: Some(Value::Int {
|
||||||
val: 4000,
|
val: 4000,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -78,7 +78,7 @@ impl Command for SubCommand {
|
|||||||
example: "[$false, $true] | into int",
|
example: "[$false, $true] | into int",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(0), Value::test_int(1)],
|
vals: vec![Value::test_int(0), Value::test_int(1)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -273,21 +273,21 @@ mod test {
|
|||||||
let word = Value::test_string("10");
|
let word = Value::test_string("10");
|
||||||
let expected = Value::test_int(10);
|
let expected = Value::test_int(10);
|
||||||
|
|
||||||
let actual = action(&word, Span::unknown(), 10);
|
let actual = action(&word, Span::test_data(), 10);
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn turns_binary_to_integer() {
|
fn turns_binary_to_integer() {
|
||||||
let s = Value::test_string("0b101");
|
let s = Value::test_string("0b101");
|
||||||
let actual = action(&s, Span::unknown(), 10);
|
let actual = action(&s, Span::test_data(), 10);
|
||||||
assert_eq!(actual, Value::test_int(5));
|
assert_eq!(actual, Value::test_int(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn turns_hex_to_integer() {
|
fn turns_hex_to_integer() {
|
||||||
let s = Value::test_string("0xFF");
|
let s = Value::test_string("0xFF");
|
||||||
let actual = action(&s, Span::unknown(), 16);
|
let actual = action(&s, Span::test_data(), 16);
|
||||||
assert_eq!(actual, Value::test_int(255));
|
assert_eq!(actual, Value::test_int(255));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -295,7 +295,7 @@ mod test {
|
|||||||
fn communicates_parsing_error_given_an_invalid_integerlike_string() {
|
fn communicates_parsing_error_given_an_invalid_integerlike_string() {
|
||||||
let integer_str = Value::test_string("36anra");
|
let integer_str = Value::test_string("36anra");
|
||||||
|
|
||||||
let actual = action(&integer_str, Span::unknown(), 10);
|
let actual = action(&integer_str, Span::test_data(), 10);
|
||||||
|
|
||||||
assert_eq!(actual.get_type(), Error)
|
assert_eq!(actual.get_type(), Error)
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ impl Command for SubCommand {
|
|||||||
example: "1.7 | into string -d 0",
|
example: "1.7 | into string -d 0",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "2".to_string(),
|
val: "2".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -61,7 +61,7 @@ impl Command for SubCommand {
|
|||||||
example: "1.7 | into string -d 1",
|
example: "1.7 | into string -d 1",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "1.7".to_string(),
|
val: "1.7".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -69,7 +69,7 @@ impl Command for SubCommand {
|
|||||||
example: "1.734 | into string -d 2",
|
example: "1.734 | into string -d 2",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "1.73".to_string(),
|
val: "1.73".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -80,7 +80,7 @@ impl Command for SubCommand {
|
|||||||
// result: Some(Value::Error {
|
// result: Some(Value::Error {
|
||||||
// error: ShellError::UnsupportedInput(
|
// error: ShellError::UnsupportedInput(
|
||||||
// String::from("Cannot accept negative integers for decimals arguments"),
|
// String::from("Cannot accept negative integers for decimals arguments"),
|
||||||
// Span::unknown(),
|
// Span::test_data(),
|
||||||
// ),
|
// ),
|
||||||
// }),
|
// }),
|
||||||
},
|
},
|
||||||
@ -89,7 +89,7 @@ impl Command for SubCommand {
|
|||||||
example: "4.3 | into string",
|
example: "4.3 | into string",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "4.3".to_string(),
|
val: "4.3".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -97,7 +97,7 @@ impl Command for SubCommand {
|
|||||||
example: "'1234' | into string",
|
example: "'1234' | into string",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "1234".to_string(),
|
val: "1234".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -105,7 +105,7 @@ impl Command for SubCommand {
|
|||||||
example: "$true | into string",
|
example: "$true | into string",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "true".to_string(),
|
val: "true".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
|
@ -99,7 +99,7 @@ impl Command for For {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let span = Span::unknown();
|
let span = Span::test_data();
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Echo the square of each integer",
|
description: "Echo the square of each integer",
|
||||||
@ -110,7 +110,7 @@ impl Command for For {
|
|||||||
Value::Int { val: 4, span },
|
Value::Int { val: 4, span },
|
||||||
Value::Int { val: 9, span },
|
Value::Int { val: 9, span },
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -122,7 +122,7 @@ impl Command for For {
|
|||||||
Value::Int { val: 2, span },
|
Value::Int { val: 2, span },
|
||||||
Value::Int { val: 3, span },
|
Value::Int { val: 3, span },
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
// FIXME? Numbered `for` is kinda strange, but was supported in previous nushell
|
// FIXME? Numbered `for` is kinda strange, but was supported in previous nushell
|
||||||
@ -140,7 +140,7 @@ impl Command for For {
|
|||||||
// span,
|
// span,
|
||||||
// },
|
// },
|
||||||
// ],
|
// ],
|
||||||
// span: Span::unknown(),
|
// span,
|
||||||
// }),
|
// }),
|
||||||
// },
|
// },
|
||||||
]
|
]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
use nu_protocol::ast::{Call, Expr, Expression, ImportPatternMember};
|
use nu_protocol::ast::{Call, Expr, Expression, ImportPatternMember};
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{Category, PipelineData, ShellError, Signature, Span, SyntaxShape};
|
use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Use;
|
pub struct Use;
|
||||||
@ -89,7 +89,7 @@ impl Command for Use {
|
|||||||
// TODO: Add string conversions (e.g. int to string)
|
// TODO: Add string conversions (e.g. int to string)
|
||||||
// TODO: Later expand env to take all Values
|
// TODO: Later expand env to take all Values
|
||||||
let val = eval_block(engine_state, stack, block, PipelineData::new(call.head))?
|
let val = eval_block(engine_state, stack, block, PipelineData::new(call.head))?
|
||||||
.into_value(Span::unknown());
|
.into_value(call.head);
|
||||||
|
|
||||||
stack.add_env_var(name, val);
|
stack.add_env_var(name, val);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{Example, IntoPipelineData, PipelineData, ShellError, Signature, Span, Value};
|
use nu_protocol::{Example, IntoPipelineData, PipelineData, ShellError, Signature, Value};
|
||||||
|
|
||||||
pub mod shadow {
|
pub mod shadow {
|
||||||
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
|
include!(concat!(env!("OUT_DIR"), "/shadow.rs"));
|
||||||
@ -66,7 +66,7 @@ pub fn version(
|
|||||||
"branch".to_string(),
|
"branch".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: branch.to_string(),
|
val: branch.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ pub fn version(
|
|||||||
"short_commit".to_string(),
|
"short_commit".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: short_commit.to_string(),
|
val: short_commit.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ pub fn version(
|
|||||||
"commit_hash".to_string(),
|
"commit_hash".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: commit_hash.to_string(),
|
val: commit_hash.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ pub fn version(
|
|||||||
"commit_date".to_string(),
|
"commit_date".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: commit_date.to_string(),
|
val: commit_date.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ pub fn version(
|
|||||||
"build_os".to_string(),
|
"build_os".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: build_os.to_string(),
|
val: build_os.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -119,7 +119,7 @@ pub fn version(
|
|||||||
"rust_version".to_string(),
|
"rust_version".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: rust_version.to_string(),
|
val: rust_version.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ pub fn version(
|
|||||||
"rust_channel".to_string(),
|
"rust_channel".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: rust_channel.to_string(),
|
val: rust_channel.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ pub fn version(
|
|||||||
"cargo_version".to_string(),
|
"cargo_version".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: cargo_version.to_string(),
|
val: cargo_version.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ pub fn version(
|
|||||||
"pkg_version".to_string(),
|
"pkg_version".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: pkg_version.to_string(),
|
val: pkg_version.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ pub fn version(
|
|||||||
"build_time".to_string(),
|
"build_time".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: build_time.to_string(),
|
val: build_time.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ pub fn version(
|
|||||||
"build_rust_channel".to_string(),
|
"build_rust_channel".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: build_rust_channel.to_string(),
|
val: build_rust_channel.to_string(),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -184,7 +184,7 @@ pub fn version(
|
|||||||
"features".to_string(),
|
"features".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: features_enabled().join(", "),
|
val: features_enabled().join(", "),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ pub fn version(
|
|||||||
"installed_plugins".to_string(),
|
"installed_plugins".to_string(),
|
||||||
Value::String {
|
Value::String {
|
||||||
val: installed_plugins.join(", "),
|
val: installed_plugins.join(", "),
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -211,9 +211,9 @@ pub fn version(
|
|||||||
// vals: vec![Value::Record {
|
// vals: vec![Value::Record {
|
||||||
// cols,
|
// cols,
|
||||||
// vals,
|
// vals,
|
||||||
// span: Span::unknown(),
|
// span: call.head,
|
||||||
// }],
|
// }],
|
||||||
// span: Span::unknown(),
|
// span: call.head,
|
||||||
// }
|
// }
|
||||||
// .into_pipeline_data())
|
// .into_pipeline_data())
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ pub fn version(
|
|||||||
Ok(Value::Record {
|
Ok(Value::Record {
|
||||||
cols,
|
cols,
|
||||||
vals,
|
vals,
|
||||||
span: Span::unknown(),
|
span: call.head,
|
||||||
}
|
}
|
||||||
.into_pipeline_data())
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,25 @@ impl Command for AppendDF {
|
|||||||
$a | dfr append $a"#,
|
$a | dfr append $a"#,
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new("a".to_string(), vec![1.into(), 3.into()]),
|
Column::new(
|
||||||
Column::new("b".to_string(), vec![2.into(), 4.into()]),
|
"a".to_string(),
|
||||||
Column::new("a_x".to_string(), vec![1.into(), 3.into()]),
|
vec![Value::test_int(1), Value::test_int(3)],
|
||||||
Column::new("b_x".to_string(), vec![2.into(), 4.into()]),
|
),
|
||||||
|
Column::new(
|
||||||
|
"b".to_string(),
|
||||||
|
vec![Value::test_int(2), Value::test_int(4)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"a_x".to_string(),
|
||||||
|
vec![Value::test_int(1), Value::test_int(3)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"b_x".to_string(),
|
||||||
|
vec![Value::test_int(2), Value::test_int(4)],
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -51,15 +63,25 @@ impl Command for AppendDF {
|
|||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new(
|
Column::new(
|
||||||
"a".to_string(),
|
"a".to_string(),
|
||||||
vec![1.into(), 3.into(), 1.into(), 3.into()],
|
vec![
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(3),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(3),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Column::new(
|
Column::new(
|
||||||
"b".to_string(),
|
"b".to_string(),
|
||||||
vec![2.into(), 4.into(), 2.into(), 4.into()],
|
vec![
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(4),
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(4),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -2,7 +2,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::values::{Column, NuDataFrame};
|
use super::values::{Column, NuDataFrame};
|
||||||
@ -32,10 +32,10 @@ impl Command for ColumnDF {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"a".to_string(),
|
"a".to_string(),
|
||||||
vec![1.into(), 3.into()],
|
vec![Value::test_int(1), Value::test_int(3)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::{
|
use polars::{
|
||||||
chunked_array::ChunkedArray,
|
chunked_array::ChunkedArray,
|
||||||
@ -37,51 +37,51 @@ impl Command for DescribeDF {
|
|||||||
Column::new(
|
Column::new(
|
||||||
"descriptor".to_string(),
|
"descriptor".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"count".to_string().into(),
|
Value::test_string("count"),
|
||||||
"sum".to_string().into(),
|
Value::test_string("sum"),
|
||||||
"mean".to_string().into(),
|
Value::test_string("mean"),
|
||||||
"median".to_string().into(),
|
Value::test_string("median"),
|
||||||
"std".to_string().into(),
|
Value::test_string("std"),
|
||||||
"min".to_string().into(),
|
Value::test_string("min"),
|
||||||
"25%".to_string().into(),
|
Value::test_string("25%"),
|
||||||
"50%".to_string().into(),
|
Value::test_string("50%"),
|
||||||
"75%".to_string().into(),
|
Value::test_string("75%"),
|
||||||
"max".to_string().into(),
|
Value::test_string("max"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Column::new(
|
Column::new(
|
||||||
"a (i64)".to_string(),
|
"a (i64)".to_string(),
|
||||||
vec![
|
vec![
|
||||||
2.0.into(),
|
Value::test_float(2.0),
|
||||||
2.0.into(),
|
Value::test_float(2.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
0.0.into(),
|
Value::test_float(0.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Column::new(
|
Column::new(
|
||||||
"b (i64)".to_string(),
|
"b (i64)".to_string(),
|
||||||
vec![
|
vec![
|
||||||
2.0.into(),
|
Value::test_float(2.0),
|
||||||
2.0.into(),
|
Value::test_float(2.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
0.0.into(),
|
Value::test_float(0.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
1.0.into(),
|
Value::test_float(1.0),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,10 @@ impl Command for DropDF {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"b".to_string(),
|
"b".to_string(),
|
||||||
vec![2.into(), 4.into()],
|
vec![Value::test_int(2), Value::test_int(4)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,21 @@ impl Command for DropNulls {
|
|||||||
$a | dfr drop-nulls"#,
|
$a | dfr drop-nulls"#,
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new("a".to_string(), vec![1.into(), 1.into()]),
|
Column::new(
|
||||||
Column::new("b".to_string(), vec![2.into(), 2.into()]),
|
"a".to_string(),
|
||||||
Column::new("res".to_string(), vec![1.into(), 1.into()]),
|
vec![Value::test_int(1), Value::test_int(1)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"b".to_string(),
|
||||||
|
vec![Value::test_int(2), Value::test_int(2)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"res".to_string(),
|
||||||
|
vec![Value::test_int(1), Value::test_int(1)],
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -55,10 +64,15 @@ impl Command for DropNulls {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"div_0_0".to_string(),
|
"div_0_0".to_string(),
|
||||||
vec![1.into(), 1.into(), 1.into(), 1.into()],
|
vec![
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(1),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -94,7 +108,7 @@ fn command(
|
|||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
(Some(agg_string), col_span)
|
(Some(agg_string), col_span)
|
||||||
}
|
}
|
||||||
None => (None, Span::unknown()),
|
None => (None, call.head),
|
||||||
};
|
};
|
||||||
|
|
||||||
let subset_slice = subset.as_ref().map(|cols| &cols[..]);
|
let subset_slice = subset.as_ref().map(|cols| &cols[..]);
|
||||||
|
@ -29,15 +29,15 @@ impl Command for DataTypes {
|
|||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new(
|
Column::new(
|
||||||
"column".to_string(),
|
"column".to_string(),
|
||||||
vec!["a".to_string().into(), "b".to_string().into()],
|
vec![Value::test_string("a"), Value::test_string("b")],
|
||||||
),
|
),
|
||||||
Column::new(
|
Column::new(
|
||||||
"dtype".to_string(),
|
"dtype".to_string(),
|
||||||
vec!["i64".to_string().into(), "i64".to_string().into()],
|
vec![Value::test_string("i64"), Value::test_string("i64")],
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,10 @@ impl Command for AllFalse {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"all_false".to_string(),
|
"all_false".to_string(),
|
||||||
vec![true.into()],
|
vec![Value::test_bool(true)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -44,10 +44,10 @@ impl Command for AllFalse {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"all_false".to_string(),
|
"all_false".to_string(),
|
||||||
vec![false.into()],
|
vec![Value::test_bool(false)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -30,10 +30,10 @@ impl Command for AllTrue {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"all_true".to_string(),
|
"all_true".to_string(),
|
||||||
vec![true.into()],
|
vec![Value::test_bool(true)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -44,10 +44,10 @@ impl Command for AllTrue {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"all_true".to_string(),
|
"all_true".to_string(),
|
||||||
vec![false.into()],
|
vec![Value::test_bool(false)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
|
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ impl Command for ArgMax {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"arg_max".to_string(),
|
"arg_max".to_string(),
|
||||||
vec![1.into()],
|
vec![Value::test_int(1)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
|
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ impl Command for ArgMin {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"arg_min".to_string(),
|
"arg_min".to_string(),
|
||||||
vec![0.into()],
|
vec![Value::test_int(0)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::{DataType, IntoSeries};
|
use polars::prelude::{DataType, IntoSeries};
|
||||||
|
|
||||||
@ -64,10 +64,16 @@ impl Command for Cumulative {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0_cum_sum".to_string(),
|
"0_cum_sum".to_string(),
|
||||||
vec![1.into(), 3.into(), 6.into(), 10.into(), 15.into()],
|
vec![
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(3),
|
||||||
|
Value::test_int(6),
|
||||||
|
Value::test_int(10),
|
||||||
|
Value::test_int(15),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetDay {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![4.into(), 4.into()],
|
vec![Value::test_int(4), Value::test_int(4)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetHour {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![16.into(), 16.into()],
|
vec![Value::test_int(16), Value::test_int(16)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetMinute {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![39.into(), 39.into()],
|
vec![Value::test_int(39), Value::test_int(39)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetMonth {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![8.into(), 8.into()],
|
vec![Value::test_int(8), Value::test_int(8)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetNanosecond {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![0.into(), 0.into()],
|
vec![Value::test_int(0), Value::test_int(0)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetOrdinal {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![217.into(), 217.into()],
|
vec![Value::test_int(217), Value::test_int(217)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetSecond {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![18.into(), 18.into()],
|
vec![Value::test_int(18), Value::test_int(18)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetWeek {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![32.into(), 32.into()],
|
vec![Value::test_int(32), Value::test_int(32)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetWeekDay {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![1.into(), 1.into()],
|
vec![Value::test_int(1), Value::test_int(1)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,10 @@ impl Command for GetYear {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![2020.into(), 2020.into()],
|
vec![Value::test_int(2020), Value::test_int(2020)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -33,10 +33,16 @@ impl Command for ArgSort {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"arg_sort".to_string(),
|
"arg_sort".to_string(),
|
||||||
vec![0.into(), 1.into(), 2.into(), 3.into(), 4.into()],
|
vec![
|
||||||
|
Value::test_int(0),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(3),
|
||||||
|
Value::test_int(4),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -45,10 +51,16 @@ impl Command for ArgSort {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"arg_sort".to_string(),
|
"arg_sort".to_string(),
|
||||||
vec![3.into(), 4.into(), 1.into(), 2.into(), 0.into()],
|
vec![
|
||||||
|
Value::test_int(3),
|
||||||
|
Value::test_int(4),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(0),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ impl Command for ArgTrue {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"arg_true".to_string(),
|
"arg_true".to_string(),
|
||||||
vec![1.into()],
|
vec![Value::test_int(1)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ impl Command for ArgUnique {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"arg_unique".to_string(),
|
"arg_unique".to_string(),
|
||||||
vec![0.into(), 1.into(), 3.into()],
|
vec![Value::test_int(0), Value::test_int(1), Value::test_int(3)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,17 @@ impl Command for SetWithIndex {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![6.into(), 1.into(), 6.into(), 2.into(), 4.into(), 3.into()],
|
vec![
|
||||||
|
Value::test_int(6),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(6),
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(4),
|
||||||
|
Value::test_int(3),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -31,17 +31,17 @@ impl Command for IsDuplicated {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"is_duplicated".to_string(),
|
"is_duplicated".to_string(),
|
||||||
vec![
|
vec![
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -35,17 +35,17 @@ impl Command for IsIn {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"is_in".to_string(),
|
"is_in".to_string(),
|
||||||
vec![
|
vec![
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,15 @@ impl Command for IsNotNull {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"is_not_null".to_string(),
|
"is_not_null".to_string(),
|
||||||
vec![true.into(), true.into(), false.into(), true.into()],
|
vec![
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(false),
|
||||||
|
Value::test_bool(true),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,15 @@ impl Command for IsNull {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"is_null".to_string(),
|
"is_null".to_string(),
|
||||||
vec![false.into(), false.into(), true.into(), false.into()],
|
vec![
|
||||||
|
Value::test_bool(false),
|
||||||
|
Value::test_bool(false),
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(false),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -31,17 +31,17 @@ impl Command for IsUnique {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"is_unique".to_string(),
|
"is_unique".to_string(),
|
||||||
vec![
|
vec![
|
||||||
true.into(),
|
Value::test_bool(true),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
false.into(),
|
Value::test_bool(false),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -32,10 +32,14 @@ impl Command for NotSeries {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![false.into(), true.into(), false.into()],
|
vec![
|
||||||
|
Value::test_bool(false),
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(false),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,16 @@ impl Command for SetSeries {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![0.into(), 0.into(), 1.into(), 2.into(), 2.into()],
|
vec![
|
||||||
|
Value::test_int(0),
|
||||||
|
Value::test_int(0),
|
||||||
|
Value::test_int(1),
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(2),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,10 @@ impl Command for NNull {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"count_null".to_string(),
|
"count_null".to_string(),
|
||||||
vec![2.into()],
|
vec![Value::test_int(2)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -29,10 +29,10 @@ impl Command for NUnique {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"count_unique".to_string(),
|
"count_unique".to_string(),
|
||||||
vec![4.into()],
|
vec![Value::test_int(4)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -32,10 +32,15 @@ impl Command for Rename {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"new_name".to_string(),
|
"new_name".to_string(),
|
||||||
vec![5.into(), 6.into(), 7.into(), 8.into()],
|
vec![
|
||||||
|
Value::test_int(5),
|
||||||
|
Value::test_int(6),
|
||||||
|
Value::test_int(7),
|
||||||
|
Value::test_int(8),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::{DataType, IntoSeries, RollingOptions};
|
use polars::prelude::{DataType, IntoSeries, RollingOptions};
|
||||||
|
|
||||||
@ -68,10 +68,15 @@ impl Command for Rolling {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0_rolling_sum".to_string(),
|
"0_rolling_sum".to_string(),
|
||||||
vec![3.into(), 5.into(), 7.into(), 9.into()],
|
vec![
|
||||||
|
Value::test_int(3),
|
||||||
|
Value::test_int(5),
|
||||||
|
Value::test_int(7),
|
||||||
|
Value::test_int(9),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -80,10 +85,15 @@ impl Command for Rolling {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0_rolling_max".to_string(),
|
"0_rolling_max".to_string(),
|
||||||
vec![2.into(), 3.into(), 4.into(), 5.into()],
|
vec![
|
||||||
|
Value::test_int(2),
|
||||||
|
Value::test_int(3),
|
||||||
|
Value::test_int(4),
|
||||||
|
Value::test_int(5),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -32,10 +32,10 @@ impl Command for Shift {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![1.into(), 2.into(), 2.into()],
|
vec![Value::test_int(1), Value::test_int(2), Value::test_int(2)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -39,13 +39,13 @@ impl Command for Concatenate {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"abcza".to_string().into(),
|
Value::test_string("abcza"),
|
||||||
"abcxs".to_string().into(),
|
Value::test_string("abcxs"),
|
||||||
"abccd".to_string().into(),
|
Value::test_string("abccd"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -37,10 +37,14 @@ impl Command for Contains {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![true.into(), false.into(), false.into()],
|
vec![
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(false),
|
||||||
|
Value::test_bool(false),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -45,13 +45,13 @@ impl Command for Replace {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"ABc".to_string().into(),
|
Value::test_string("ABc"),
|
||||||
"ABc".to_string().into(),
|
Value::test_string("ABc"),
|
||||||
"ABc".to_string().into(),
|
Value::test_string("ABc"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -45,13 +45,13 @@ impl Command for ReplaceAll {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"AbAc".to_string().into(),
|
Value::test_string("AbAc"),
|
||||||
"AbAc".to_string().into(),
|
Value::test_string("AbAc"),
|
||||||
"AbAc".to_string().into(),
|
Value::test_string("AbAc"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ impl Command for StrLengths {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![1.into(), 2.into(), 3.into()],
|
vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -35,13 +35,13 @@ impl Command for StrSlice {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"bc".to_string().into(),
|
Value::test_string("bc"),
|
||||||
"bc".to_string().into(),
|
Value::test_string("bc"),
|
||||||
"bc".to_string().into(),
|
Value::test_string("bc"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use nu_engine::CallExt;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape,
|
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -36,12 +36,12 @@ impl Command for StrFTime {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"2020/08/04".to_string().into(),
|
Value::test_string("2020/08/04"),
|
||||||
"2020/08/04".to_string().into(),
|
Value::test_string("2020/08/04"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -31,13 +31,13 @@ impl Command for ToLowerCase {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"abc".to_string().into(),
|
Value::test_string("abc"),
|
||||||
"abc".to_string().into(),
|
Value::test_string("abc"),
|
||||||
"abc".to_string().into(),
|
Value::test_string("abc"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -31,13 +31,13 @@ impl Command for ToUpperCase {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"ABC".to_string().into(),
|
Value::test_string("ABC"),
|
||||||
"ABC".to_string().into(),
|
Value::test_string("ABC"),
|
||||||
"ABC".to_string().into(),
|
Value::test_string("ABC"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
use polars::prelude::IntoSeries;
|
use polars::prelude::IntoSeries;
|
||||||
|
|
||||||
@ -28,9 +28,12 @@ impl Command for Unique {
|
|||||||
description: "Returns unique values from a series",
|
description: "Returns unique values from a series",
|
||||||
example: "[2 2 2 2 2] | dfr to-df | dfr unique",
|
example: "[2 2 2 2 2] | dfr to-df | dfr unique",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new("0".to_string(), vec![2.into()])])
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
|
"0".to_string(),
|
||||||
|
vec![Value::test_int(2)],
|
||||||
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ use super::super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -28,11 +28,17 @@ impl Command for ValueCount {
|
|||||||
example: "[5 5 5 5 6 6] | dfr to-df | dfr value-counts",
|
example: "[5 5 5 5 6 6] | dfr to-df | dfr value-counts",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new("0".to_string(), vec![5.into(), 6.into()]),
|
Column::new(
|
||||||
Column::new("counts".to_string(), vec![4.into(), 2.into()]),
|
"0".to_string(),
|
||||||
|
vec![Value::test_int(5), Value::test_int(6)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"counts".to_string(),
|
||||||
|
vec![Value::test_int(4), Value::test_int(2)],
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ pub fn test_dataframe(cmds: Vec<Box<dyn Command + 'static>>) {
|
|||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec![],
|
cols: vec![],
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -70,11 +70,11 @@ pub fn test_dataframe(cmds: Vec<Box<dyn Command + 'static>>) {
|
|||||||
&engine_state,
|
&engine_state,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
&block,
|
&block,
|
||||||
PipelineData::new(Span::unknown()),
|
PipelineData::new(Span::test_data()),
|
||||||
) {
|
) {
|
||||||
Err(err) => panic!("test eval error in `{}`: {:?}", example.example, err),
|
Err(err) => panic!("test eval error in `{}`: {:?}", example.example, err),
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
let result = result.into_value(Span::unknown());
|
let result = result.into_value(Span::test_data());
|
||||||
println!("input: {}", example.example);
|
println!("input: {}", example.example);
|
||||||
println!("result: {:?}", result);
|
println!("result: {:?}", result);
|
||||||
println!("done: {:?}", start.elapsed());
|
println!("done: {:?}", start.elapsed());
|
||||||
|
@ -3,7 +3,7 @@ use super::values::{Column, NuDataFrame};
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, PipelineData, ShellError, Signature, Span,
|
Category, Example, PipelineData, ShellError, Signature, Span, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -29,11 +29,17 @@ impl Command for ToDataFrame {
|
|||||||
example: "[[a b];[1 2] [3 4]] | dfr to-df",
|
example: "[[a b];[1 2] [3 4]] | dfr to-df",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new("a".to_string(), vec![1.into(), 3.into()]),
|
Column::new(
|
||||||
Column::new("b".to_string(), vec![2.into(), 4.into()]),
|
"a".to_string(),
|
||||||
|
vec![Value::test_int(1), Value::test_int(3)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"b".to_string(),
|
||||||
|
vec![Value::test_int(2), Value::test_int(4)],
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -41,19 +47,25 @@ impl Command for ToDataFrame {
|
|||||||
example: "[[1 2 a] [3 4 b] [5 6 c]] | dfr to-df",
|
example: "[[1 2 a] [3 4 b] [5 6 c]] | dfr to-df",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new("0".to_string(), vec![1.into(), 3.into(), 5.into()]),
|
Column::new(
|
||||||
Column::new("1".to_string(), vec![2.into(), 4.into(), 6.into()]),
|
"0".to_string(),
|
||||||
|
vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"1".to_string(),
|
||||||
|
vec![Value::test_int(2), Value::test_int(4), Value::test_int(6)],
|
||||||
|
),
|
||||||
Column::new(
|
Column::new(
|
||||||
"2".to_string(),
|
"2".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"a".to_string().into(),
|
Value::test_string("a"),
|
||||||
"b".to_string().into(),
|
Value::test_string("b"),
|
||||||
"c".to_string().into(),
|
Value::test_string("c"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -63,13 +75,13 @@ impl Command for ToDataFrame {
|
|||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![
|
vec![
|
||||||
"a".to_string().into(),
|
Value::test_string("a"),
|
||||||
"b".to_string().into(),
|
Value::test_string("b"),
|
||||||
"c".to_string().into(),
|
Value::test_string("c"),
|
||||||
],
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -78,10 +90,14 @@ impl Command for ToDataFrame {
|
|||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![Column::new(
|
NuDataFrame::try_from_columns(vec![Column::new(
|
||||||
"0".to_string(),
|
"0".to_string(),
|
||||||
vec![true.into(), true.into(), false.into()],
|
vec![
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(true),
|
||||||
|
Value::test_bool(false),
|
||||||
|
],
|
||||||
)])
|
)])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -7,7 +7,7 @@ use polars::chunked_array::object::builder::ObjectChunkedBuilder;
|
|||||||
use polars::chunked_array::ChunkedArray;
|
use polars::chunked_array::ChunkedArray;
|
||||||
use polars::prelude::{
|
use polars::prelude::{
|
||||||
DataFrame, DataType, DatetimeChunked, Int64Type, IntoSeries, NamedFrom, NewChunkedArray,
|
DataFrame, DataType, DatetimeChunked, Int64Type, IntoSeries, NamedFrom, NewChunkedArray,
|
||||||
ObjectType, PolarsNumericType, Series,
|
ObjectType, Series,
|
||||||
};
|
};
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
@ -109,13 +109,12 @@ pub fn create_column(
|
|||||||
series: &Series,
|
series: &Series,
|
||||||
from_row: usize,
|
from_row: usize,
|
||||||
to_row: usize,
|
to_row: usize,
|
||||||
|
span: Span,
|
||||||
) -> Result<Column, ShellError> {
|
) -> Result<Column, ShellError> {
|
||||||
let size = to_row - from_row;
|
let size = to_row - from_row;
|
||||||
match series.dtype() {
|
match series.dtype() {
|
||||||
DataType::Null => {
|
DataType::Null => {
|
||||||
let values = std::iter::repeat(Value::Nothing {
|
let values = std::iter::repeat(Value::Nothing { span })
|
||||||
span: Span::unknown(),
|
|
||||||
})
|
|
||||||
.take(size)
|
.take(size)
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -125,61 +124,188 @@ pub fn create_column(
|
|||||||
let casted = series.u8().map_err(|e| {
|
let casted = series.u8().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to u8".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to u8".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::UInt16 => {
|
DataType::UInt16 => {
|
||||||
let casted = series.u16().map_err(|e| {
|
let casted = series.u16().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to u16".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to u16".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::UInt32 => {
|
DataType::UInt32 => {
|
||||||
let casted = series.u32().map_err(|e| {
|
let casted = series.u32().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to u32".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to u32".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::UInt64 => {
|
DataType::UInt64 => {
|
||||||
let casted = series.u64().map_err(|e| {
|
let casted = series.u64().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to u64".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to u64".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Int8 => {
|
DataType::Int8 => {
|
||||||
let casted = series.i8().map_err(|e| {
|
let casted = series.i8().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to i8".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to i8".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Int16 => {
|
DataType::Int16 => {
|
||||||
let casted = series.i16().map_err(|e| {
|
let casted = series.i16().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to i16".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to i16".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Int32 => {
|
DataType::Int32 => {
|
||||||
let casted = series.i32().map_err(|e| {
|
let casted = series.i32().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to i32".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to i32".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Int64 => {
|
DataType::Int64 => {
|
||||||
let casted = series.i64().map_err(|e| {
|
let casted = series.i64().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to i64".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to i64".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Int {
|
||||||
|
val: a as i64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Float32 => {
|
DataType::Float32 => {
|
||||||
let casted = series.f32().map_err(|e| {
|
let casted = series.f32().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to f32".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to f32".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Float {
|
||||||
|
val: a as f64,
|
||||||
|
span,
|
||||||
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Float64 => {
|
DataType::Float64 => {
|
||||||
let casted = series.f64().map_err(|e| {
|
let casted = series.f64().map_err(|e| {
|
||||||
ShellError::LabeledError("Error casting column to f64".into(), e.to_string())
|
ShellError::LabeledError("Error casting column to f64".into(), e.to_string())
|
||||||
})?;
|
})?;
|
||||||
Ok(column_from_casted(casted, from_row, size))
|
let values = casted
|
||||||
|
.into_iter()
|
||||||
|
.skip(from_row)
|
||||||
|
.take(size)
|
||||||
|
.map(|v| match v {
|
||||||
|
Some(a) => Value::Float { val: a, span },
|
||||||
|
None => Value::Nothing { span },
|
||||||
|
})
|
||||||
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
Ok(Column::new(casted.name().into(), values))
|
||||||
}
|
}
|
||||||
DataType::Boolean => {
|
DataType::Boolean => {
|
||||||
let casted = series.bool().map_err(|e| {
|
let casted = series.bool().map_err(|e| {
|
||||||
@ -191,13 +317,8 @@ pub fn create_column(
|
|||||||
.skip(from_row)
|
.skip(from_row)
|
||||||
.take(size)
|
.take(size)
|
||||||
.map(|v| match v {
|
.map(|v| match v {
|
||||||
Some(a) => Value::Bool {
|
Some(a) => Value::Bool { val: a, span },
|
||||||
val: a,
|
None => Value::Nothing { span },
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
None => Value::Nothing {
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -215,11 +336,9 @@ pub fn create_column(
|
|||||||
.map(|v| match v {
|
.map(|v| match v {
|
||||||
Some(a) => Value::String {
|
Some(a) => Value::String {
|
||||||
val: a.into(),
|
val: a.into(),
|
||||||
span: Span::unknown(),
|
span,
|
||||||
},
|
|
||||||
None => Value::Nothing {
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -242,9 +361,7 @@ pub fn create_column(
|
|||||||
.take(size)
|
.take(size)
|
||||||
.map(|v| match v {
|
.map(|v| match v {
|
||||||
Some(a) => a.get_value(),
|
Some(a) => a.get_value(),
|
||||||
None => Value::Nothing {
|
None => Value::Nothing { span },
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -273,12 +390,10 @@ pub fn create_column(
|
|||||||
|
|
||||||
Value::Date {
|
Value::Date {
|
||||||
val: datetime,
|
val: datetime,
|
||||||
span: Span::unknown(),
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => Value::Nothing {
|
None => Value::Nothing { span },
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -305,12 +420,10 @@ pub fn create_column(
|
|||||||
|
|
||||||
Value::Date {
|
Value::Date {
|
||||||
val: datetime,
|
val: datetime,
|
||||||
span: Span::unknown(),
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => Value::Nothing {
|
None => Value::Nothing { span },
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -328,11 +441,9 @@ pub fn create_column(
|
|||||||
.map(|v| match v {
|
.map(|v| match v {
|
||||||
Some(nanoseconds) => Value::Duration {
|
Some(nanoseconds) => Value::Duration {
|
||||||
val: nanoseconds,
|
val: nanoseconds,
|
||||||
span: Span::unknown(),
|
span,
|
||||||
},
|
|
||||||
None => Value::Nothing {
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
},
|
||||||
|
None => Value::Nothing { span },
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
@ -345,29 +456,9 @@ pub fn create_column(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn column_from_casted<T>(casted: &ChunkedArray<T>, from_row: usize, size: usize) -> Column
|
|
||||||
where
|
|
||||||
T: PolarsNumericType,
|
|
||||||
T::Native: Into<Value>,
|
|
||||||
{
|
|
||||||
let values = casted
|
|
||||||
.into_iter()
|
|
||||||
.skip(from_row)
|
|
||||||
.take(size)
|
|
||||||
.map(|v| match v {
|
|
||||||
Some(a) => a.into(),
|
|
||||||
None => Value::Nothing {
|
|
||||||
span: Span::unknown(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.collect::<Vec<Value>>();
|
|
||||||
|
|
||||||
Column::new(casted.name().into(), values)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a separator to the vector of values using the column names from the
|
// Adds a separator to the vector of values using the column names from the
|
||||||
// dataframe to create the Values Row
|
// dataframe to create the Values Row
|
||||||
pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame) {
|
pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame, span: Span) {
|
||||||
let mut cols = vec![];
|
let mut cols = vec![];
|
||||||
let mut vals = vec![];
|
let mut vals = vec![];
|
||||||
|
|
||||||
@ -375,15 +466,11 @@ pub fn add_separator(values: &mut Vec<Value>, df: &DataFrame) {
|
|||||||
cols.push(name.to_string());
|
cols.push(name.to_string());
|
||||||
vals.push(Value::String {
|
vals.push(Value::String {
|
||||||
val: "...".into(),
|
val: "...".into(),
|
||||||
span: Span::unknown(),
|
span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let extra_record = Value::Record {
|
let extra_record = Value::Record { cols, vals, span };
|
||||||
cols,
|
|
||||||
vals,
|
|
||||||
span: Span::unknown(),
|
|
||||||
};
|
|
||||||
|
|
||||||
values.push(extra_record);
|
values.push(extra_record);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ impl CustomValue for NuDataFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_base_value(&self, span: Span) -> Result<Value, ShellError> {
|
fn to_base_value(&self, span: Span) -> Result<Value, ShellError> {
|
||||||
let vals = self.print()?;
|
let vals = self.print(span)?;
|
||||||
|
|
||||||
Ok(Value::List { vals, span })
|
Ok(Value::List { vals, span })
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ impl Display for DataFrameValue {
|
|||||||
impl Default for DataFrameValue {
|
impl Default for DataFrameValue {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(Value::Nothing {
|
Self(Value::Nothing {
|
||||||
span: Span::unknown(),
|
span: Span { start: 0, end: 0 },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,15 +178,15 @@ impl NuDataFrame {
|
|||||||
Value::CustomValue { val, span } => match val.as_any().downcast_ref::<NuDataFrame>() {
|
Value::CustomValue { val, span } => match val.as_any().downcast_ref::<NuDataFrame>() {
|
||||||
Some(df) => Ok(NuDataFrame(df.0.clone())),
|
Some(df) => Ok(NuDataFrame(df.0.clone())),
|
||||||
None => Err(ShellError::CantConvert(
|
None => Err(ShellError::CantConvert(
|
||||||
"Dataframe not found".into(),
|
"dataframe".into(),
|
||||||
"value is not a dataframe".into(),
|
"non-dataframe".into(),
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
},
|
},
|
||||||
_ => Err(ShellError::CantConvert(
|
x => Err(ShellError::CantConvert(
|
||||||
"Dataframe not found".into(),
|
"dataframe".into(),
|
||||||
"value is not a dataframe".into(),
|
x.get_type().to_string(),
|
||||||
value.span()?,
|
x.span()?,
|
||||||
)),
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,8 +239,8 @@ impl NuDataFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_value(&self, row: usize, span: Span) -> Result<Value, ShellError> {
|
pub fn get_value(&self, row: usize, span: Span) -> Result<Value, ShellError> {
|
||||||
let series = self.as_series(Span::unknown())?;
|
let series = self.as_series(span)?;
|
||||||
let column = conversion::create_column(&series, row, row + 1)?;
|
let column = conversion::create_column(&series, row, row + 1, span)?;
|
||||||
|
|
||||||
if column.len() == 0 {
|
if column.len() == 0 {
|
||||||
Err(ShellError::AccessBeyondEnd(series.len(), span))
|
Err(ShellError::AccessBeyondEnd(series.len(), span))
|
||||||
@ -254,44 +254,49 @@ impl NuDataFrame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Print is made out a head and if the dataframe is too large, then a tail
|
// Print is made out a head and if the dataframe is too large, then a tail
|
||||||
pub fn print(&self) -> Result<Vec<Value>, ShellError> {
|
pub fn print(&self, span: Span) -> Result<Vec<Value>, ShellError> {
|
||||||
let df = &self.0;
|
let df = &self.0;
|
||||||
let size: usize = 20;
|
let size: usize = 20;
|
||||||
|
|
||||||
if df.height() > size {
|
if df.height() > size {
|
||||||
let sample_size = size / 2;
|
let sample_size = size / 2;
|
||||||
let mut values = self.head(Some(sample_size))?;
|
let mut values = self.head(Some(sample_size), span)?;
|
||||||
conversion::add_separator(&mut values, df);
|
conversion::add_separator(&mut values, df, span);
|
||||||
let remaining = df.height() - sample_size;
|
let remaining = df.height() - sample_size;
|
||||||
let tail_size = remaining.min(sample_size);
|
let tail_size = remaining.min(sample_size);
|
||||||
let mut tail_values = self.tail(Some(tail_size))?;
|
let mut tail_values = self.tail(Some(tail_size), span)?;
|
||||||
values.append(&mut tail_values);
|
values.append(&mut tail_values);
|
||||||
|
|
||||||
Ok(values)
|
Ok(values)
|
||||||
} else {
|
} else {
|
||||||
Ok(self.head(Some(size))?)
|
Ok(self.head(Some(size), span)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn head(&self, rows: Option<usize>) -> Result<Vec<Value>, ShellError> {
|
pub fn head(&self, rows: Option<usize>, span: Span) -> Result<Vec<Value>, ShellError> {
|
||||||
let to_row = rows.unwrap_or(5);
|
let to_row = rows.unwrap_or(5);
|
||||||
let values = self.to_rows(0, to_row)?;
|
let values = self.to_rows(0, to_row, span)?;
|
||||||
|
|
||||||
Ok(values)
|
Ok(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tail(&self, rows: Option<usize>) -> Result<Vec<Value>, ShellError> {
|
pub fn tail(&self, rows: Option<usize>, span: Span) -> Result<Vec<Value>, ShellError> {
|
||||||
let df = &self.0;
|
let df = &self.0;
|
||||||
let to_row = df.height();
|
let to_row = df.height();
|
||||||
let size = rows.unwrap_or(5);
|
let size = rows.unwrap_or(5);
|
||||||
let from_row = to_row.saturating_sub(size);
|
let from_row = to_row.saturating_sub(size);
|
||||||
|
|
||||||
let values = self.to_rows(from_row, to_row)?;
|
let values = self.to_rows(from_row, to_row, span)?;
|
||||||
|
|
||||||
Ok(values)
|
Ok(values)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_rows(&self, from_row: usize, to_row: usize) -> Result<Vec<Value>, ShellError> {
|
pub fn to_rows(
|
||||||
|
&self,
|
||||||
|
from_row: usize,
|
||||||
|
to_row: usize,
|
||||||
|
span: Span,
|
||||||
|
) -> Result<Vec<Value>, ShellError> {
|
||||||
let df = &self.0;
|
let df = &self.0;
|
||||||
let upper_row = to_row.min(df.height());
|
let upper_row = to_row.min(df.height());
|
||||||
|
|
||||||
@ -301,7 +306,7 @@ impl NuDataFrame {
|
|||||||
.get_columns()
|
.get_columns()
|
||||||
.iter()
|
.iter()
|
||||||
.map(
|
.map(
|
||||||
|col| match conversion::create_column(col, from_row, upper_row) {
|
|col| match conversion::create_column(col, from_row, upper_row, span) {
|
||||||
Ok(col) => {
|
Ok(col) => {
|
||||||
size = col.len();
|
size = col.len();
|
||||||
Ok(col)
|
Ok(col)
|
||||||
@ -327,17 +332,11 @@ impl NuDataFrame {
|
|||||||
|
|
||||||
match col.next() {
|
match col.next() {
|
||||||
Some(v) => vals.push(v),
|
Some(v) => vals.push(v),
|
||||||
None => vals.push(Value::Nothing {
|
None => vals.push(Value::Nothing { span }),
|
||||||
span: Span::unknown(),
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::Record {
|
Value::Record { cols, vals, span }
|
||||||
cols,
|
|
||||||
vals,
|
|
||||||
span: Span::unknown(),
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<Value>>();
|
.collect::<Vec<Value>>();
|
||||||
|
|
||||||
|
@ -33,12 +33,21 @@ impl Command for WithColumn {
|
|||||||
"[[a b]; [1 2] [3 4]] | dfr to-df | dfr with-column ([5 6] | dfr to-df) --name c",
|
"[[a b]; [1 2] [3 4]] | dfr to-df | dfr with-column ([5 6] | dfr to-df) --name c",
|
||||||
result: Some(
|
result: Some(
|
||||||
NuDataFrame::try_from_columns(vec![
|
NuDataFrame::try_from_columns(vec![
|
||||||
Column::new("a".to_string(), vec![1.into(), 3.into()]),
|
Column::new(
|
||||||
Column::new("b".to_string(), vec![2.into(), 4.into()]),
|
"a".to_string(),
|
||||||
Column::new("c".to_string(), vec![5.into(), 6.into()]),
|
vec![Value::test_int(1), Value::test_int(3)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"b".to_string(),
|
||||||
|
vec![Value::test_int(2), Value::test_int(4)],
|
||||||
|
),
|
||||||
|
Column::new(
|
||||||
|
"c".to_string(),
|
||||||
|
vec![Value::test_int(5), Value::test_int(6)],
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.expect("simple df for test should not fail")
|
.expect("simple df for test should not fail")
|
||||||
.into_value(Span::unknown()),
|
.into_value(Span::test_data()),
|
||||||
),
|
),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ impl Command for SubCommand {
|
|||||||
example: "date format '%Y-%m-%d'",
|
example: "date format '%Y-%m-%d'",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: Local::now().format("%Y-%m-%d").to_string(),
|
val: Local::now().format("%Y-%m-%d").to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -60,7 +60,7 @@ impl Command for SubCommand {
|
|||||||
example: r#"date format "%Y-%m-%d %H:%M:%S""#,
|
example: r#"date format "%Y-%m-%d %H:%M:%S""#,
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
|
val: Local::now().format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -68,7 +68,7 @@ impl Command for SubCommand {
|
|||||||
example: r#""2021-10-22 20:00:12 +01:00" | date format "%Y-%m-%d""#,
|
example: r#""2021-10-22 20:00:12 +01:00" | date format "%Y-%m-%d""#,
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "2021-10-22".into(),
|
val: "2021-10-22".into(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -81,8 +81,11 @@ fn format_helper(value: Value, formatter: &Spanned<String>, span: Span) -> Value
|
|||||||
val: val.format(formatter.item.as_str()).to_string(),
|
val: val.format(formatter.item.as_str()).to_string(),
|
||||||
span,
|
span,
|
||||||
},
|
},
|
||||||
Value::String { val, span: _ } => {
|
Value::String {
|
||||||
let dt = parse_date_from_string(val);
|
val,
|
||||||
|
span: val_span,
|
||||||
|
} => {
|
||||||
|
let dt = parse_date_from_string(val, val_span);
|
||||||
match dt {
|
match dt {
|
||||||
Ok(x) => Value::String {
|
Ok(x) => Value::String {
|
||||||
val: x.format(formatter.item.as_str()).to_string(),
|
val: x.format(formatter.item.as_str()).to_string(),
|
||||||
@ -101,7 +104,7 @@ fn format_helper(value: Value, formatter: &Spanned<String>, span: Span) -> Value
|
|||||||
span,
|
span,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unsupported_input_error(),
|
_ => unsupported_input_error(span),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ impl Command for SubCommand {
|
|||||||
example: "date humanize",
|
example: "date humanize",
|
||||||
result: Some(Value::String {
|
result: Some(Value::String {
|
||||||
val: "now".to_string(),
|
val: "now".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -59,8 +59,11 @@ fn helper(value: Value, head: Span) -> Value {
|
|||||||
span: head,
|
span: head,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value::String { val, span: _ } => {
|
Value::String {
|
||||||
let dt = parse_date_from_string(val);
|
val,
|
||||||
|
span: val_span,
|
||||||
|
} => {
|
||||||
|
let dt = parse_date_from_string(val, val_span);
|
||||||
match dt {
|
match dt {
|
||||||
Ok(x) => Value::String {
|
Ok(x) => Value::String {
|
||||||
val: humanize_date(x),
|
val: humanize_date(x),
|
||||||
@ -76,7 +79,7 @@ fn helper(value: Value, head: Span) -> Value {
|
|||||||
_ => Value::Error {
|
_ => Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
error: ShellError::UnsupportedInput(
|
||||||
String::from("Date cannot be parsed / date format is not supported"),
|
String::from("Date cannot be parsed / date format is not supported"),
|
||||||
Span::unknown(),
|
head,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ impl Command for SubCommand {
|
|||||||
description: "Print the date in a structured table.",
|
description: "Print the date in a structured table.",
|
||||||
example: " '2020-04-12 22:10:57 +0200' | date to-table",
|
example: " '2020-04-12 22:10:57 +0200' | date to-table",
|
||||||
result: {
|
result: {
|
||||||
let span = Span::unknown();
|
let span = Span::test_data();
|
||||||
let cols = vec![
|
let cols = vec![
|
||||||
"year".into(),
|
"year".into(),
|
||||||
"month".into(),
|
"month".into(),
|
||||||
@ -136,8 +136,11 @@ fn parse_date_into_table(date: Result<DateTime<FixedOffset>, Value>, head: Span)
|
|||||||
|
|
||||||
fn helper(val: Value, head: Span) -> Value {
|
fn helper(val: Value, head: Span) -> Value {
|
||||||
match val {
|
match val {
|
||||||
Value::String { val, span: _ } => {
|
Value::String {
|
||||||
let date = parse_date_from_string(val);
|
val,
|
||||||
|
span: val_span,
|
||||||
|
} => {
|
||||||
|
let date = parse_date_from_string(val, val_span);
|
||||||
parse_date_into_table(date, head)
|
parse_date_into_table(date, head)
|
||||||
}
|
}
|
||||||
Value::Nothing { span: _ } => {
|
Value::Nothing { span: _ } => {
|
||||||
@ -146,7 +149,7 @@ fn helper(val: Value, head: Span) -> Value {
|
|||||||
parse_date_into_table(Ok(n), head)
|
parse_date_into_table(Ok(n), head)
|
||||||
}
|
}
|
||||||
Value::Date { val, span: _ } => parse_date_into_table(Ok(val), head),
|
Value::Date { val, span: _ } => parse_date_into_table(Ok(val), head),
|
||||||
_ => unsupported_input_error(),
|
_ => unsupported_input_error(head),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ impl Command for SubCommand {
|
|||||||
|
|
||||||
Some(Value::Date {
|
Some(Value::Date {
|
||||||
val: dt,
|
val: dt,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -89,8 +89,11 @@ impl Command for SubCommand {
|
|||||||
fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
|
fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
|
||||||
match value {
|
match value {
|
||||||
Value::Date { val, span: _ } => _to_timezone(val, timezone, head),
|
Value::Date { val, span: _ } => _to_timezone(val, timezone, head),
|
||||||
Value::String { val, span: _ } => {
|
Value::String {
|
||||||
let time = parse_date_from_string(val);
|
val,
|
||||||
|
span: val_span,
|
||||||
|
} => {
|
||||||
|
let time = parse_date_from_string(val, val_span);
|
||||||
match time {
|
match time {
|
||||||
Ok(dt) => _to_timezone(dt, timezone, head),
|
Ok(dt) => _to_timezone(dt, timezone, head),
|
||||||
Err(e) => e,
|
Err(e) => e,
|
||||||
@ -101,7 +104,7 @@ fn helper(value: Value, head: Span, timezone: &Spanned<String>) -> Value {
|
|||||||
let dt = Local::now();
|
let dt = Local::now();
|
||||||
_to_timezone(dt.with_timezone(dt.offset()), timezone, head)
|
_to_timezone(dt.with_timezone(dt.offset()), timezone, head)
|
||||||
}
|
}
|
||||||
_ => unsupported_input_error(),
|
_ => unsupported_input_error(head),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use chrono::{DateTime, FixedOffset};
|
use chrono::{DateTime, FixedOffset};
|
||||||
use nu_protocol::{ShellError, Span, Value};
|
use nu_protocol::{ShellError, Span, Value};
|
||||||
|
|
||||||
pub fn unsupported_input_error() -> Value {
|
pub fn unsupported_input_error(span: Span) -> Value {
|
||||||
Value::Error {
|
Value::Error {
|
||||||
error: ShellError::UnsupportedInput(
|
error: ShellError::UnsupportedInput(
|
||||||
String::from(
|
String::from(
|
||||||
@ -11,12 +11,12 @@ pub fn unsupported_input_error() -> Value {
|
|||||||
* rfc3339 -- 2020-04-12T22:10:57+02:00 \n
|
* rfc3339 -- 2020-04-12T22:10:57+02:00 \n
|
||||||
* rfc2822 -- Tue, 1 Jul 2003 10:52:37 +0200",
|
* rfc2822 -- Tue, 1 Jul 2003 10:52:37 +0200",
|
||||||
),
|
),
|
||||||
Span::unknown(),
|
span,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_date_from_string(input: String) -> Result<DateTime<FixedOffset>, Value> {
|
pub fn parse_date_from_string(input: String, span: Span) -> Result<DateTime<FixedOffset>, Value> {
|
||||||
let datetime = DateTime::parse_from_str(&input, "%Y-%m-%d %H:%M:%S %z"); // "2020-04-12 22:10:57 +02:00";
|
let datetime = DateTime::parse_from_str(&input, "%Y-%m-%d %H:%M:%S %z"); // "2020-04-12 22:10:57 +02:00";
|
||||||
match datetime {
|
match datetime {
|
||||||
Ok(x) => Ok(x),
|
Ok(x) => Ok(x),
|
||||||
@ -32,7 +32,7 @@ pub fn parse_date_from_string(input: String) -> Result<DateTime<FixedOffset>, Va
|
|||||||
let datetime = DateTime::parse_from_rfc2822(&input); // "Tue, 1 Jul 2003 10:52:37 +0200";
|
let datetime = DateTime::parse_from_rfc2822(&input); // "Tue, 1 Jul 2003 10:52:37 +0200";
|
||||||
match datetime {
|
match datetime {
|
||||||
Ok(x) => Ok(x),
|
Ok(x) => Ok(x),
|
||||||
Err(_) => Err(unsupported_input_error()),
|
Err(_) => Err(unsupported_input_error(span)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
|
#[cfg(test)]
|
||||||
use nu_engine::eval_block;
|
use nu_engine::eval_block;
|
||||||
|
#[cfg(test)]
|
||||||
use nu_parser::parse;
|
use nu_parser::parse;
|
||||||
|
#[cfg(test)]
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
engine::{Command, EngineState, Stack, StateWorkingSet},
|
engine::{Command, EngineState, Stack, StateWorkingSet},
|
||||||
PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
PipelineData, Span, Value, CONFIG_VARIABLE_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
use crate::To;
|
use crate::To;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
use super::{Ansi, Date, From, Into, Math, Path, Random, Split, Str, StrCollect, Url};
|
use super::{Ansi, Date, From, Into, Math, Path, Random, Split, Str, StrCollect, Url};
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
pub fn test_examples(cmd: impl Command + 'static) {
|
pub fn test_examples(cmd: impl Command + 'static) {
|
||||||
let examples = cmd.examples();
|
let examples = cmd.examples();
|
||||||
let mut engine_state = Box::new(EngineState::new());
|
let mut engine_state = Box::new(EngineState::new());
|
||||||
@ -68,7 +74,7 @@ pub fn test_examples(cmd: impl Command + 'static) {
|
|||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec![],
|
cols: vec![],
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -76,11 +82,11 @@ pub fn test_examples(cmd: impl Command + 'static) {
|
|||||||
&engine_state,
|
&engine_state,
|
||||||
&mut stack,
|
&mut stack,
|
||||||
&block,
|
&block,
|
||||||
PipelineData::new(Span::unknown()),
|
PipelineData::new(Span::test_data()),
|
||||||
) {
|
) {
|
||||||
Err(err) => panic!("test eval error in `{}`: {:?}", example.example, err),
|
Err(err) => panic!("test eval error in `{}`: {:?}", example.example, err),
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
let result = result.into_value(Span::unknown());
|
let result = result.into_value(Span::test_data());
|
||||||
println!("input: {}", example.example);
|
println!("input: {}", example.example);
|
||||||
println!("result: {:?}", result);
|
println!("result: {:?}", result);
|
||||||
println!("done: {:?}", start.elapsed());
|
println!("done: {:?}", start.elapsed());
|
||||||
|
@ -2,7 +2,7 @@ use nu_engine::eval_block;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape,
|
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -28,18 +28,16 @@ impl Command for All {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
use nu_protocol::Value;
|
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Find if services are running",
|
description: "Find if services are running",
|
||||||
example: "echo [[status]; [UP] [UP]] | all? status == UP",
|
example: "echo [[status]; [UP] [UP]] | all? status == UP",
|
||||||
result: Some(Value::from(true)),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check that all values are even",
|
description: "Check that all values are even",
|
||||||
example: "echo [2 4 6 8] | all? ($it mod 2) == 0",
|
example: "echo [2 4 6 8] | all? ($it mod 2) == 0",
|
||||||
result: Some(Value::from(true)),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -65,9 +63,8 @@ impl Command for All {
|
|||||||
let ctrlc = engine_state.ctrlc.clone();
|
let ctrlc = engine_state.ctrlc.clone();
|
||||||
let engine_state = engine_state.clone();
|
let engine_state = engine_state.clone();
|
||||||
|
|
||||||
Ok(input
|
Ok(Value::Bool {
|
||||||
.into_interruptible_iter(ctrlc)
|
val: input.into_interruptible_iter(ctrlc).all(move |value| {
|
||||||
.all(move |value| {
|
|
||||||
if let Some(var_id) = var_id {
|
if let Some(var_id) = var_id {
|
||||||
stack.add_var(var_id, value);
|
stack.add_var(var_id, value);
|
||||||
}
|
}
|
||||||
@ -76,7 +73,9 @@ impl Command for All {
|
|||||||
.map_or(false, |pipeline_data| {
|
.map_or(false, |pipeline_data| {
|
||||||
pipeline_data.into_value(span).is_true()
|
pipeline_data.into_value(span).is_true()
|
||||||
})
|
})
|
||||||
})
|
}),
|
||||||
|
span,
|
||||||
|
}
|
||||||
.into_pipeline_data())
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use nu_engine::eval_block;
|
|||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
ast::Call,
|
ast::Call,
|
||||||
engine::{Command, EngineState, Stack},
|
engine::{Command, EngineState, Stack},
|
||||||
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape,
|
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -28,18 +28,16 @@ impl Command for Any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
use nu_protocol::Value;
|
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
Example {
|
Example {
|
||||||
description: "Find if a service is not running",
|
description: "Find if a service is not running",
|
||||||
example: "echo [[status]; [UP] [DOWN] [UP]] | any? status == DOWN",
|
example: "echo [[status]; [UP] [DOWN] [UP]] | any? status == DOWN",
|
||||||
result: Some(Value::from(true)),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Check if any of the values is odd",
|
description: "Check if any of the values is odd",
|
||||||
example: "echo [2 4 1 6 8] | any? ($it mod 2) == 1",
|
example: "echo [2 4 1 6 8] | any? ($it mod 2) == 1",
|
||||||
result: Some(Value::from(true)),
|
result: Some(Value::test_bool(true)),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -65,9 +63,8 @@ impl Command for Any {
|
|||||||
let ctrlc = engine_state.ctrlc.clone();
|
let ctrlc = engine_state.ctrlc.clone();
|
||||||
let engine_state = engine_state.clone();
|
let engine_state = engine_state.clone();
|
||||||
|
|
||||||
Ok(input
|
Ok(Value::Bool {
|
||||||
.into_interruptible_iter(ctrlc)
|
val: input.into_interruptible_iter(ctrlc).any(move |value| {
|
||||||
.any(move |value| {
|
|
||||||
if let Some(var_id) = var_id {
|
if let Some(var_id) = var_id {
|
||||||
stack.add_var(var_id, value);
|
stack.add_var(var_id, value);
|
||||||
}
|
}
|
||||||
@ -76,7 +73,9 @@ impl Command for Any {
|
|||||||
.map_or(false, |pipeline_data| {
|
.map_or(false, |pipeline_data| {
|
||||||
pipeline_data.into_value(span).is_true()
|
pipeline_data.into_value(span).is_true()
|
||||||
})
|
})
|
||||||
})
|
}),
|
||||||
|
span,
|
||||||
|
}
|
||||||
.into_pipeline_data())
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ impl Command for Append {
|
|||||||
Value::test_int(3),
|
Value::test_int(3),
|
||||||
Value::test_int(4),
|
Value::test_int(4),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -51,7 +51,7 @@ impl Command for Append {
|
|||||||
Value::test_int(3),
|
Value::test_int(3),
|
||||||
Value::test_int(4),
|
Value::test_int(4),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -66,7 +66,7 @@ impl Command for Append {
|
|||||||
Value::test_int(4),
|
Value::test_int(4),
|
||||||
Value::test_string("shell"),
|
Value::test_string("shell"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -62,13 +62,14 @@ fn getcol(
|
|||||||
PipelineData::Value(
|
PipelineData::Value(
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: input_vals,
|
vals: input_vals,
|
||||||
span: _,
|
span,
|
||||||
},
|
},
|
||||||
..,
|
..,
|
||||||
) => {
|
) => {
|
||||||
let input_cols = get_input_cols(input_vals);
|
let input_cols = get_input_cols(input_vals);
|
||||||
Ok(input_cols
|
Ok(input_cols
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.map(move |x| Value::String { val: x, span })
|
||||||
.into_pipeline_data(engine_state.ctrlc.clone()))
|
.into_pipeline_data(engine_state.ctrlc.clone()))
|
||||||
}
|
}
|
||||||
PipelineData::Stream(stream, ..) => {
|
PipelineData::Stream(stream, ..) => {
|
||||||
@ -77,6 +78,7 @@ fn getcol(
|
|||||||
|
|
||||||
Ok(input_cols
|
Ok(input_cols
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
.map(move |x| Value::String { val: x, span })
|
||||||
.into_pipeline_data(engine_state.ctrlc.clone()))
|
.into_pipeline_data(engine_state.ctrlc.clone()))
|
||||||
}
|
}
|
||||||
PipelineData::Value(_v, ..) => {
|
PipelineData::Value(_v, ..) => {
|
||||||
|
@ -68,7 +68,7 @@ fn dropcol(
|
|||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
let input_cols = get_input_cols(input_vals.clone());
|
let input_cols = get_input_cols(input_vals.clone());
|
||||||
let kc = get_keep_columns(input_cols, columns);
|
let kc = get_keep_columns(input_cols, columns);
|
||||||
keep_columns = get_cellpath_columns(kc);
|
keep_columns = get_cellpath_columns(kc, span);
|
||||||
|
|
||||||
for input_val in input_vals {
|
for input_val in input_vals {
|
||||||
let mut cols = vec![];
|
let mut cols = vec![];
|
||||||
@ -92,7 +92,7 @@ fn dropcol(
|
|||||||
let v: Vec<_> = stream.into_iter().collect();
|
let v: Vec<_> = stream.into_iter().collect();
|
||||||
let input_cols = get_input_cols(v.clone());
|
let input_cols = get_input_cols(v.clone());
|
||||||
let kc = get_keep_columns(input_cols, columns);
|
let kc = get_keep_columns(input_cols, columns);
|
||||||
keep_columns = get_cellpath_columns(kc);
|
keep_columns = get_cellpath_columns(kc, span);
|
||||||
|
|
||||||
for input_val in v {
|
for input_val in v {
|
||||||
let mut cols = vec![];
|
let mut cols = vec![];
|
||||||
@ -134,10 +134,9 @@ fn get_input_cols(input: Vec<Value>) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cellpath_columns(keep_cols: Vec<String>) -> Vec<CellPath> {
|
fn get_cellpath_columns(keep_cols: Vec<String>, span: Span) -> Vec<CellPath> {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for keep_col in keep_cols {
|
for keep_col in keep_cols {
|
||||||
let span = Span::unknown();
|
|
||||||
let val = Value::String {
|
let val = Value::String {
|
||||||
val: keep_col,
|
val: keep_col,
|
||||||
span,
|
span,
|
||||||
|
@ -36,7 +36,7 @@ impl Command for Drop {
|
|||||||
description: "Remove the last item of a list/table",
|
description: "Remove the last item of a list/table",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
|
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -49,7 +49,7 @@ impl Command for Drop {
|
|||||||
Value::test_int(2),
|
Value::test_int(2),
|
||||||
Value::test_int(3),
|
Value::test_int(3),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -57,7 +57,7 @@ impl Command for Drop {
|
|||||||
description: "Remove the last two items of a list/table",
|
description: "Remove the last two items of a list/table",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(0), Value::test_int(1)],
|
vals: vec![Value::test_int(0), Value::test_int(1)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -31,7 +31,7 @@ impl Command for DropNth {
|
|||||||
description: "Drop the first, second, and third row",
|
description: "Drop the first, second, and third row",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
|
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -39,7 +39,7 @@ impl Command for DropNth {
|
|||||||
description: "Drop the first, second, and third row",
|
description: "Drop the first, second, and third row",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
|
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -47,7 +47,7 @@ impl Command for DropNth {
|
|||||||
description: "Drop rows 0 2 4",
|
description: "Drop rows 0 2 4",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
|
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -55,7 +55,7 @@ impl Command for DropNth {
|
|||||||
description: "Drop rows 2 0 4",
|
description: "Drop rows 2 0 4",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
|
vals: vec![Value::test_int(1), Value::test_int(3), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -33,15 +33,15 @@ impl Command for Each {
|
|||||||
let stream_test_1 = vec![
|
let stream_test_1 = vec![
|
||||||
Value::Int {
|
Value::Int {
|
||||||
val: 2,
|
val: 2,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Int {
|
Value::Int {
|
||||||
val: 4,
|
val: 4,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Int {
|
Value::Int {
|
||||||
val: 6,
|
val: 6,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ impl Command for Each {
|
|||||||
description: "Multiplies elements in list",
|
description: "Multiplies elements in list",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: stream_test_1,
|
vals: stream_test_1,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ impl Command for First {
|
|||||||
example: "[1 2 3] | first 2",
|
example: "[1 2 3] | first 2",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(1), Value::test_int(2)],
|
vals: vec![Value::test_int(1), Value::test_int(2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -35,7 +35,7 @@ impl Command for Get {
|
|||||||
let cell_path: CellPath = call.req(engine_state, stack, 0)?;
|
let cell_path: CellPath = call.req(engine_state, stack, 0)?;
|
||||||
|
|
||||||
input
|
input
|
||||||
.follow_cell_path(&cell_path.members)
|
.follow_cell_path(&cell_path.members, call.head)
|
||||||
.map(|x| x.into_pipeline_data())
|
.map(|x| x.into_pipeline_data())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,24 +35,24 @@ impl Command for Keep {
|
|||||||
vals: vec![
|
vals: vec![
|
||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["editions".to_owned()],
|
cols: vec!["editions".to_owned()],
|
||||||
vals: vec![Value::from(2015)],
|
vals: vec![Value::test_int(2015)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["editions".to_owned()],
|
cols: vec!["editions".to_owned()],
|
||||||
vals: vec![Value::from(2018)],
|
vals: vec![Value::test_int(2018)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Keep the first value",
|
description: "Keep the first value",
|
||||||
example: "echo [2 4 6 8] | keep",
|
example: "echo [2 4 6 8] | keep",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::from(2)],
|
vals: vec![Value::test_int(2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -33,8 +33,8 @@ impl Command for KeepUntil {
|
|||||||
description: "Keep until the element is positive",
|
description: "Keep until the element is positive",
|
||||||
example: "echo [-1 -2 9 1] | keep until $it > 0",
|
example: "echo [-1 -2 9 1] | keep until $it > 0",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::from(-1), Value::from(-2)],
|
vals: vec![Value::test_int(-1), Value::test_int(-2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ impl Command for KeepWhile {
|
|||||||
description: "Keep while the element is negative",
|
description: "Keep while the element is negative",
|
||||||
example: "echo [-1 -2 9 1] | keep while $it < 0",
|
example: "echo [-1 -2 9 1] | keep while $it < 0",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::from(-1), Value::from(-2)],
|
vals: vec![Value::test_int(-1), Value::test_int(-2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ impl Command for Last {
|
|||||||
description: "Get the last 2 items",
|
description: "Get the last 2 items",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(2), Value::test_int(3)],
|
vals: vec![Value::test_int(2), Value::test_int(3)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ impl Command for Nth {
|
|||||||
Value::test_string("sarah"),
|
Value::test_string("sarah"),
|
||||||
Value::test_int(2),
|
Value::test_int(2),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -44,7 +44,7 @@ impl Command for Nth {
|
|||||||
description: "Get the first, second, and third row",
|
description: "Get the first, second, and third row",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
|
vals: vec![Value::test_int(0), Value::test_int(1), Value::test_int(2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -52,7 +52,7 @@ impl Command for Nth {
|
|||||||
description: "Skip the first, second, and third row",
|
description: "Skip the first, second, and third row",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
|
vals: vec![Value::test_int(3), Value::test_int(4), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -60,7 +60,7 @@ impl Command for Nth {
|
|||||||
description: "Get the first, third, and fifth row",
|
description: "Get the first, third, and fifth row",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(4)],
|
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(4)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -68,7 +68,7 @@ impl Command for Nth {
|
|||||||
description: "Get the first, third, and fifth row",
|
description: "Get the first, third, and fifth row",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(4)],
|
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(4)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -37,7 +37,7 @@ impl Command for Prepend {
|
|||||||
Value::test_int(3),
|
Value::test_int(3),
|
||||||
Value::test_int(4),
|
Value::test_int(4),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -51,7 +51,7 @@ impl Command for Prepend {
|
|||||||
Value::test_int(3),
|
Value::test_int(3),
|
||||||
Value::test_int(4),
|
Value::test_int(4),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -67,7 +67,7 @@ impl Command for Prepend {
|
|||||||
Value::test_int(4),
|
Value::test_int(4),
|
||||||
Value::test_string("shell"),
|
Value::test_string("shell"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -36,7 +36,7 @@ impl Command for Range {
|
|||||||
description: "Get the last 2 items",
|
description: "Get the last 2 items",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(4), Value::test_int(5)],
|
vals: vec![Value::test_int(4), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -44,7 +44,7 @@ impl Command for Range {
|
|||||||
description: "Get the last 2 items",
|
description: "Get the last 2 items",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(4), Value::test_int(5)],
|
vals: vec![Value::test_int(4), Value::test_int(5)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -52,7 +52,7 @@ impl Command for Range {
|
|||||||
description: "Get the next to last 2 items",
|
description: "Get the next to last 2 items",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(3), Value::test_int(4)],
|
vals: vec![Value::test_int(3), Value::test_int(4)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -64,7 +64,7 @@ fn reject(
|
|||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
let input_cols = get_input_cols(input_vals.clone());
|
let input_cols = get_input_cols(input_vals.clone());
|
||||||
let kc = get_keep_columns(input_cols, columns);
|
let kc = get_keep_columns(input_cols, columns);
|
||||||
keep_columns = get_cellpath_columns(kc);
|
keep_columns = get_cellpath_columns(kc, span);
|
||||||
|
|
||||||
for input_val in input_vals {
|
for input_val in input_vals {
|
||||||
let mut cols = vec![];
|
let mut cols = vec![];
|
||||||
@ -88,7 +88,7 @@ fn reject(
|
|||||||
let v: Vec<_> = stream.into_iter().collect();
|
let v: Vec<_> = stream.into_iter().collect();
|
||||||
let input_cols = get_input_cols(v.clone());
|
let input_cols = get_input_cols(v.clone());
|
||||||
let kc = get_keep_columns(input_cols, columns);
|
let kc = get_keep_columns(input_cols, columns);
|
||||||
keep_columns = get_cellpath_columns(kc);
|
keep_columns = get_cellpath_columns(kc, span);
|
||||||
|
|
||||||
for input_val in v {
|
for input_val in v {
|
||||||
let mut cols = vec![];
|
let mut cols = vec![];
|
||||||
@ -130,10 +130,9 @@ fn get_input_cols(input: Vec<Value>) -> Vec<String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cellpath_columns(keep_cols: Vec<String>) -> Vec<CellPath> {
|
fn get_cellpath_columns(keep_cols: Vec<String>, span: Span) -> Vec<CellPath> {
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
for keep_col in keep_cols {
|
for keep_col in keep_cols {
|
||||||
let span = Span::unknown();
|
|
||||||
let val = Value::String {
|
let val = Value::String {
|
||||||
val: keep_col,
|
val: keep_col,
|
||||||
span,
|
span,
|
||||||
|
@ -32,7 +32,7 @@ impl Command for Reverse {
|
|||||||
Value::test_int(1),
|
Value::test_int(1),
|
||||||
Value::test_int(0),
|
Value::test_int(0),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -184,9 +184,9 @@ fn select(
|
|||||||
// let actual = select(
|
// let actual = select(
|
||||||
// Tag::unknown(),
|
// Tag::unknown(),
|
||||||
// vec![
|
// vec![
|
||||||
// ColumnPath::build(&"col_none".to_string().spanned(Span::unknown())),
|
// ColumnPath::build(&"col_none".to_string().spanned(Span::test_data())),
|
||||||
// ColumnPath::build(&"col_foo".to_string().spanned(Span::unknown())),
|
// ColumnPath::build(&"col_foo".to_string().spanned(Span::test_data())),
|
||||||
// ColumnPath::build(&"col_bar".to_string().spanned(Span::unknown())),
|
// ColumnPath::build(&"col_bar".to_string().spanned(Span::test_data())),
|
||||||
// ],
|
// ],
|
||||||
// input.into(),
|
// input.into(),
|
||||||
// );
|
// );
|
||||||
|
@ -34,18 +34,18 @@ impl Command for Skip {
|
|||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::Record {
|
vals: vec![Value::Record {
|
||||||
cols: vec!["editions".to_owned()],
|
cols: vec!["editions".to_owned()],
|
||||||
vals: vec![Value::from(2021)],
|
vals: vec![Value::test_int(2021)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
description: "Skip the first value",
|
description: "Skip the first value",
|
||||||
example: "echo [2 4 6 8] | skip",
|
example: "echo [2 4 6 8] | skip",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::from(4), Value::from(6), Value::from(8)],
|
vals: vec![Value::test_int(4), Value::test_int(6), Value::test_int(8)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -33,8 +33,8 @@ impl Command for SkipUntil {
|
|||||||
description: "Skip until the element is positive",
|
description: "Skip until the element is positive",
|
||||||
example: "echo [-2 0 2 -1] | skip until $it > 0",
|
example: "echo [-2 0 2 -1] | skip until $it > 0",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::from(2), Value::from(-1)],
|
vals: vec![Value::test_int(2), Value::test_int(-1)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,8 @@ impl Command for SkipWhile {
|
|||||||
description: "Skip while the element is negative",
|
description: "Skip while the element is negative",
|
||||||
example: "echo [-2 0 2 -1] | skip while $it < 0",
|
example: "echo [-2 0 2 -1] | skip while $it < 0",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::from(0), Value::from(2), Value::from(-1)],
|
vals: vec![Value::test_int(0), Value::test_int(2), Value::test_int(-1)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ impl Command for Uniq {
|
|||||||
example: "[2 3 3 4] | uniq",
|
example: "[2 3 3 4] | uniq",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_int(2), Value::test_int(3), Value::test_int(4)],
|
vals: vec![Value::test_int(2), Value::test_int(3), Value::test_int(4)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -70,7 +70,7 @@ impl Command for Uniq {
|
|||||||
example: "['hello' 'goodbye' 'Hello'] | uniq -i",
|
example: "['hello' 'goodbye' 'Hello'] | uniq -i",
|
||||||
result: Some(Value::List {
|
result: Some(Value::List {
|
||||||
vals: vec![Value::test_string("hello"), Value::test_string("goodbye")],
|
vals: vec![Value::test_string("hello"), Value::test_string("goodbye")],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -81,15 +81,15 @@ impl Command for Uniq {
|
|||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["value".to_string(), "count".to_string()],
|
cols: vec!["value".to_string(), "count".to_string()],
|
||||||
vals: vec![Value::test_int(1), Value::test_int(1)],
|
vals: vec![Value::test_int(1), Value::test_int(1)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["value".to_string(), "count".to_string()],
|
cols: vec!["value".to_string(), "count".to_string()],
|
||||||
vals: vec![Value::test_int(2), Value::test_int(2)],
|
vals: vec![Value::test_int(2), Value::test_int(2)],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -47,11 +47,11 @@ impl Command for Update {
|
|||||||
vec![Example {
|
vec![Example {
|
||||||
description: "Update a column value",
|
description: "Update a column value",
|
||||||
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
|
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
|
||||||
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::unknown()}),
|
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::test_data()}),
|
||||||
}, Example {
|
}, Example {
|
||||||
description: "Use in block form for more involved updating logic",
|
description: "Use in block form for more involved updating logic",
|
||||||
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { get authors | str collect ',' }",
|
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { get authors | str collect ',' }",
|
||||||
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["project".into(), "authors".into()], vals: vec![Value::test_string("nu"), Value::test_string("Andrés,JT,Yehuda")], span: Span::unknown()}], span: Span::unknown()}),
|
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["project".into(), "authors".into()], vals: vec![Value::test_string("nu"), Value::test_string("Andrés,JT,Yehuda")], span: Span::test_data()}], span: Span::test_data()}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,22 +70,22 @@ Test' | from eml",
|
|||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::nothing(Span::unknown()),
|
Value::nothing(Span::test_data()),
|
||||||
Value::test_string("test@email.com"),
|
Value::test_string("test@email.com"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::nothing(Span::unknown()),
|
Value::nothing(Span::test_data()),
|
||||||
Value::test_string("someone@somewhere.com"),
|
Value::test_string("someone@somewhere.com"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::test_string("Test"),
|
Value::test_string("Test"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -107,22 +107,22 @@ Test' | from eml -b 1",
|
|||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::nothing(Span::unknown()),
|
Value::nothing(Span::test_data()),
|
||||||
Value::test_string("test@email.com"),
|
Value::test_string("test@email.com"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Record {
|
Value::Record {
|
||||||
cols: vec!["Name".to_string(), "Address".to_string()],
|
cols: vec!["Name".to_string(), "Address".to_string()],
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::nothing(Span::unknown()),
|
Value::nothing(Span::test_data()),
|
||||||
Value::test_string("someone@somewhere.com"),
|
Value::test_string("someone@somewhere.com"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::test_string("T"),
|
Value::test_string("T"),
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -57,36 +57,36 @@ END:VCALENDAR' | from ics",
|
|||||||
vals: vec![
|
vals: vec![
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![],
|
vals: vec![],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -34,16 +34,16 @@ b=2' | from ini",
|
|||||||
vals: vec![
|
vals: vec![
|
||||||
Value::String {
|
Value::String {
|
||||||
val: "1".to_string(),
|
val: "1".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::String {
|
Value::String {
|
||||||
val: "2".to_string(),
|
val: "2".to_string(),
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,9 @@ impl Command for FromJson {
|
|||||||
cols: vec!["a".to_string()],
|
cols: vec!["a".to_string()],
|
||||||
vals: vec![Value::Int {
|
vals: vec![Value::Int {
|
||||||
val: 1,
|
val: 1,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}],
|
}],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
Example {
|
Example {
|
||||||
@ -45,23 +45,23 @@ impl Command for FromJson {
|
|||||||
vals: vec![
|
vals: vec![
|
||||||
Value::Int {
|
Value::Int {
|
||||||
val: 1,
|
val: 1,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::List {
|
Value::List {
|
||||||
vals: vec![
|
vals: vec![
|
||||||
Value::Int {
|
Value::Int {
|
||||||
val: 1,
|
val: 1,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
Value::Int {
|
Value::Int {
|
||||||
val: 2,
|
val: 2,
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
span: Span::unknown(),
|
span: Span::test_data(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -43,7 +43,7 @@ impl Command for FromOds {
|
|||||||
let sel_sheets = if let Some(Value::List { vals: columns, .. }) =
|
let sel_sheets = if let Some(Value::List { vals: columns, .. }) =
|
||||||
call.get_flag(engine_state, stack, "sheets")?
|
call.get_flag(engine_state, stack, "sheets")?
|
||||||
{
|
{
|
||||||
convert_columns(columns.as_slice())?
|
convert_columns(columns.as_slice(), call.head)?
|
||||||
} else {
|
} else {
|
||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
@ -67,14 +67,14 @@ impl Command for FromOds {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_columns(columns: &[Value]) -> Result<Vec<String>, ShellError> {
|
fn convert_columns(columns: &[Value], span: Span) -> Result<Vec<String>, ShellError> {
|
||||||
let res = columns
|
let res = columns
|
||||||
.iter()
|
.iter()
|
||||||
.map(|value| match &value {
|
.map(|value| match &value {
|
||||||
Value::String { val: s, .. } => Ok(s.clone()),
|
Value::String { val: s, .. } => Ok(s.clone()),
|
||||||
_ => Err(ShellError::IncompatibleParametersSingle(
|
_ => Err(ShellError::IncompatibleParametersSingle(
|
||||||
"Incorrect column format, Only string as column name".to_string(),
|
"Incorrect column format, Only string as column name".to_string(),
|
||||||
value.span().unwrap_or_else(|_| Span::unknown()),
|
value.span().unwrap_or(span),
|
||||||
)),
|
)),
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<String>, _>>()?;
|
.collect::<Result<Vec<String>, _>>()?;
|
||||||
@ -82,7 +82,7 @@ fn convert_columns(columns: &[Value]) -> Result<Vec<String>, ShellError> {
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_binary(input: PipelineData) -> Result<Vec<u8>, ShellError> {
|
fn collect_binary(input: PipelineData, span: Span) -> Result<Vec<u8>, ShellError> {
|
||||||
let mut bytes = vec![];
|
let mut bytes = vec![];
|
||||||
let mut values = input.into_iter();
|
let mut values = input.into_iter();
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ fn collect_binary(input: PipelineData) -> Result<Vec<u8>, ShellError> {
|
|||||||
Some(x) => {
|
Some(x) => {
|
||||||
return Err(ShellError::UnsupportedInput(
|
return Err(ShellError::UnsupportedInput(
|
||||||
"Expected binary from pipeline".to_string(),
|
"Expected binary from pipeline".to_string(),
|
||||||
x.span().unwrap_or_else(|_| Span::unknown()),
|
x.span().unwrap_or(span),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
None => break,
|
None => break,
|
||||||
@ -109,7 +109,7 @@ fn from_ods(
|
|||||||
head: Span,
|
head: Span,
|
||||||
sel_sheets: Vec<String>,
|
sel_sheets: Vec<String>,
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let bytes = collect_binary(input)?;
|
let bytes = collect_binary(input, head)?;
|
||||||
let buf: Cursor<Vec<u8>> = Cursor::new(bytes);
|
let buf: Cursor<Vec<u8>> = Cursor::new(bytes);
|
||||||
let mut ods = Ods::<_>::new(buf)
|
let mut ods = Ods::<_>::new(buf)
|
||||||
.map_err(|_| ShellError::UnsupportedInput("Could not load ods file".to_string(), head))?;
|
.map_err(|_| ShellError::UnsupportedInput("Could not load ods file".to_string(), head))?;
|
||||||
|
@ -43,13 +43,13 @@ impl Command for FromSsv {
|
|||||||
example: r#"'FOO BAR
|
example: r#"'FOO BAR
|
||||||
1 2' | from ssv"#,
|
1 2' | from ssv"#,
|
||||||
description: "Converts ssv formatted string to table",
|
description: "Converts ssv formatted string to table",
|
||||||
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["FOO".to_string(), "BAR".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::unknown() }, Value::String { val: "2".to_string(), span: Span::unknown() }], span: Span::unknown() }], span: Span::unknown() }),
|
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["FOO".to_string(), "BAR".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::test_data() }, Value::String { val: "2".to_string(), span: Span::test_data() }], span: Span::test_data() }], span: Span::test_data() }),
|
||||||
}, Example {
|
}, Example {
|
||||||
example: r#"'FOO BAR
|
example: r#"'FOO BAR
|
||||||
1 2' | from ssv -n"#,
|
1 2' | from ssv -n"#,
|
||||||
description: "Converts ssv formatted string to table but not treating the first row as column names",
|
description: "Converts ssv formatted string to table but not treating the first row as column names",
|
||||||
result: Some(
|
result: Some(
|
||||||
Value::List { vals: vec![Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "FOO".to_string(), span: Span::unknown() }, Value::String { val: "BAR".to_string(), span: Span::unknown() }], span: Span::unknown() }, Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::unknown() }, Value::String { val: "2".to_string(), span: Span::unknown() }], span: Span::unknown() }], span: Span::unknown() }),
|
Value::List { vals: vec![Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "FOO".to_string(), span: Span::test_data() }, Value::String { val: "BAR".to_string(), span: Span::test_data() }], span: Span::test_data() }, Value::Record { cols: vec!["Column1".to_string(), "Column2".to_string()], vals: vec![Value::String { val: "1".to_string(), span: Span::test_data() }, Value::String { val: "2".to_string(), span: Span::test_data() }], span: Span::test_data() }], span: Span::test_data() }),
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user