Remove dfr from dataframe commands (#5760)

* input and output tests

* input and output types for dfr

* expression converter

* remove deprecated command

* correct expressions

* cargo clippy

* identifier for ls

* cargo clippy

* type for head and tail expression

* modify full cell path if block
This commit is contained in:
Fernando Herrera 2022-06-12 14:18:00 -05:00 committed by GitHub
parent 2dea9e6f1f
commit 11d7d8ea1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
105 changed files with 2646 additions and 1361 deletions

View File

@ -87,7 +87,7 @@ impl NuHelpCompleter {
let extra: Vec<String> = examples let extra: Vec<String> = examples
.iter() .iter()
.map(|example| example.example.to_string()) .map(|example| example.example.replace('\n', "\r\n"))
.collect(); .collect();
Suggestion { Suggestion {

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use super::super::values::{Axis, Column, NuDataFrame}; use super::super::values::{Axis, Column, NuDataFrame};
@ -12,7 +12,7 @@ pub struct AppendDF;
impl Command for AppendDF { impl Command for AppendDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr append" "append"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -30,8 +30,8 @@ impl Command for AppendDF {
vec![ vec![
Example { Example {
description: "Appends a dataframe as new columns", description: "Appends a dataframe as new columns",
example: r#"let a = ([[a b]; [1 2] [3 4]] | dfr to-df); example: r#"let a = ([[a b]; [1 2] [3 4]] | to-df);
$a | dfr append $a"#, $a | append $a"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -57,8 +57,8 @@ impl Command for AppendDF {
}, },
Example { Example {
description: "Appends a dataframe merging at the end of columns", description: "Appends a dataframe merging at the end of columns",
example: r#"let a = ([[a b]; [1 2] [3 4]] | dfr to-df); example: r#"let a = ([[a b]; [1 2] [3 4]] | to-df);
$a | dfr append $a --col"#, $a | append $a --col"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -87,6 +87,14 @@ impl Command for AppendDF {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,87 +0,0 @@
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Value,
};
use super::super::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct ColumnDF;
impl Command for ColumnDF {
fn name(&self) -> &str {
"dfr column"
}
fn usage(&self) -> &str {
"Returns the selected column"
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.required("column", SyntaxShape::String, "column name")
.category(Category::Custom("dataframe".into()))
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns the selected column as series",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr column a",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(3)],
)])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
}]
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
command(engine_state, stack, call, input)
}
}
fn command(
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let column: Spanned<String> = call.req(engine_state, stack, 0)?;
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let res = df.as_ref().column(&column.item).map_err(|e| {
ShellError::GenericError(
"Error selecting column".into(),
e.to_string(),
Some(column.span),
None,
Vec::new(),
)
})?;
NuDataFrame::try_from_series(vec![res.clone()], call.head)
.map(|df| PipelineData::Value(NuDataFrame::into_value(df, call.head), None))
}
#[cfg(test)]
mod test {
use super::super::super::test_dataframe::test_dataframe;
use super::*;
#[test]
fn test_examples() {
test_dataframe(vec![Box::new(ColumnDF {})])
}
}

View File

@ -1,42 +0,0 @@
use nu_engine::get_full_help;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, IntoPipelineData, PipelineData, ShellError, Signature, Value,
};
#[derive(Clone)]
pub struct Dataframe;
impl Command for Dataframe {
fn name(&self) -> &str {
"dfr"
}
fn usage(&self) -> &str {
"Dataframe commands"
}
fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Custom("dataframe".into()))
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<PipelineData, ShellError> {
Ok(Value::String {
val: get_full_help(
&Dataframe.signature(),
&Dataframe.examples(),
engine_state,
stack,
),
span: call.head,
}
.into_pipeline_data())
}
}

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::{ use polars::{
chunked_array::ChunkedArray, chunked_array::ChunkedArray,
@ -19,7 +19,7 @@ pub struct DescribeDF;
impl Command for DescribeDF { impl Command for DescribeDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr describe" "describe"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -40,7 +40,7 @@ impl Command for DescribeDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "dataframe description", description: "dataframe description",
example: "[[a b]; [1 1] [1 1]] | dfr to-df | dfr describe", example: "[[a b]; [1 1] [1 1]] | to-df | describe",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -95,6 +95,14 @@ impl Command for DescribeDF {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use super::super::values::utils::convert_columns; use super::super::values::utils::convert_columns;
@ -13,7 +13,7 @@ pub struct DropDF;
impl Command for DropDF { impl Command for DropDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr drop" "drop"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -29,7 +29,7 @@ impl Command for DropDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "drop column a", description: "drop column a",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr drop a", example: "[[a b]; [1 2] [3 4]] | to-df | drop a",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"b".to_string(), "b".to_string(),
@ -41,6 +41,14 @@ impl Command for DropDF {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::UniqueKeepStrategy; use polars::prelude::UniqueKeepStrategy;
@ -14,7 +14,7 @@ pub struct DropDuplicates;
impl Command for DropDuplicates { impl Command for DropDuplicates {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr drop-duplicates" "drop-duplicates"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -40,7 +40,7 @@ impl Command for DropDuplicates {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "drop duplicates", description: "drop duplicates",
example: "[[a b]; [1 2] [3 4] [1 2]] | dfr to-df | dfr drop-duplicates", example: "[[a b]; [1 2] [3 4] [1 2]] | to-df | drop-duplicates",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -58,6 +58,14 @@ impl Command for DropDuplicates {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use super::super::values::utils::convert_columns_string; use super::super::values::utils::convert_columns_string;
@ -13,7 +13,7 @@ pub struct DropNulls;
impl Command for DropNulls { impl Command for DropNulls {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr drop-nulls" "drop-nulls"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -34,10 +34,10 @@ impl Command for DropNulls {
vec![ vec![
Example { Example {
description: "drop null values in dataframe", description: "drop null values in dataframe",
example: r#"let df = ([[a b]; [1 2] [3 0] [1 2]] | dfr to-df); example: r#"let df = ([[a b]; [1 2] [3 0] [1 2]] | to-df);
let res = ($df.b / $df.b); let res = ($df.b / $df.b);
let a = ($df | dfr with-column $res --name res); let a = ($df | with-column $res --name res);
$a | dfr drop-nulls"#, $a | drop-nulls"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -59,8 +59,8 @@ impl Command for DropNulls {
}, },
Example { Example {
description: "drop null values in dataframe", description: "drop null values in dataframe",
example: r#"let s = ([1 2 0 0 3 4] | dfr to-df); example: r#"let s = ([1 2 0 0 3 4] | to-df);
($s / $s) | dfr drop-nulls"#, ($s / $s) | drop-nulls"#,
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(),
@ -78,6 +78,14 @@ impl Command for DropNulls {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -2,7 +2,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -10,7 +10,7 @@ pub struct DataTypes;
impl Command for DataTypes { impl Command for DataTypes {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr dtypes" "dtypes"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -24,7 +24,7 @@ impl Command for DataTypes {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Dataframe dtypes", description: "Dataframe dtypes",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr dtypes", example: "[[a b]; [1 2] [3 4]] | to-df | dtypes",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -42,6 +42,14 @@ impl Command for DataTypes {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -2,7 +2,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::DataFrameOps; use polars::prelude::DataFrameOps;
@ -11,7 +11,7 @@ pub struct Dummies;
impl Command for Dummies { impl Command for Dummies {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-dummies" "to-dummies"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for Dummies {
vec![ vec![
Example { Example {
description: "Create new dataframe with dummy variables from a dataframe", description: "Create new dataframe with dummy variables from a dataframe",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr to-dummies", example: "[[a b]; [1 2] [3 4]] | to-df | to-dummies",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -52,7 +52,7 @@ impl Command for Dummies {
}, },
Example { Example {
description: "Create new dataframe with dummy variables from a series", description: "Create new dataframe with dummy variables from a series",
example: "[1 2 2 3 3] | dfr to-df | dfr to-dummies", example: "[1 2 2 3 3] | to-df | to-dummies",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -93,6 +93,14 @@ impl Command for Dummies {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::LazyFrame; use polars::prelude::LazyFrame;
@ -15,7 +15,7 @@ pub struct FilterWith;
impl Command for FilterWith { impl Command for FilterWith {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr filter-with" "filter-with"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -36,8 +36,8 @@ impl Command for FilterWith {
vec![ vec![
Example { Example {
description: "Filter dataframe using a bool mask", description: "Filter dataframe using a bool mask",
example: r#"let mask = ([true false] | dfr to-df); example: r#"let mask = ([true false] | to-df);
[[a b]; [1 2] [3 4]] | dfr to-df | dfr filter-with $mask"#, [[a b]; [1 2] [3 4]] | to-df | filter-with $mask"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![Value::test_int(1)]), Column::new("a".to_string(), vec![Value::test_int(1)]),
@ -49,7 +49,7 @@ impl Command for FilterWith {
}, },
Example { Example {
description: "Filter dataframe using an expression", description: "Filter dataframe using an expression",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr filter-with ((dfr col a) > 1)", example: "[[a b]; [1 2] [3 4]] | to-df | filter-with ((col a) > 1)",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![Value::test_int(3)]), Column::new("a".to_string(), vec![Value::test_int(3)]),
@ -62,6 +62,14 @@ impl Command for FilterWith {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,
@ -74,16 +82,9 @@ impl Command for FilterWith {
if NuLazyFrame::can_downcast(&value) { if NuLazyFrame::can_downcast(&value) {
let df = NuLazyFrame::try_from_value(value)?; let df = NuLazyFrame::try_from_value(value)?;
command_lazy(engine_state, stack, call, df) command_lazy(engine_state, stack, call, df)
} else if NuDataFrame::can_downcast(&value) { } else {
let df = NuDataFrame::try_from_value(value)?; let df = NuDataFrame::try_from_value(value)?;
command_eager(engine_state, stack, call, df) command_eager(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
} }
} }
} }

View File

@ -1,10 +1,9 @@
use super::super::values::{utils::DEFAULT_ROWS, Column, NuDataFrame}; use super::super::values::{utils::DEFAULT_ROWS, Column, NuDataFrame};
use crate::dataframe::values::NuExpression;
use nu_engine::CallExt; 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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,39 +11,40 @@ pub struct FirstDF;
impl Command for FirstDF { impl Command for FirstDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr first" "first"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Creates new dataframe with first rows or creates a first expression" "Creates new dataframe with first rows"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()) Signature::build(self.name())
.optional("rows", SyntaxShape::Int, "Number of rows for head") .optional("rows", SyntaxShape::Int, "Number of rows for head")
.category(Category::Custom("dataframe or expression".into())) .category(Category::Custom("dataframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "Create new dataframe with head rows",
description: "Create new dataframe with head rows", example: "[[a b]; [1 2] [3 4]] | to-df | first 1",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr first 1", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_int(1)]),
Column::new("a".to_string(), vec![Value::test_int(1)]), Column::new("b".to_string(), vec![Value::test_int(2)]),
Column::new("b".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::test_data()),
.into_value(Span::test_data()), ),
), }]
}, }
Example {
description: "Creates a first expression from a column", fn input_type(&self) -> Type {
example: "dfr col a | dfr first", Type::Custom("dataframe".into())
result: None, }
},
] fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
} }
fn run( fn run(
@ -54,27 +54,8 @@ impl Command for FirstDF {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head); let df = NuDataFrame::try_from_pipeline(input, call.head)?;
command(engine_state, stack, call, df)
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().is_null().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else if NuDataFrame::can_downcast(&value) {
let df = NuDataFrame::try_from_value(value)?;
command(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
}
} }
} }

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use crate::dataframe::values::utils::convert_columns_string; use crate::dataframe::values::utils::convert_columns_string;
@ -14,7 +14,7 @@ pub struct GetDF;
impl Command for GetDF { impl Command for GetDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get" "get"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -29,8 +29,8 @@ impl Command for GetDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Creates dataframe with selected columns", description: "Returns the selected column",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr get a", example: "[[a b]; [1 2] [3 4]] | to-df | get a",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"a".to_string(), "a".to_string(),
@ -42,6 +42,14 @@ impl Command for GetDF {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,10 +1,9 @@
use super::super::values::{utils::DEFAULT_ROWS, Column, NuDataFrame}; use super::super::values::{utils::DEFAULT_ROWS, Column, NuDataFrame};
use crate::dataframe::values::NuExpression;
use nu_engine::CallExt; 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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +11,7 @@ pub struct LastDF;
impl Command for LastDF { impl Command for LastDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr last" "last"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -22,29 +21,30 @@ impl Command for LastDF {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()) Signature::build(self.name())
.optional("rows", SyntaxShape::Int, "Number of rows for tail") .optional("rows", SyntaxShape::Int, "Number of rows for tail")
.category(Category::Custom("dataframe or lazyframe".into())) .category(Category::Custom("dataframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "Create new dataframe with last rows",
description: "Create new dataframe with last rows", example: "[[a b]; [1 2] [3 4]] | to-df | last 1",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr last 1", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_int(3)]),
Column::new("a".to_string(), vec![Value::test_int(3)]), Column::new("b".to_string(), vec![Value::test_int(4)]),
Column::new("b".to_string(), vec![Value::test_int(4)]), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), }]
}, }
Example {
description: "Creates a last expression from a column", fn input_type(&self) -> Type {
example: "dfr col a | dfr last", Type::Custom("dataframe".into())
result: None, }
},
] fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
} }
fn run( fn run(
@ -54,27 +54,8 @@ impl Command for LastDF {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head); let df = NuDataFrame::try_from_pipeline(input, call.head)?;
command(engine_state, stack, call, df)
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().is_null().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else if NuDataFrame::can_downcast(&value) {
let df = NuDataFrame::try_from_value(value)?;
command(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
}
} }
} }

View File

@ -11,7 +11,7 @@ pub struct ListDF;
impl Command for ListDF { impl Command for ListDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr ls" "ls-df"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -25,8 +25,8 @@ impl Command for ListDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Creates a new dataframe and shows it in the dataframe list", description: "Creates a new dataframe and shows it in the dataframe list",
example: r#"let test = ([[a b];[1 2] [3 4]] | dfr to-df); example: r#"let test = ([[a b];[1 2] [3 4]] | to-df);
dfr ls"#, ls-df"#,
result: None, result: None,
}] }]
} }

View File

@ -2,7 +2,8 @@ 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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
Value,
}; };
use crate::dataframe::values::utils::convert_columns_string; use crate::dataframe::values::utils::convert_columns_string;
@ -14,7 +15,7 @@ pub struct MeltDF;
impl Command for MeltDF { impl Command for MeltDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr melt" "melt"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -53,8 +54,7 @@ impl Command for MeltDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "melt dataframe", description: "melt dataframe",
example: example: "[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | to-df | melt -c [b c] -v [a d]",
"[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | dfr to-df | dfr melt -c [b c] -v [a d]",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -108,6 +108,14 @@ impl Command for MeltDF {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,6 +1,4 @@
mod append; mod append;
mod column;
mod command;
mod describe; mod describe;
mod drop; mod drop;
mod drop_duplicates; mod drop_duplicates;
@ -28,8 +26,6 @@ mod with_column;
use nu_protocol::engine::StateWorkingSet; use nu_protocol::engine::StateWorkingSet;
pub use append::AppendDF; pub use append::AppendDF;
pub use column::ColumnDF;
pub use command::Dataframe;
pub use describe::DescribeDF; pub use describe::DescribeDF;
pub use drop::DropDF; pub use drop::DropDF;
pub use drop_duplicates::DropDuplicates; pub use drop_duplicates::DropDuplicates;
@ -67,8 +63,6 @@ pub fn add_eager_decls(working_set: &mut StateWorkingSet) {
// Dataframe commands // Dataframe commands
bind_command!( bind_command!(
AppendDF, AppendDF,
ColumnDF,
Dataframe,
DataTypes, DataTypes,
DescribeDF, DescribeDF,
DropDF, DropDF,

View File

@ -3,7 +3,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, Spanned, SyntaxShape, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
}; };
use std::{fs::File, io::BufReader, path::PathBuf}; use std::{fs::File, io::BufReader, path::PathBuf};
@ -15,7 +15,7 @@ pub struct OpenDataFrame;
impl Command for OpenDataFrame { impl Command for OpenDataFrame {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr open" "open-df"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -64,11 +64,19 @@ impl Command for OpenDataFrame {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Takes a file name and creates a dataframe", description: "Takes a file name and creates a dataframe",
example: "dfr open test.csv", example: "open test.csv",
result: None, result: None,
}] }]
} }
fn input_type(&self) -> Type {
Type::Any
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use crate::dataframe::{utils::extract_strings, values::NuLazyFrame}; use crate::dataframe::{utils::extract_strings, values::NuLazyFrame};
@ -14,7 +14,7 @@ pub struct RenameDF;
impl Command for RenameDF { impl Command for RenameDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr rename" "rename"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -40,7 +40,7 @@ impl Command for RenameDF {
vec![ vec![
Example { Example {
description: "Renames a series", description: "Renames a series",
example: "[5 6 7 8] | dfr to-df | dfr rename '0' new_name", example: "[5 6 7 8] | to-df | rename '0' new_name",
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(),
@ -57,7 +57,7 @@ impl Command for RenameDF {
}, },
Example { Example {
description: "Renames a dataframe column", description: "Renames a dataframe column",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr rename a a_new", example: "[[a b]; [1 2] [3 4]] | to-df | rename a a_new",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -75,7 +75,7 @@ impl Command for RenameDF {
}, },
Example { Example {
description: "Renames two dataframe columns", description: "Renames two dataframe columns",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr rename [a b] [a_new b_new]", example: "[[a b]; [1 2] [3 4]] | to-df | rename [a b] [a_new b_new]",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -94,6 +94,14 @@ impl Command for RenameDF {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,
@ -106,16 +114,9 @@ impl Command for RenameDF {
if NuLazyFrame::can_downcast(&value) { if NuLazyFrame::can_downcast(&value) {
let df = NuLazyFrame::try_from_value(value)?; let df = NuLazyFrame::try_from_value(value)?;
command_lazy(engine_state, stack, call, df) command_lazy(engine_state, stack, call, df)
} else if NuDataFrame::can_downcast(&value) { } else {
let df = NuDataFrame::try_from_value(value)?; let df = NuDataFrame::try_from_value(value)?;
command_eager(engine_state, stack, call, df) command_eager(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
} }
} }
} }

View File

@ -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, Spanned, SyntaxShape, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
}; };
use super::super::values::NuDataFrame; use super::super::values::NuDataFrame;
@ -12,7 +12,7 @@ pub struct SampleDF;
impl Command for SampleDF { impl Command for SampleDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr sample" "sample"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -47,17 +47,25 @@ impl Command for SampleDF {
vec![ vec![
Example { Example {
description: "Sample rows from dataframe", description: "Sample rows from dataframe",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr sample -n 1", example: "[[a b]; [1 2] [3 4]] | to-df | sample -n 1",
result: None, // No expected value because sampling is random result: None, // No expected value because sampling is random
}, },
Example { Example {
description: "Shows sample row using fraction and replace", description: "Shows sample row using fraction and replace",
example: "[[a b]; [1 2] [3 4] [5 6]] | dfr to-df | dfr sample -f 0.5 -e", example: "[[a b]; [1 2] [3 4] [5 6]] | to-df | sample -f 0.5 -e",
result: None, // No expected value because sampling is random result: None, // No expected value because sampling is random
}, },
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,7 +1,7 @@
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use crate::dataframe::values::Column; use crate::dataframe::values::Column;
@ -13,7 +13,7 @@ pub struct ShapeDF;
impl Command for ShapeDF { impl Command for ShapeDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr shape" "shape"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,7 +27,7 @@ impl Command for ShapeDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Shows row and column shape", description: "Shows row and column shape",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr shape", example: "[[a b]; [1 2] [3 4]] | to-df | shape",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new("rows".to_string(), vec![Value::test_int(2)]), Column::new("rows".to_string(), vec![Value::test_int(2)]),
@ -39,6 +39,14 @@ impl Command for ShapeDF {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use crate::dataframe::values::Column; use crate::dataframe::values::Column;
@ -14,7 +14,7 @@ pub struct SliceDF;
impl Command for SliceDF { impl Command for SliceDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr slice" "slice"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -31,7 +31,7 @@ impl Command for SliceDF {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Create new dataframe from a slice of the rows", description: "Create new dataframe from a slice of the rows",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr slice 0 1", example: "[[a b]; [1 2] [3 4]] | to-df | slice 0 1",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![Value::test_int(1)]), Column::new("a".to_string(), vec![Value::test_int(1)]),
@ -43,6 +43,14 @@ impl Command for SliceDF {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::DataType; use polars::prelude::DataType;
@ -15,7 +15,7 @@ pub struct TakeDF;
impl Command for TakeDF { impl Command for TakeDF {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr take" "take"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -36,9 +36,9 @@ impl Command for TakeDF {
vec![ vec![
Example { Example {
description: "Takes selected rows from dataframe", description: "Takes selected rows from dataframe",
example: r#"let df = ([[a b]; [4 1] [5 2] [4 3]] | dfr to-df); example: r#"let df = ([[a b]; [4 1] [5 2] [4 3]] | to-df);
let indices = ([0 2] | dfr to-df); let indices = ([0 2] | to-df);
$df | dfr take $indices"#, $df | take $indices"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -56,9 +56,9 @@ impl Command for TakeDF {
}, },
Example { Example {
description: "Takes selected rows from series", description: "Takes selected rows from series",
example: r#"let series = ([4 1 5 2 4 3] | dfr to-df); example: r#"let series = ([4 1 5 2 4 3] | to-df);
let indices = ([0 2] | dfr to-df); let indices = ([0 2] | to-df);
$series | dfr take $indices"#, $series | take $indices"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -71,6 +71,14 @@ impl Command for TakeDF {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
}; };
use polars::prelude::{CsvWriter, SerWriter}; use polars::prelude::{CsvWriter, SerWriter};
@ -15,7 +15,7 @@ pub struct ToCSV;
impl Command for ToCSV { impl Command for ToCSV {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-csv" "to-csv"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -39,17 +39,25 @@ impl Command for ToCSV {
vec![ vec![
Example { Example {
description: "Saves dataframe to csv file", description: "Saves dataframe to csv file",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr to-csv test.csv", example: "[[a b]; [1 2] [3 4]] | to-df | to-csv test.csv",
result: None, result: None,
}, },
Example { Example {
description: "Saves dataframe to csv file using other delimiter", description: "Saves dataframe to csv file using other delimiter",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr to-csv test.csv -d '|'", example: "[[a b]; [1 2] [3 4]] | to-df | to-csv test.csv -d '|'",
result: None, result: None,
}, },
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Any
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct ToDataFrame;
impl Command for ToDataFrame { impl Command for ToDataFrame {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-df" "to-df"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ToDataFrame {
vec![ vec![
Example { Example {
description: "Takes a dictionary and creates a dataframe", description: "Takes a dictionary and creates a dataframe",
example: "[[a b];[1 2] [3 4]] | dfr to-df", example: "[[a b];[1 2] [3 4]] | to-df",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -44,7 +44,7 @@ impl Command for ToDataFrame {
}, },
Example { Example {
description: "Takes a list of tables and creates a dataframe", description: "Takes a list of tables and creates a dataframe",
example: "[[1 2 a] [3 4 b] [5 6 c]] | dfr to-df", example: "[[1 2 a] [3 4 b] [5 6 c]] | to-df",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -70,7 +70,7 @@ impl Command for ToDataFrame {
}, },
Example { Example {
description: "Takes a list and creates a dataframe", description: "Takes a list and creates a dataframe",
example: "[a b c] | dfr to-df", example: "[a b c] | to-df",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -86,7 +86,7 @@ impl Command for ToDataFrame {
}, },
Example { Example {
description: "Takes a list of booleans and creates a dataframe", description: "Takes a list of booleans and creates a dataframe",
example: "[true true false] | dfr to-df", example: "[true true false] | to-df",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -103,6 +103,14 @@ impl Command for ToDataFrame {
] ]
} }
fn input_type(&self) -> Type {
Type::Any
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
}; };
use super::super::values::NuDataFrame; use super::super::values::NuDataFrame;
@ -12,7 +12,7 @@ pub struct ToNu;
impl Command for ToNu { impl Command for ToNu {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-nu" "to-nu"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -22,7 +22,7 @@ impl Command for ToNu {
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()) Signature::build(self.name())
.named( .named(
"n-rows", "rows",
SyntaxShape::Number, SyntaxShape::Number,
"number of rows to be shown", "number of rows to be shown",
Some('n'), Some('n'),
@ -35,17 +35,25 @@ impl Command for ToNu {
vec![ vec![
Example { Example {
description: "Shows head rows from dataframe", description: "Shows head rows from dataframe",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr to-nu", example: "[[a b]; [1 2] [3 4]] | to-df | to nu",
result: None, result: None,
}, },
Example { Example {
description: "Shows tail rows from dataframe", description: "Shows tail rows from dataframe",
example: "[[a b]; [1 2] [3 4] [5 6]] | dfr to-df | dfr to-nu -t -n 1", example: "[[a b]; [1 2] [3 4] [5 6]] | to-df | to nu -t -n 1",
result: None, result: None,
}, },
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Any
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Spanned, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type, Value,
}; };
use polars::prelude::ParquetWriter; use polars::prelude::ParquetWriter;
@ -15,7 +15,7 @@ pub struct ToParquet;
impl Command for ToParquet { impl Command for ToParquet {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-parquet" "to-parquet"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -30,12 +30,20 @@ impl Command for ToParquet {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Saves dataframe to csv file", description: "Saves dataframe to parquet file",
example: "[[a b]; [1 2] [3 4]] | dfr to-df | dfr to-parquet test.parquet", example: "[[a b]; [1 2] [3 4]] | to-df | to-parquet test.parquet",
result: None, result: None,
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Any
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,7 @@ pub struct WithColumn;
impl Command for WithColumn { impl Command for WithColumn {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr with-column" "with-column"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -35,8 +35,8 @@ impl Command for WithColumn {
Example { Example {
description: "Adds a series to the dataframe", description: "Adds a series to the dataframe",
example: r#"[[a b]; [1 2] [3 4]] example: r#"[[a b]; [1 2] [3 4]]
| dfr to-df | to-df
| dfr with-column ([5 6] | dfr to-df) --name c"#, | with-column ([5 6] | to-df) --name c"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -59,12 +59,12 @@ impl Command for WithColumn {
Example { Example {
description: "Adds a series to the dataframe", description: "Adds a series to the dataframe",
example: r#"[[a b]; [1 2] [3 4]] example: r#"[[a b]; [1 2] [3 4]]
| dfr to-lazy | to-lazy
| dfr with-column [ | with-column [
((dfr col a) * 2 | dfr as "c") ((col a) * 2 | as "c")
((dfr col a) * 3 | dfr as "d") ((col a) * 3 | as "d")
] ]
| dfr collect"#, | collect"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -91,6 +91,14 @@ impl Command for WithColumn {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,7 @@ pub struct ExprAlias;
impl Command for ExprAlias { impl Command for ExprAlias {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr as" "as"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -32,7 +32,7 @@ impl Command for ExprAlias {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Creates and alias expression", description: "Creates and alias expression",
example: "dfr col a | dfr as new_a | dfr as-nu", example: "col a | as new_a | to-nu",
result: { result: {
let cols = vec!["expr".into(), "value".into()]; let cols = vec!["expr".into(), "value".into()];
let expr = Value::test_string("column"); let expr = Value::test_string("column");
@ -57,6 +57,14 @@ impl Command for ExprAlias {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("expression".into())
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -3,7 +3,7 @@ use super::super::values::NuExpression;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct ExprAsNu;
impl Command for ExprAsNu { impl Command for ExprAsNu {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr as-nu" "to-nu"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -25,7 +25,7 @@ impl Command for ExprAsNu {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Convert a col expression into a nushell value", description: "Convert a col expression into a nushell value",
example: "dfr col col_a | dfr as-nu", example: "col a | to-nu",
result: Some(Value::Record { result: Some(Value::Record {
cols: vec!["expr".into(), "value".into()], cols: vec!["expr".into(), "value".into()],
vals: vec![ vals: vec![
@ -34,7 +34,7 @@ impl Command for ExprAsNu {
span: Span::test_data(), span: Span::test_data(),
}, },
Value::String { Value::String {
val: "col_a".into(), val: "a".into(),
span: Span::test_data(), span: Span::test_data(),
}, },
], ],
@ -43,6 +43,14 @@ impl Command for ExprAsNu {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("expression".into())
}
fn output_type(&self) -> Type {
Type::Any
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::col; use polars::prelude::col;
@ -12,7 +12,7 @@ pub struct ExprCol;
impl Command for ExprCol { impl Command for ExprCol {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr col" "col"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -32,7 +32,7 @@ impl Command for ExprCol {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Creates a named column expression and converts it to a nu object", description: "Creates a named column expression and converts it to a nu object",
example: "dfr col col_a | dfr as-nu", example: "col a | to-nu",
result: Some(Value::Record { result: Some(Value::Record {
cols: vec!["expr".into(), "value".into()], cols: vec!["expr".into(), "value".into()],
vals: vec![ vals: vec![
@ -41,7 +41,7 @@ impl Command for ExprCol {
span: Span::test_data(), span: Span::test_data(),
}, },
Value::String { Value::String {
val: "col_a".into(), val: "a".into(),
span: Span::test_data(), span: Span::test_data(),
}, },
], ],
@ -50,6 +50,14 @@ impl Command for ExprCol {
}] }]
} }
fn input_type(&self) -> Type {
Type::Any
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,18 +1,17 @@
/// Definition of multiple Expression commands using a macro rule /// Definition of multiple Expression commands using a macro rule
/// All of these expressions have an identical body and only require /// All of these expressions have an identical body and only require
/// to have a change in the name, description and expression function /// to have a change in the name, description and expression function
use super::super::values::NuExpression; use crate::dataframe::values::{Column, NuDataFrame, NuExpression};
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
// The structs defined in this file are structs that form part of other commands // The structs defined in this file are structs that form part of other commands
// since they share a similar name // since they share a similar name
macro_rules! expr_command { macro_rules! expr_command {
($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident) => { ($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident, $test: ident) => {
#[derive(Clone)] #[derive(Clone)]
pub struct $command; pub struct $command;
@ -33,6 +32,14 @@ macro_rules! expr_command {
$examples $examples
} }
fn input_type(&self) -> Type {
Type::Custom("expression".into())
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,
@ -49,6 +56,23 @@ macro_rules! expr_command {
)) ))
} }
} }
#[cfg(test)]
mod $test {
use super::super::super::test_dataframe::test_dataframe;
use super::*;
use crate::dataframe::lazy::aggregate::LazyAggregate;
use crate::dataframe::lazy::groupby::ToLazyGroupBy;
#[test]
fn test_examples() {
test_dataframe(vec![
Box::new($command {}),
Box::new(LazyAggregate {}),
Box::new(ToLazyGroupBy {}),
])
}
}
}; };
} }
@ -56,68 +80,380 @@ macro_rules! expr_command {
// Expands to a command definition for a list expression // Expands to a command definition for a list expression
expr_command!( expr_command!(
ExprList, ExprList,
"dfr list", "list",
"Aggregates a group to a Series", "Aggregates a group to a Series",
vec![Example { vec![Example {
description: "", description: "",
example: "", example: "",
result: None, result: None,
}], }],
list list,
test_list
); );
// ExprAggGroups command // ExprAggGroups command
// Expands to a command definition for a agg groups expression // Expands to a command definition for a agg groups expression
expr_command!( expr_command!(
ExprAggGroups, ExprAggGroups,
"dfr agg-groups", "agg-groups",
"creates an agg_groups expression", "creates an agg_groups expression",
vec![Example { vec![Example {
description: "", description: "",
example: "", example: "",
result: None, result: None,
}], }],
agg_groups agg_groups,
test_groups
); );
// ExprFlatten command // ExprFlatten command
// Expands to a command definition for a flatten expression // Expands to a command definition for a flatten expression
expr_command!( expr_command!(
ExprFlatten, ExprFlatten,
"dfr flatten", "flatten",
"creates a flatten expression", "creates a flatten expression",
vec![Example { vec![Example {
description: "", description: "",
example: "", example: "",
result: None, result: None,
}], }],
flatten flatten,
test_flatten
); );
// ExprExplode command // ExprExplode command
// Expands to a command definition for a explode expression // Expands to a command definition for a explode expression
expr_command!( expr_command!(
ExprExplode, ExprExplode,
"dfr explode", "explode",
"creates an explode expression", "creates an explode expression",
vec![Example { vec![Example {
description: "", description: "",
example: "", example: "",
result: None, result: None,
}], }],
explode explode,
test_explode
); );
// ExprCount command // ExprCount command
// Expands to a command definition for a count expression // Expands to a command definition for a count expression
expr_command!( expr_command!(
ExprCount, ExprCount,
"dfr count", "count",
"creates a count expression", "creates a count expression",
vec![Example { vec![Example {
description: "", description: "",
example: "", example: "",
result: None, result: None,
}], }],
count count,
test_count
);
// ExprFirst command
// Expands to a command definition for a count expression
expr_command!(
ExprFirst,
"first",
"creates a first expression",
vec![Example {
description: "Creates a first expression from a column",
example: "col a | first",
result: None,
},],
first,
test_first
);
// ExprLast command
// Expands to a command definition for a count expression
expr_command!(
ExprLast,
"last",
"creates a last expression",
vec![Example {
description: "Creates a last expression from a column",
example: "col a | last",
result: None,
},],
last,
test_last
);
// ExprNUnique command
// Expands to a command definition for a n-unique expression
expr_command!(
ExprNUnique,
"n-unique",
"creates a n-unique expression",
vec![Example {
description: "Creates a is n-unique expression from a column",
example: "col a | n-unique",
result: None,
},],
n_unique,
test_nunique
);
// ExprIsNotNull command
// Expands to a command definition for a n-unique expression
expr_command!(
ExprIsNotNull,
"is-not-null",
"creates a is not null expression",
vec![Example {
description: "Creates a is not null expression from a column",
example: "col a | is-not-null",
result: None,
},],
is_not_null,
test_is_not_null
);
// ExprIsNull command
// Expands to a command definition for a n-unique expression
expr_command!(
ExprIsNull,
"is-null",
"creates a is null expression",
vec![Example {
description: "Creates a is null expression from a column",
example: "col a | is-null",
result: None,
},],
is_null,
test_is_null
);
// ExprNot command
// Expands to a command definition for a not expression
expr_command!(
ExprNot,
"expr-not",
"creates a not expression",
vec![Example {
description: "Creates a not expression",
example: "(col a) > 2) | expr-not",
result: None,
},],
not,
test_not
);
// ExprMax command
// Expands to a command definition for max aggregation
expr_command!(
ExprMax,
"max",
"Creates a max expression",
vec![Example {
description: "Max aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| to-df
| group-by a
| agg (col b | max)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_int(4), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
max,
test_max
);
// ExprMin command
// Expands to a command definition for min aggregation
expr_command!(
ExprMin,
"min",
"Creates a min expression",
vec![Example {
description: "Min aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| to-df
| group-by a
| agg (col b | min)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
min,
test_min
);
// ExprSum command
// Expands to a command definition for sum aggregation
expr_command!(
ExprSum,
"sum",
"Creates a sum expression for an aggregation",
vec![Example {
description: "Sum aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| to-df
| group-by a
| agg (col b | sum)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_int(6), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
sum,
test_sum
);
// ExprMean command
// Expands to a command definition for mean aggregation
expr_command!(
ExprMean,
"mean",
"Creates a mean expression for an aggregation",
vec![Example {
description: "Mean aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| to-df
| group-by a
| agg (col b | mean)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(3.0), Value::test_float(1.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
mean,
test_mean
);
// ExprMedian command
// Expands to a command definition for median aggregation
expr_command!(
ExprMedian,
"median",
"Creates a median expression for an aggregation",
vec![Example {
description: "Median aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| to-df
| group-by a
| agg (col b | median)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(3.0), Value::test_float(1.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
median,
test_median
);
// ExprStd command
// Expands to a command definition for std aggregation
expr_command!(
ExprStd,
"std",
"Creates a std expression for an aggregation",
vec![Example {
description: "Std aggregation for a group by",
example: r#"[[a b]; [one 2] [one 2] [two 1] [two 1]]
| to-df
| group-by a
| agg (col b | std)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(0.0), Value::test_float(0.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
std,
test_std
);
// ExprVar command
// Expands to a command definition for var aggregation
expr_command!(
ExprVar,
"var",
"Create a var expression for an aggregation",
vec![Example {
description: "Var aggregation for a group by",
example: r#"[[a b]; [one 2] [one 2] [two 1] [two 1]]
| to-df
| group-by a
| agg (col b | var)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(0.0), Value::test_float(0.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
var,
test_var
); );

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct ExprLit;
impl Command for ExprLit { impl Command for ExprLit {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr lit" "lit"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -31,7 +31,7 @@ impl Command for ExprLit {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Created a literal expression and converts it to a nu object", description: "Created a literal expression and converts it to a nu object",
example: "dfr lit 2 | dfr as-nu", example: "lit 2 | to-nu",
result: Some(Value::Record { result: Some(Value::Record {
cols: vec!["expr".into(), "value".into()], cols: vec!["expr".into(), "value".into()],
vals: vec![ vals: vec![
@ -49,6 +49,14 @@ impl Command for ExprLit {
}] }]
} }
fn input_type(&self) -> Type {
Type::Any
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -4,6 +4,7 @@ mod col;
mod expressions_macro; mod expressions_macro;
mod lit; mod lit;
mod otherwise; mod otherwise;
mod quantile;
mod when; mod when;
use nu_protocol::engine::StateWorkingSet; use nu_protocol::engine::StateWorkingSet;
@ -14,6 +15,7 @@ pub(super) use crate::dataframe::expressions::col::ExprCol;
pub(crate) use crate::dataframe::expressions::expressions_macro::*; pub(crate) use crate::dataframe::expressions::expressions_macro::*;
pub(super) use crate::dataframe::expressions::lit::ExprLit; pub(super) use crate::dataframe::expressions::lit::ExprLit;
pub(super) use crate::dataframe::expressions::otherwise::ExprOtherwise; pub(super) use crate::dataframe::expressions::otherwise::ExprOtherwise;
pub(super) use crate::dataframe::expressions::quantile::ExprQuantile;
pub(super) use crate::dataframe::expressions::when::ExprWhen; pub(super) use crate::dataframe::expressions::when::ExprWhen;
pub fn add_expressions(working_set: &mut StateWorkingSet) { pub fn add_expressions(working_set: &mut StateWorkingSet) {
@ -35,9 +37,24 @@ pub fn add_expressions(working_set: &mut StateWorkingSet) {
ExprAsNu, ExprAsNu,
ExprWhen, ExprWhen,
ExprOtherwise, ExprOtherwise,
ExprQuantile,
ExprList, ExprList,
ExprAggGroups, ExprAggGroups,
ExprFlatten, ExprFlatten,
ExprExplode ExprExplode,
ExprCount,
ExprFirst,
ExprLast,
ExprNUnique,
ExprIsNotNull,
ExprIsNull,
ExprNot,
ExprMax,
ExprMin,
ExprSum,
ExprMean,
ExprMedian,
ExprStd,
ExprVar
); );
} }

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct ExprOtherwise;
impl Command for ExprOtherwise { impl Command for ExprOtherwise {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr otherwise" "otherwise"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -32,26 +32,25 @@ impl Command for ExprOtherwise {
vec![ vec![
Example { Example {
description: "Create a when conditions", description: "Create a when conditions",
example: "dfr when ((dfr col a) > 2) 4 | dfr otherwise 5", example: "when ((col a) > 2) 4 | otherwise 5",
result: None, result: None,
}, },
Example { Example {
description: "Create a when conditions", description: "Create a when conditions",
example: example: "when ((col a) > 2) 4 | when ((col a) < 0) 6 | otherwise 0",
"dfr when ((dfr col a) > 2) 4 | dfr when ((dfr col a) < 0) 6 | dfr otherwise 0",
result: None, result: None,
}, },
Example { Example {
description: "Create a new column for the dataframe", description: "Create a new column for the dataframe",
example: r#"[[a b]; [6 2] [1 4] [4 1]] example: r#"[[a b]; [6 2] [1 4] [4 1]]
| dfr to-lazy | to-lazy
| dfr with-column ( | with-column (
dfr when ((dfr col a) > 2) 4 | dfr otherwise 5 | dfr as c when ((col a) > 2) 4 | otherwise 5 | as c
) )
| dfr with-column ( | with-column (
dfr when ((dfr col a) > 5) 10 | dfr when ((dfr col a) < 2) 6 | dfr otherwise 0 | dfr as d when ((col a) > 5) 10 | when ((col a) < 2) 6 | otherwise 0 | as d
) )
| dfr collect"#, | collect"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -78,6 +77,14 @@ impl Command for ExprOtherwise {
] ]
} }
fn input_type(&self) -> Type {
Type::Any
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -0,0 +1,102 @@
use crate::dataframe::values::{Column, NuDataFrame, NuExpression};
use nu_engine::CallExt;
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::QuantileInterpolOptions;
#[derive(Clone)]
pub struct ExprQuantile;
impl Command for ExprQuantile {
fn name(&self) -> &str {
"quantile"
}
fn usage(&self) -> &str {
"Aggregates the columns to the selected quantile"
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.required(
"quantile",
SyntaxShape::Number,
"quantile value for quantile operation",
)
.category(Category::Custom("expression".into()))
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Quantile aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| to-df
| group-by a
| agg (col b | quantile 0.5)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(4.0), Value::test_float(1.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
}]
}
fn input_type(&self) -> Type {
Type::Custom("expression".into())
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run(
&self,
engine_state: &EngineState,
stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head);
let quantile: f64 = call.req(engine_state, stack, 0)?;
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr
.into_polars()
.quantile(quantile, QuantileInterpolOptions::default())
.into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
}
}
#[cfg(test)]
mod test {
use super::super::super::test_dataframe::test_dataframe;
use super::*;
use crate::dataframe::lazy::aggregate::LazyAggregate;
use crate::dataframe::lazy::groupby::ToLazyGroupBy;
#[test]
fn test_examples() {
test_dataframe(vec![
Box::new(ExprQuantile {}),
Box::new(LazyAggregate {}),
Box::new(ToLazyGroupBy {}),
])
}
}

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::when; use polars::prelude::when;
@ -12,7 +12,7 @@ pub struct ExprWhen;
impl Command for ExprWhen { impl Command for ExprWhen {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr when" "when"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -38,25 +38,25 @@ impl Command for ExprWhen {
vec![ vec![
Example { Example {
description: "Create a when conditions", description: "Create a when conditions",
example: "dfr when ((dfr col a) > 2) 4", example: "when ((col a) > 2) 4",
result: None, result: None,
}, },
Example { Example {
description: "Create a when conditions", description: "Create a when conditions",
example: "dfr when ((dfr col a) > 2) 4 | dfr when ((dfr col a) < 0) 6", example: "when ((col a) > 2) 4 | when ((col a) < 0) 6",
result: None, result: None,
}, },
Example { Example {
description: "Create a new column for the dataframe", description: "Create a new column for the dataframe",
example: r#"[[a b]; [6 2] [1 4] [4 1]] example: r#"[[a b]; [6 2] [1 4] [4 1]]
| dfr to-lazy | to-lazy
| dfr with-column ( | with-column (
dfr when ((dfr col a) > 2) 4 | dfr otherwise 5 | dfr as c when ((col a) > 2) 4 | otherwise 5 | as c
) )
| dfr with-column ( | with-column (
dfr when ((dfr col a) > 5) 10 | dfr when ((dfr col a) < 2) 6 | dfr otherwise 0 | dfr as d when ((col a) > 5) 10 | when ((col a) < 2) 6 | otherwise 0 | as d
) )
| dfr collect"#, | collect"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -83,6 +83,14 @@ impl Command for ExprWhen {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("expression".into())
}
fn output_type(&self) -> Type {
Type::Custom("expression".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,7 @@ pub struct LazyAggregate;
impl Command for LazyAggregate { impl Command for LazyAggregate {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr agg" "agg"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -34,12 +34,12 @@ impl Command for LazyAggregate {
Example { Example {
description: "Group by and perform an aggregation", description: "Group by and perform an aggregation",
example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]] example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr to-df | to-df
| dfr group-by a | group-by a
| dfr agg [ | agg [
("b" | dfr min | dfr as "b_min") (col b | min | as "b_min")
("b" | dfr max | dfr as "b_max") (col b | max | as "b_max")
("b" | dfr sum | dfr as "b_sum") (col b | sum | as "b_sum")
]"#, ]"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
@ -67,14 +67,14 @@ impl Command for LazyAggregate {
Example { Example {
description: "Group by and perform an aggregation", description: "Group by and perform an aggregation",
example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]] example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr to-lazy | to-lazy
| dfr group-by a | group-by a
| dfr agg [ | agg [
("b" | dfr min | dfr as "b_min") (col b | min | as "b_min")
("b" | dfr max | dfr as "b_max") (col b | max | as "b_max")
("b" | dfr sum | dfr as "b_sum") (col b | sum | as "b_sum")
] ]
| dfr collect"#, | collect"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -101,6 +101,14 @@ impl Command for LazyAggregate {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,
@ -133,9 +141,8 @@ impl Command for LazyAggregate {
mod test { mod test {
use super::super::super::test_dataframe::test_dataframe; use super::super::super::test_dataframe::test_dataframe;
use super::*; use super::*;
use crate::dataframe::expressions::ExprAlias; use crate::dataframe::expressions::{ExprAlias, ExprMax, ExprMin, ExprSum};
use crate::dataframe::lazy::groupby::ToLazyGroupBy; use crate::dataframe::lazy::groupby::ToLazyGroupBy;
use crate::dataframe::lazy::{LazyMax, LazyMin, LazySum};
#[test] #[test]
fn test_examples() { fn test_examples() {
@ -143,9 +150,9 @@ mod test {
Box::new(LazyAggregate {}), Box::new(LazyAggregate {}),
Box::new(ToLazyGroupBy {}), Box::new(ToLazyGroupBy {}),
Box::new(ExprAlias {}), Box::new(ExprAlias {}),
Box::new(LazyMin {}), Box::new(ExprMin {}),
Box::new(LazyMax {}), Box::new(ExprMax {}),
Box::new(LazySum {}), Box::new(ExprSum {}),
]) ])
} }
} }

View File

@ -4,7 +4,7 @@ use super::super::values::NuLazyFrame;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,7 @@ pub struct LazyCollect;
impl Command for LazyCollect { impl Command for LazyCollect {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr collect" "collect"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for LazyCollect {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "drop duplicates", description: "drop duplicates",
example: "[[a b]; [1 2] [3 4]] | dfr to-lazy | dfr collect", example: "[[a b]; [1 2] [3 4]] | to-lazy | collect",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -44,6 +44,14 @@ impl Command for LazyCollect {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,7 @@ pub struct LazyFetch;
impl Command for LazyFetch { impl Command for LazyFetch {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr fetch" "fetch"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -32,7 +32,7 @@ impl Command for LazyFetch {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Fetch a rows from the dataframe", description: "Fetch a rows from the dataframe",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr fetch 2", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | fetch 2",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -50,6 +50,14 @@ impl Command for LazyFetch {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -3,7 +3,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, SyntaxShape, Value, Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct LazyFillNA;
impl Command for LazyFillNA { impl Command for LazyFillNA {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr fill-na" "fill-na"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -36,6 +36,14 @@ impl Command for LazyFillNA {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct LazyFillNull;
impl Command for LazyFillNull { impl Command for LazyFillNull {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr fill-null" "fill-null"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -31,7 +31,7 @@ impl Command for LazyFillNull {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Fills the null values by 0", description: "Fills the null values by 0",
example: "[1 2 2 3 3] | dfr to-df | dfr shift 2 | dfr fill-null 0", example: "[1 2 2 3 3] | to-df | shift 2 | fill-null 0",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -49,6 +49,14 @@ impl Command for LazyFillNull {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::Expr; use polars::prelude::Expr;
@ -12,7 +12,7 @@ pub struct ToLazyGroupBy;
impl Command for ToLazyGroupBy { impl Command for ToLazyGroupBy {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr group-by" "group-by"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -34,12 +34,12 @@ impl Command for ToLazyGroupBy {
Example { Example {
description: "Group by and perform an aggregation", description: "Group by and perform an aggregation",
example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]] example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr to-df | to-df
| dfr group-by a | group-by a
| dfr agg [ | agg [
("b" | dfr min | dfr as "b_min") (col b | min | as "b_min")
("b" | dfr max | dfr as "b_max") (col b | max | as "b_max")
("b" | dfr sum | dfr as "b_sum") (col b | sum | as "b_sum")
]"#, ]"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
@ -67,14 +67,14 @@ impl Command for ToLazyGroupBy {
Example { Example {
description: "Group by and perform an aggregation", description: "Group by and perform an aggregation",
example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]] example: r#"[[a b]; [1 2] [1 4] [2 6] [2 4]]
| dfr to-df | to-lazy
| dfr group-by a | group-by a
| dfr agg [ | agg [
("b" | dfr min | dfr as "b_min") (col b | min | as "b_min")
("b" | dfr max | dfr as "b_max") (col b | max | as "b_max")
("b" | dfr sum | dfr as "b_sum") (col b | sum | as "b_sum")
] ]
| dfr collect"#, | collect"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -101,6 +101,14 @@ impl Command for ToLazyGroupBy {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,
@ -143,9 +151,8 @@ impl Command for ToLazyGroupBy {
mod test { mod test {
use super::super::super::test_dataframe::test_dataframe; use super::super::super::test_dataframe::test_dataframe;
use super::*; use super::*;
use crate::dataframe::expressions::ExprAlias; use crate::dataframe::expressions::{ExprAlias, ExprMax, ExprMin, ExprSum};
use crate::dataframe::lazy::aggregate::LazyAggregate; use crate::dataframe::lazy::aggregate::LazyAggregate;
use crate::dataframe::lazy::{LazyMax, LazyMin, LazySum};
#[test] #[test]
fn test_examples() { fn test_examples() {
@ -153,9 +160,9 @@ mod test {
Box::new(LazyAggregate {}), Box::new(LazyAggregate {}),
Box::new(ToLazyGroupBy {}), Box::new(ToLazyGroupBy {}),
Box::new(ExprAlias {}), Box::new(ExprAlias {}),
Box::new(LazyMin {}), Box::new(ExprMin {}),
Box::new(LazyMax {}), Box::new(ExprMax {}),
Box::new(LazySum {}), Box::new(ExprSum {}),
]) ])
} }
} }

View File

@ -3,7 +3,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::{Expr, JoinType}; use polars::prelude::{Expr, JoinType};
@ -12,7 +12,7 @@ pub struct LazyJoin;
impl Command for LazyJoin { impl Command for LazyJoin {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr join" "join"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -45,9 +45,9 @@ impl Command for LazyJoin {
vec![ vec![
Example { Example {
description: "Join two lazy dataframes", description: "Join two lazy dataframes",
example: r#"let df_a = ([[a b c];[1 "a" 0] [2 "b" 1] [1 "c" 2] [1 "c" 3]] | dfr to-lazy); example: r#"let df_a = ([[a b c];[1 "a" 0] [2 "b" 1] [1 "c" 2] [1 "c" 3]] | to-lazy);
let df_b = ([["foo" "bar" "ham"];[1 "a" "let"] [2 "c" "var"] [3 "c" "const"]] | dfr to-lazy); let df_b = ([["foo" "bar" "ham"];[1 "a" "let"] [2 "c" "var"] [3 "c" "const"]] | to-lazy);
$df_a | dfr join $df_b a foo | dfr collect"#, $df_a | join $df_b a foo | collect"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -102,9 +102,9 @@ impl Command for LazyJoin {
}, },
Example { Example {
description: "Join one eager dataframe with a lazy dataframe", description: "Join one eager dataframe with a lazy dataframe",
example: r#"let df_a = ([[a b c];[1 "a" 0] [2 "b" 1] [1 "c" 2] [1 "c" 3]] | dfr to-df); example: r#"let df_a = ([[a b c];[1 "a" 0] [2 "b" 1] [1 "c" 2] [1 "c" 3]] | to-df);
let df_b = ([["foo" "bar" "ham"];[1 "a" "let"] [2 "c" "var"] [3 "c" "const"]] | dfr to-lazy); let df_b = ([["foo" "bar" "ham"];[1 "a" "let"] [2 "c" "var"] [3 "c" "const"]] | to-lazy);
$df_a | dfr join $df_b a foo"#, $df_a | join $df_b a foo"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -160,6 +160,14 @@ impl Command for LazyJoin {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,11 +1,11 @@
/// Definition of multiple lazyframe commands using a macro rule /// Definition of multiple lazyframe commands using a macro rule
/// All of these commands have an identical body and only require /// All of these commands have an identical body and only require
/// to have a change in the name, description and function /// to have a change in the name, description and function
use crate::dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame}; use crate::dataframe::values::{Column, NuDataFrame, NuLazyFrame};
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
macro_rules! lazy_command { macro_rules! lazy_command {
@ -30,6 +30,14 @@ macro_rules! lazy_command {
$examples $examples
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,
@ -61,11 +69,11 @@ macro_rules! lazy_command {
// Expands to a command definition for reverse // Expands to a command definition for reverse
lazy_command!( lazy_command!(
LazyReverse, LazyReverse,
"dfr reverse", "reverse",
"Reverses the LazyFrame", "Reverses the LazyFrame",
vec![Example { vec![Example {
description: "Reverses the dataframe", description: "Reverses the dataframe",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr reverse", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | reverse",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -89,398 +97,167 @@ lazy_command!(
// Expands to a command definition for cache // Expands to a command definition for cache
lazy_command!( lazy_command!(
LazyCache, LazyCache,
"dfr cache", "cache",
"Caches operations in a new LazyFrame", "Caches operations in a new LazyFrame",
vec![Example { vec![Example {
description: "Caches the result into a new LazyFrame", description: "Caches the result into a new LazyFrame",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr reverse | dfr cache", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | reverse | cache",
result: None, result: None,
}], }],
cache, cache,
test_cache test_cache
); );
// Creates a command that may result in a lazy frame operation or
// lazy frame expression
macro_rules! lazy_expr_command {
($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident, $test: ident) => {
#[derive(Clone)]
pub struct $command;
impl Command for $command {
fn name(&self) -> &str {
$name
}
fn usage(&self) -> &str {
$desc
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.category(Category::Custom("lazyframe or expression".into()))
}
fn examples(&self) -> Vec<Example> {
$examples
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head);
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().$func().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else {
let lazy = NuLazyFrame::try_from_value(value)?;
let lazy = NuLazyFrame::new(lazy.from_eager, lazy.into_polars().$func());
Ok(PipelineData::Value(lazy.into_value(call.head)?, None))
}
}
}
#[cfg(test)]
mod $test {
use super::super::super::test_dataframe::test_dataframe;
use super::*;
use crate::dataframe::lazy::aggregate::LazyAggregate;
use crate::dataframe::lazy::groupby::ToLazyGroupBy;
#[test]
fn test_examples() {
test_dataframe(vec![
Box::new($command {}),
Box::new(LazyAggregate {}),
Box::new(ToLazyGroupBy {}),
])
}
}
};
}
// LazyMax command // LazyMax command
// Expands to a command definition for max aggregation // Expands to a command definition for max aggregation
lazy_expr_command!( lazy_command!(
LazyMax, LazyMax,
"dfr max", "max",
"Aggregates columns to their max value or creates a max expression", "Aggregates columns to their max value",
vec![ vec![Example {
Example { description: "Max value from columns in a dataframe",
description: "Max value from columns in a dataframe", example: "[[a b]; [6 2] [1 4] [4 1]] | to-df | max",
example: "[[a b]; [6 2] [1 4] [4 1]] | dfr to-df | dfr max", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_int(6)],),
Column::new("a".to_string(), vec![Value::test_int(6)],), Column::new("b".to_string(), vec![Value::test_int(4)],),
Column::new("b".to_string(), vec![Value::test_int(4)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Max aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr max)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_int(4), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
max, max,
test_max test_max
); );
// LazyMin command // LazyMin command
// Expands to a command definition for min aggregation // Expands to a command definition for min aggregation
lazy_expr_command!( lazy_command!(
LazyMin, LazyMin,
"dfr min", "min",
"Aggregates columns to their min value or creates a min expression", "Aggregates columns to their min value",
vec![ vec![Example {
Example { description: "Min value from columns in a dataframe",
description: "Min value from columns in a dataframe", example: "[[a b]; [6 2] [1 4] [4 1]] | to-df | min",
example: "[[a b]; [6 2] [1 4] [4 1]] | dfr to-df | dfr min", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_int(1)],),
Column::new("a".to_string(), vec![Value::test_int(1)],), Column::new("b".to_string(), vec![Value::test_int(1)],),
Column::new("b".to_string(), vec![Value::test_int(1)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Min aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr min)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
min, min,
test_min test_min
); );
// LazySum command // LazySum command
// Expands to a command definition for sum aggregation // Expands to a command definition for sum aggregation
lazy_expr_command!( lazy_command!(
LazySum, LazySum,
"dfr sum", "sum",
"Aggregates columns to their sum value or creates a sum expression for an aggregation", "Aggregates columns to their sum value",
vec![ vec![Example {
Example { description: "Sums all columns in a dataframe",
description: "Sums all columns in a dataframe", example: "[[a b]; [6 2] [1 4] [4 1]] | to-df | sum",
example: "[[a b]; [6 2] [1 4] [4 1]] | dfr to-df | dfr sum", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_int(11)],),
Column::new("a".to_string(), vec![Value::test_int(11)],), Column::new("b".to_string(), vec![Value::test_int(7)],),
Column::new("b".to_string(), vec![Value::test_int(7)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Sum aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr sum)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_int(6), Value::test_int(1)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
sum, sum,
test_sum test_sum
); );
// LazyMean command // LazyMean command
// Expands to a command definition for mean aggregation // Expands to a command definition for mean aggregation
lazy_expr_command!( lazy_command!(
LazyMean, LazyMean,
"dfr mean", "mean",
"Aggregates columns to their mean value or creates a mean expression for an aggregation", "Aggregates columns to their mean value",
vec![ vec![Example {
Example { description: "Mean value from columns in a dataframe",
description: "Mean value from columns in a dataframe", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | mean",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr mean", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_float(4.0)],),
Column::new("a".to_string(), vec![Value::test_float(4.0)],), Column::new("b".to_string(), vec![Value::test_float(2.0)],),
Column::new("b".to_string(), vec![Value::test_float(2.0)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Mean aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr mean)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(3.0), Value::test_float(1.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
mean, mean,
test_mean test_mean
); );
// LazyMedian command // LazyMedian command
// Expands to a command definition for median aggregation // Expands to a command definition for median aggregation
lazy_expr_command!( lazy_command!(
LazyMedian, LazyMedian,
"dfr median", "median",
"Aggregates columns to their median value or creates a median expression for an aggregation", "Aggregates columns to their median value",
vec![ vec![Example {
Example { description: "Median value from columns in a dataframe",
description: "Median value from columns in a dataframe", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | median",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr median", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_float(4.0)],),
Column::new("a".to_string(), vec![Value::test_float(4.0)],), Column::new("b".to_string(), vec![Value::test_float(2.0)],),
Column::new("b".to_string(), vec![Value::test_float(2.0)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Median aggregation for a group by",
example: r#"[[a b]; [one 2] [one 4] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr median)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(3.0), Value::test_float(1.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
median, median,
test_median test_median
); );
// LazyStd command // LazyStd command
// Expands to a command definition for std aggregation // Expands to a command definition for std aggregation
lazy_expr_command!( lazy_command!(
LazyStd, LazyStd,
"dfr std", "std",
"Aggregates columns to their std value or creates a std expression for an aggregation", "Aggregates columns to their std value",
vec![ vec![Example {
Example { description: "Std value from columns in a dataframe",
description: "Std value from columns in a dataframe", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | std",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr std", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_float(2.0)],),
Column::new("a".to_string(), vec![Value::test_float(2.0)],), Column::new("b".to_string(), vec![Value::test_float(0.0)],),
Column::new("b".to_string(), vec![Value::test_float(0.0)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Std aggregation for a group by",
example: r#"[[a b]; [one 2] [one 2] [two 1] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr std)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(0.0), Value::test_float(0.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
std, std,
test_std test_std
); );
// LazyVar command // LazyVar command
// Expands to a command definition for var aggregation // Expands to a command definition for var aggregation
lazy_expr_command!( lazy_command!(
LazyVar, LazyVar,
"dfr var", "var",
"Aggregates columns to their var value or create a var expression for an aggregation", "Aggregates columns to their var value",
vec![ vec![Example {
Example { description: "Var value from columns in a dataframe",
description: "Var value from columns in a dataframe", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | var",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr var", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_float(4.0)],),
Column::new("a".to_string(), vec![Value::test_float(4.0)],), Column::new("b".to_string(), vec![Value::test_float(0.0)],),
Column::new("b".to_string(), vec![Value::test_float(0.0)],), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), },],
},
Example {
description: "Var aggregation for a group by",
example: r#"[[a b]; [one 2] [one 2] [two 1] [two 1]]
| dfr to-df
| dfr group-by a
| dfr agg ("b" | dfr var)"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(0.0), Value::test_float(0.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
],
var, var,
test_var test_var
); );

View File

@ -1,9 +1,9 @@
mod aggregate; pub mod aggregate;
mod collect; mod collect;
mod fetch; mod fetch;
mod fill_na; mod fill_na;
mod fill_null; mod fill_null;
mod groupby; pub mod groupby;
mod join; mod join;
mod macro_commands; mod macro_commands;
mod quantile; mod quantile;

View File

@ -1,9 +1,9 @@
use crate::dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame}; use crate::dataframe::values::{Column, NuDataFrame, NuLazyFrame};
use nu_engine::CallExt; 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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::QuantileInterpolOptions; use polars::prelude::QuantileInterpolOptions;
@ -12,7 +12,7 @@ pub struct LazyQuantile;
impl Command for LazyQuantile { impl Command for LazyQuantile {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr quantile" "quantile"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -30,41 +30,26 @@ impl Command for LazyQuantile {
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "quantile value from columns in a dataframe",
description: "quantile value from columns in a dataframe", example: "[[a b]; [6 2] [1 4] [4 1]] | to-df | quantile 0.5",
example: "[[a b]; [6 2] [1 4] [4 1]] | dfr to-df | dfr quantile 0.5", result: Some(
result: Some( NuDataFrame::try_from_columns(vec![
NuDataFrame::try_from_columns(vec![ Column::new("a".to_string(), vec![Value::test_float(4.0)]),
Column::new("a".to_string(), vec![Value::test_float(4.0)]), Column::new("b".to_string(), vec![Value::test_float(2.0)]),
Column::new("b".to_string(), vec![Value::test_float(2.0)]), ])
]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), }]
}, }
Example {
description: "Quantile aggregation for a group by", fn input_type(&self) -> Type {
example: r#"[[a b]; [one 2] [one 4] [two 1]] Type::Custom("dataframe".into())
| dfr to-df }
| dfr group-by a
| dfr agg ("b" | dfr quantile 0.5)"#, fn output_type(&self) -> Type {
result: Some( Type::Custom("dataframe".into())
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_string("one"), Value::test_string("two")],
),
Column::new(
"b".to_string(),
vec![Value::test_float(4.0), Value::test_float(1.0)],
),
])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
]
} }
fn run( fn run(
@ -77,27 +62,14 @@ impl Command for LazyQuantile {
let value = input.into_value(call.head); let value = input.into_value(call.head);
let quantile: f64 = call.req(engine_state, stack, 0)?; let quantile: f64 = call.req(engine_state, stack, 0)?;
if NuExpression::can_downcast(&value) { let lazy = NuLazyFrame::try_from_value(value)?;
let expr = NuExpression::try_from_value(value)?; let lazy = NuLazyFrame::new(
let expr: NuExpression = expr lazy.from_eager,
.into_polars() lazy.into_polars()
.quantile(quantile, QuantileInterpolOptions::default()) .quantile(quantile, QuantileInterpolOptions::default()),
.into(); );
Ok(PipelineData::Value( Ok(PipelineData::Value(lazy.into_value(call.head)?, None))
NuExpression::into_value(expr, call.head),
None,
))
} else {
let lazy = NuLazyFrame::try_from_value(value)?;
let lazy = NuLazyFrame::new(
lazy.from_eager,
lazy.into_polars()
.quantile(quantile, QuantileInterpolOptions::default()),
);
Ok(PipelineData::Value(lazy.into_value(call.head)?, None))
}
} }
} }
@ -105,15 +77,9 @@ impl Command for LazyQuantile {
mod test { mod test {
use super::super::super::test_dataframe::test_dataframe; use super::super::super::test_dataframe::test_dataframe;
use super::*; use super::*;
use crate::dataframe::lazy::aggregate::LazyAggregate;
use crate::dataframe::lazy::groupby::ToLazyGroupBy;
#[test] #[test]
fn test_examples() { fn test_examples() {
test_dataframe(vec![ test_dataframe(vec![Box::new(LazyQuantile {})])
Box::new(LazyQuantile {}),
Box::new(LazyAggregate {}),
Box::new(ToLazyGroupBy {}),
])
} }
} }

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::Expr; use polars::prelude::Expr;
@ -13,7 +13,7 @@ pub struct LazySelect;
impl Command for LazySelect { impl Command for LazySelect {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr select" "select"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -33,7 +33,7 @@ impl Command for LazySelect {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Select a column from the dataframe", description: "Select a column from the dataframe",
example: "[[a b]; [6 2] [4 2] [2 2]] | dfr to-df | dfr select a", example: "[[a b]; [6 2] [4 2] [2 2]] | to-df | select a",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"a".to_string(), "a".to_string(),
@ -45,6 +45,14 @@ impl Command for LazySelect {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -12,7 +12,7 @@ pub struct LazySortBy;
impl Command for LazySortBy { impl Command for LazySortBy {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr sort-by" "sort-by"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -39,7 +39,7 @@ impl Command for LazySortBy {
vec![ vec![
Example { Example {
description: "Sort dataframe by one column", description: "Sort dataframe by one column",
example: "[[a b]; [6 2] [1 4] [4 1]] | dfr to-df | dfr sort-by a", example: "[[a b]; [6 2] [1 4] [4 1]] | to-df | sort-by a",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -57,8 +57,7 @@ impl Command for LazySortBy {
}, },
Example { Example {
description: "Sort column using two columns", description: "Sort column using two columns",
example: example: "[[a b]; [6 2] [1 1] [1 4] [2 4]] | to-df | sort-by [a b] -r [false true]",
"[[a b]; [6 2] [1 1] [1 4] [2 4]] | dfr to-df | dfr sort-by [a b] -r [false true]",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -87,6 +86,14 @@ impl Command for LazySortBy {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -3,7 +3,7 @@ use super::super::values::{NuDataFrame, NuLazyFrame};
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Value, Category, Example, PipelineData, ShellError, Signature, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct ToLazyFrame;
impl Command for ToLazyFrame { impl Command for ToLazyFrame {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-lazy" "to-lazy"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -25,11 +25,19 @@ impl Command for ToLazyFrame {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Takes a dictionary and creates a lazy dataframe", description: "Takes a dictionary and creates a lazy dataframe",
example: "[[a b];[1 2] [3 4]] | dfr to-df | dfl to-lazy", example: "[[a b];[1 2] [3 4]] | to-lazy",
result: None, result: None,
}] }]
} }
fn input_type(&self) -> Type {
Type::Any
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
_engine_state: &EngineState, _engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct AllFalse;
impl Command for AllFalse { impl Command for AllFalse {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr all-false" "all-false"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for AllFalse {
vec![ vec![
Example { Example {
description: "Returns true if all values are false", description: "Returns true if all values are false",
example: "[false false false] | dfr to-df | dfr all-false", example: "[false false false] | to-df | all-false",
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(),
@ -38,9 +38,9 @@ impl Command for AllFalse {
}, },
Example { Example {
description: "Checks the result from a comparison", description: "Checks the result from a comparison",
example: r#"let s = ([5 6 2 10] | dfr to-df); example: r#"let s = ([5 6 2 10] | to-df);
let res = ($s > 9); let res = ($s > 9);
$res | dfr all-false"#, $res | all-false"#,
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(),
@ -53,6 +53,14 @@ impl Command for AllFalse {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct AllTrue;
impl Command for AllTrue { impl Command for AllTrue {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr all-true" "all-true"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for AllTrue {
vec![ vec![
Example { Example {
description: "Returns true if all values are true", description: "Returns true if all values are true",
example: "[true true true] | dfr to-df | dfr all-true", example: "[true true true] | to-df | all-true",
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(),
@ -38,9 +38,9 @@ impl Command for AllTrue {
}, },
Example { Example {
description: "Checks the result from a comparison", description: "Checks the result from a comparison",
example: r#"let s = ([5 6 2 8] | dfr to-df); example: r#"let s = ([5 6 2 8] | to-df);
let res = ($s > 9); let res = ($s > 9);
$res | dfr all-true"#, $res | all-true"#,
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(),
@ -53,6 +53,14 @@ impl Command for AllTrue {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked}; use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
@ -12,7 +12,7 @@ pub struct ArgMax;
impl Command for ArgMax { impl Command for ArgMax {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr arg-max" "arg-max"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ArgMax {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Returns index for max value", description: "Returns index for max value",
example: "[1 3 2] | dfr to-df | dfr arg-max", example: "[1 3 2] | to-df | arg-max",
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(),
@ -38,6 +38,14 @@ impl Command for ArgMax {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked}; use polars::prelude::{IntoSeries, NewChunkedArray, UInt32Chunked};
@ -12,7 +12,7 @@ pub struct ArgMin;
impl Command for ArgMin { impl Command for ArgMin {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr arg-min" "arg-min"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ArgMin {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Returns index for min value", description: "Returns index for min value",
example: "[1 3 2] | dfr to-df | dfr arg-min", example: "[1 3 2] | to-df | arg-min",
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(),
@ -38,6 +38,14 @@ impl Command for ArgMin {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -4,7 +4,8 @@ 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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
Value,
}; };
use polars::prelude::{DataType, IntoSeries}; use polars::prelude::{DataType, IntoSeries};
@ -44,7 +45,7 @@ pub struct Cumulative;
impl Command for Cumulative { impl Command for Cumulative {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr cumulative" "cumulative"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -61,7 +62,7 @@ impl Command for Cumulative {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Cumulative sum for a series", description: "Cumulative sum for a series",
example: "[1 2 3 4 5] | dfr to-df | dfr cumulative sum", example: "[1 2 3 4 5] | to-df | cumulative sum",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0_cumulative_sum".to_string(), "0_cumulative_sum".to_string(),
@ -79,6 +80,14 @@ impl Command for Cumulative {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, SyntaxShape, Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type,
}; };
use polars::prelude::{IntoSeries, Utf8Methods}; use polars::prelude::{IntoSeries, Utf8Methods};
@ -13,7 +13,7 @@ pub struct AsDate;
impl Command for AsDate { impl Command for AsDate {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr as-date" "as-date"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -37,11 +37,19 @@ impl Command for AsDate {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Converts string to date", description: "Converts string to date",
example: r#"["2021-12-30" "2021-12-31"] | dfr to-df | dfr as-datetime "%Y-%m-%d""#, example: r#"["2021-12-30" "2021-12-31"] | to-df | as-datetime "%Y-%m-%d""#,
result: None, result: None,
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -5,7 +5,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::{IntoSeries, TimeUnit, Utf8Methods}; use polars::prelude::{IntoSeries, TimeUnit, Utf8Methods};
@ -14,7 +14,7 @@ pub struct AsDateTime;
impl Command for AsDateTime { impl Command for AsDateTime {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr as-datetime" "as-datetime"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -46,7 +46,7 @@ impl Command for AsDateTime {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Converts string to datetime", description: "Converts string to datetime",
example: r#"["2021-12-30 00:00:00" "2021-12-31 00:00:00"] | dfr to-df | dfr as-datetime "%Y-%m-%d %H:%M:%S""#, example: r#"["2021-12-30 00:00:00" "2021-12-31 00:00:00"] | to-df | as-datetime "%Y-%m-%d %H:%M:%S""#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"datetime".to_string(), "datetime".to_string(),
@ -75,6 +75,14 @@ impl Command for AsDateTime {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetDay;
impl Command for GetDay { impl Command for GetDay {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-day" "get-day"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetDay {
vec![Example { vec![Example {
description: "Returns day from a date", description: "Returns day from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-day"#, $df | get-day"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetDay {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetHour;
impl Command for GetHour { impl Command for GetHour {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-hour" "get-hour"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetHour {
vec![Example { vec![Example {
description: "Returns hour from a date", description: "Returns hour from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-hour"#, $df | get-hour"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetHour {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetMinute;
impl Command for GetMinute { impl Command for GetMinute {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-minute" "get-minute"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetMinute {
vec![Example { vec![Example {
description: "Returns minute from a date", description: "Returns minute from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-minute"#, $df | get-minute"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetMinute {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetMonth;
impl Command for GetMonth { impl Command for GetMonth {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-month" "get-month"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetMonth {
vec![Example { vec![Example {
description: "Returns month from a date", description: "Returns month from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-month"#, $df | get-month"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetMonth {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetNanosecond;
impl Command for GetNanosecond { impl Command for GetNanosecond {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-nanosecond" "get-nanosecond"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetNanosecond {
vec![Example { vec![Example {
description: "Returns nanosecond from a date", description: "Returns nanosecond from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-nanosecond"#, $df | get-nanosecond"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetNanosecond {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetOrdinal;
impl Command for GetOrdinal { impl Command for GetOrdinal {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-ordinal" "get-ordinal"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetOrdinal {
vec![Example { vec![Example {
description: "Returns ordinal from a date", description: "Returns ordinal from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-ordinal"#, $df | get-ordinal"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetOrdinal {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetSecond;
impl Command for GetSecond { impl Command for GetSecond {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-second" "get-second"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetSecond {
vec![Example { vec![Example {
description: "Returns second from a date", description: "Returns second from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-second"#, $df | get-second"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetSecond {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetWeek;
impl Command for GetWeek { impl Command for GetWeek {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-week" "get-week"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetWeek {
vec![Example { vec![Example {
description: "Returns week from a date", description: "Returns week from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-week"#, $df | get-week"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetWeek {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetWeekDay;
impl Command for GetWeekDay { impl Command for GetWeekDay {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-weekday" "get-weekday"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetWeekDay {
vec![Example { vec![Example {
description: "Returns weekday from a date", description: "Returns weekday from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-weekday"#, $df | get-weekday"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetWeekDay {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{DatetimeMethods, IntoSeries}; use polars::prelude::{DatetimeMethods, IntoSeries};
@ -12,7 +12,7 @@ pub struct GetYear;
impl Command for GetYear { impl Command for GetYear {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr get-year" "get-year"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -27,8 +27,8 @@ impl Command for GetYear {
vec![Example { vec![Example {
description: "Returns year from a date", description: "Returns year from a date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr get-year"#, $df | get-year"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -40,6 +40,14 @@ impl Command for GetYear {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::{IntoSeries, SortOptions}; use polars::prelude::{IntoSeries, SortOptions};
@ -12,7 +12,7 @@ pub struct ArgSort;
impl Command for ArgSort { impl Command for ArgSort {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr arg-sort" "arg-sort"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -30,7 +30,7 @@ impl Command for ArgSort {
vec![ vec![
Example { Example {
description: "Returns indexes for a sorted series", description: "Returns indexes for a sorted series",
example: "[1 2 2 3 3] | dfr to-df | dfr arg-sort", example: "[1 2 2 3 3] | to-df | arg-sort",
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(),
@ -48,7 +48,7 @@ impl Command for ArgSort {
}, },
Example { Example {
description: "Returns indexes for a sorted series", description: "Returns indexes for a sorted series",
example: "[1 2 2 3 3] | dfr to-df | dfr arg-sort -r", example: "[1 2 2 3 3] | to-df | arg-sort -r",
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(),
@ -67,6 +67,14 @@ impl Command for ArgSort {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct ArgTrue;
impl Command for ArgTrue { impl Command for ArgTrue {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr arg-true" "arg-true"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ArgTrue {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Returns indexes where values are true", description: "Returns indexes where values are true",
example: "[false true false] | dfr to-df | dfr arg-true", example: "[false true false] | to-df | arg-true",
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(),
@ -38,6 +38,14 @@ impl Command for ArgTrue {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct ArgUnique;
impl Command for ArgUnique { impl Command for ArgUnique {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr arg-unique" "arg-unique"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ArgUnique {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Returns indexes for unique values", description: "Returns indexes for unique values",
example: "[1 2 2 3 3] | dfr to-df | dfr arg-unique", example: "[1 2 2 3 3] | to-df | arg-unique",
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(),
@ -38,6 +38,14 @@ impl Command for ArgUnique {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::{ChunkSet, DataType, IntoSeries}; use polars::prelude::{ChunkSet, DataType, IntoSeries};
@ -13,7 +13,7 @@ pub struct SetWithIndex;
impl Command for SetWithIndex { impl Command for SetWithIndex {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr set-with-idx" "set-with-idx"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -35,9 +35,9 @@ impl Command for SetWithIndex {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Set value in selected rows from series", description: "Set value in selected rows from series",
example: r#"let series = ([4 1 5 2 4 3] | dfr to-df); example: r#"let series = ([4 1 5 2 4 3] | to-df);
let indices = ([0 2] | dfr to-df); let indices = ([0 2] | to-df);
$series | dfr set-with-idx 6 -i $indices"#, $series | set-with-idx 6 -i $indices"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -56,6 +56,14 @@ impl Command for SetWithIndex {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct IsDuplicated;
impl Command for IsDuplicated { impl Command for IsDuplicated {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr is-duplicated" "is-duplicated"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for IsDuplicated {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Create mask indicating duplicated values", description: "Create mask indicating duplicated values",
example: "[5 6 6 6 8 8 8] | dfr to-df | dfr is-duplicated", example: "[5 6 6 6 8 8 8] | to-df | is-duplicated",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"is_duplicated".to_string(), "is_duplicated".to_string(),
@ -46,6 +46,14 @@ impl Command for IsDuplicated {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct IsIn;
impl Command for IsIn { impl Command for IsIn {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr is-in" "is-in"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -29,8 +29,8 @@ impl Command for IsIn {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Checks if elements from a series are contained in right series", description: "Checks if elements from a series are contained in right series",
example: r#"let other = ([1 3 6] | dfr to-df); example: r#"let other = ([1 3 6] | to-df);
[5 6 6 6 8 8 8] | dfr to-df | dfr is-in $other"#, [5 6 6 6 8 8 8] | to-df | is-in $other"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"is_in".to_string(), "is_in".to_string(),
@ -50,6 +50,14 @@ impl Command for IsIn {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,9 +1,8 @@
use super::super::super::values::{Column, NuDataFrame}; use super::super::super::values::{Column, NuDataFrame};
use crate::dataframe::values::NuExpression;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,44 +11,45 @@ pub struct IsNotNull;
impl Command for IsNotNull { impl Command for IsNotNull {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr is-not-null" "is-not-null"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Creates mask where value is not null or creates a is-not-null expression" "Creates mask where value is not null"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Custom("dataframe or lazyframe".into())) Signature::build(self.name()).category(Category::Custom("dataframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "Create mask where values are not null",
description: "Create mask where values are not null", example: r#"let s = ([5 6 0 8] | to-df);
example: r#"let s = ([5 6 0 8] | dfr to-df);
let res = ($s / $s); let res = ($s / $s);
$res | dfr is-not-null"#, $res | is-not-null"#,
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![ vec![
Value::test_bool(true), Value::test_bool(true),
Value::test_bool(true), Value::test_bool(true),
Value::test_bool(false), Value::test_bool(false),
Value::test_bool(true), Value::test_bool(true),
], ],
)]) )])
.expect("simple df for test should not fail") .expect("simple df for test should not fail")
.into_value(Span::test_data()), .into_value(Span::test_data()),
), ),
}, }]
Example { }
description: "Creates a is not null expression from a column",
example: "dfr col a | dfr is-not-null", fn input_type(&self) -> Type {
result: None, Type::Custom("dataframe".into())
}, }
]
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
} }
fn run( fn run(
@ -59,27 +59,8 @@ impl Command for IsNotNull {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head); let df = NuDataFrame::try_from_pipeline(input, call.head)?;
command(engine_state, stack, call, df)
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().is_not_null().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else if NuDataFrame::can_downcast(&value) {
let df = NuDataFrame::try_from_value(value)?;
command(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
}
} }
} }

View File

@ -1,9 +1,8 @@
use super::super::super::values::{Column, NuDataFrame}; use super::super::super::values::{Column, NuDataFrame};
use crate::dataframe::values::NuExpression;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,44 +11,45 @@ pub struct IsNull;
impl Command for IsNull { impl Command for IsNull {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr is-null" "is-null"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Creates mask where value is null or creates a is-null expression" "Creates mask where value is null"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Custom("dataframe or expression".into())) Signature::build(self.name()).category(Category::Custom("dataframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "Create mask where values are null",
description: "Create mask where values are null", example: r#"let s = ([5 6 0 8] | to-df);
example: r#"let s = ([5 6 0 8] | dfr to-df);
let res = ($s / $s); let res = ($s / $s);
$res | dfr is-null"#, $res | is-null"#,
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![ vec![
Value::test_bool(false), Value::test_bool(false),
Value::test_bool(false), Value::test_bool(false),
Value::test_bool(true), 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::test_data()), .into_value(Span::test_data()),
), ),
}, }]
Example { }
description: "Creates a is not null expression from a column",
example: "dfr col a | dfr is-null", fn input_type(&self) -> Type {
result: None, Type::Custom("dataframe".into())
}, }
]
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
} }
fn run( fn run(
@ -59,27 +59,8 @@ impl Command for IsNull {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head); let df = NuDataFrame::try_from_pipeline(input, call.head)?;
command(engine_state, stack, call, df)
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().is_null().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else if NuDataFrame::can_downcast(&value) {
let df = NuDataFrame::try_from_value(value)?;
command(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
}
} }
} }

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct IsUnique;
impl Command for IsUnique { impl Command for IsUnique {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr is-unique" "is-unique"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for IsUnique {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Create mask indicating unique values", description: "Create mask indicating unique values",
example: "[5 6 6 6 8 8 8] | dfr to-df | dfr is-unique", example: "[5 6 6 6 8 8 8] | to-df | is-unique",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"is_unique".to_string(), "is_unique".to_string(),
@ -46,6 +46,14 @@ impl Command for IsUnique {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,9 +1,8 @@
use super::super::super::values::{Column, NuDataFrame}; use super::super::super::values::{Column, NuDataFrame};
use crate::dataframe::values::NuExpression;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -14,41 +13,42 @@ pub struct NotSeries;
impl Command for NotSeries { impl Command for NotSeries {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr not" "df-not"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Inverts boolean mask or creates a not expression" "Inverts boolean mask"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Custom("dataframe or lazyframes".into())) Signature::build(self.name()).category(Category::Custom("dataframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "Inverts boolean mask",
description: "Inverts boolean mask", example: "[true false true] | to-df | df-not",
example: "[true false true] | dfr to-df | dfr not", 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![
vec![ Value::test_bool(false),
Value::test_bool(false), Value::test_bool(true),
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::test_data()),
.into_value(Span::test_data()), ),
), }]
}, }
Example {
description: "Creates a not expression from a column", fn input_type(&self) -> Type {
example: "((dfr col a) > 2) | dfr not", Type::Custom("dataframe".into())
result: None, }
},
] fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
} }
fn run( fn run(
@ -58,27 +58,8 @@ impl Command for NotSeries {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head); let df = NuDataFrame::try_from_pipeline(input, call.head)?;
command(engine_state, stack, call, df)
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().is_null().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else if NuDataFrame::can_downcast(&value) {
let df = NuDataFrame::try_from_value(value)?;
command(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
}
} }
} }

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::{ChunkSet, DataType, IntoSeries}; use polars::prelude::{ChunkSet, DataType, IntoSeries};
@ -13,7 +13,7 @@ pub struct SetSeries;
impl Command for SetSeries { impl Command for SetSeries {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr set" "set"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -35,9 +35,9 @@ impl Command for SetSeries {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Shifts the values by a given period", description: "Shifts the values by a given period",
example: r#"let s = ([1 2 2 3 3] | dfr to-df | dfr shift 2); example: r#"let s = ([1 2 2 3 3] | to-df | shift 2);
let mask = ($s | dfr is-null); let mask = ($s | is-null);
$s | dfr set 0 --mask $mask"#, $s | set 0 --mask $mask"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -55,6 +55,14 @@ impl Command for SetSeries {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct NNull;
impl Command for NNull { impl Command for NNull {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr count-null" "count-null"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -25,8 +25,8 @@ impl Command for NNull {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Counts null values", description: "Counts null values",
example: r#"let s = ([1 1 0 0 3 3 4] | dfr to-df); example: r#"let s = ([1 1 0 0 3 3 4] | to-df);
($s / $s) | dfr count-null"#, ($s / $s) | count-null"#,
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(),
@ -38,6 +38,14 @@ impl Command for NNull {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -1,9 +1,8 @@
use super::super::values::{Column, NuDataFrame}; use super::super::values::{Column, NuDataFrame};
use crate::dataframe::values::NuExpression;
use nu_protocol::{ use nu_protocol::{
ast::Call, ast::Call,
engine::{Command, EngineState, Stack}, engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,37 +10,38 @@ pub struct NUnique;
impl Command for NUnique { impl Command for NUnique {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr n-unique" "n-unique"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Counts unique values or creates a n-unique expression" "Counts unique values"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Custom("dataframe or expression".into())) Signature::build(self.name()).category(Category::Custom("dataframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![Example {
Example { description: "Counts unique values",
description: "Counts unique values", example: "[1 1 2 2 3 3 4] | to-df | n-unique",
example: "[1 1 2 2 3 3 4] | dfr to-df | dfr n-unique", 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![Value::test_int(4)],
vec![Value::test_int(4)], )])
)]) .expect("simple df for test should not fail")
.expect("simple df for test should not fail") .into_value(Span::test_data()),
.into_value(Span::test_data()), ),
), }]
}, }
Example {
description: "Creates a is n-unique expression from a column", fn input_type(&self) -> Type {
example: "dfr col a | dfr n-unique", Type::Custom("dataframe".into())
result: None, }
},
] fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
} }
fn run( fn run(
@ -51,27 +51,8 @@ impl Command for NUnique {
call: &Call, call: &Call,
input: PipelineData, input: PipelineData,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let value = input.into_value(call.head); let df = NuDataFrame::try_from_pipeline(input, call.head)?;
command(engine_state, stack, call, df)
if NuExpression::can_downcast(&value) {
let expr = NuExpression::try_from_value(value)?;
let expr: NuExpression = expr.into_polars().n_unique().into();
Ok(PipelineData::Value(
NuExpression::into_value(expr, call.head),
None,
))
} else if NuDataFrame::can_downcast(&value) {
let df = NuDataFrame::try_from_value(value)?;
command(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
}
} }
} }

View File

@ -4,7 +4,8 @@ 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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
Value,
}; };
use polars::prelude::{DataType, IntoSeries, RollingOptions}; use polars::prelude::{DataType, IntoSeries, RollingOptions};
@ -47,7 +48,7 @@ pub struct Rolling;
impl Command for Rolling { impl Command for Rolling {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr rolling" "rolling"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -65,7 +66,7 @@ impl Command for Rolling {
vec![ vec![
Example { Example {
description: "Rolling sum for a series", description: "Rolling sum for a series",
example: "[1 2 3 4 5] | dfr to-df | dfr rolling sum 2 | dfr drop-nulls", example: "[1 2 3 4 5] | to-df | rolling sum 2 | drop-nulls",
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(),
@ -82,7 +83,7 @@ impl Command for Rolling {
}, },
Example { Example {
description: "Rolling max for a series", description: "Rolling max for a series",
example: "[1 2 3 4 5] | dfr to-df | dfr rolling max 2 | dfr drop-nulls", example: "[1 2 3 4 5] | to-df | rolling max 2 | drop-nulls",
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(),
@ -100,6 +101,14 @@ impl Command for Rolling {
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -6,7 +6,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -14,7 +14,7 @@ pub struct Shift;
impl Command for Shift { impl Command for Shift {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr shift" "shift"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -36,7 +36,7 @@ impl Command for Shift {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Shifts the values by a given period", description: "Shifts the values by a given period",
example: "[1 2 2 3 3] | dfr to-df | dfr shift 2 | dfr drop-nulls", example: "[1 2 2 3 3] | to-df | shift 2 | drop-nulls",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -48,6 +48,14 @@ impl Command for Shift {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,
@ -60,16 +68,9 @@ impl Command for Shift {
if NuLazyFrame::can_downcast(&value) { if NuLazyFrame::can_downcast(&value) {
let df = NuLazyFrame::try_from_value(value)?; let df = NuLazyFrame::try_from_value(value)?;
command_lazy(engine_state, stack, call, df) command_lazy(engine_state, stack, call, df)
} else if NuDataFrame::can_downcast(&value) { } else {
let df = NuDataFrame::try_from_value(value)?; let df = NuDataFrame::try_from_value(value)?;
command_eager(engine_state, stack, call, df) command_eager(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
} }
} }
} }

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct Concatenate;
impl Command for Concatenate { impl Command for Concatenate {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr concatenate" "concatenate"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -33,8 +33,8 @@ impl Command for Concatenate {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Concatenate string", description: "Concatenate string",
example: r#"let other = ([za xs cd] | dfr to-df); example: r#"let other = ([za xs cd] | to-df);
[abc abc abc] | dfr to-df | dfr concatenate $other"#, [abc abc abc] | to-df | concatenate $other"#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -50,6 +50,14 @@ impl Command for Concatenate {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct Contains;
impl Command for Contains { impl Command for Contains {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr contains" "contains"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -33,7 +33,7 @@ impl Command for Contains {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Returns boolean indicating if pattern was found", description: "Returns boolean indicating if pattern was found",
example: "[abc acb acb] | dfr to-df | dfr contains ab", example: "[abc acb acb] | to-df | contains ab",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -49,6 +49,14 @@ impl Command for Contains {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct Replace;
impl Command for Replace { impl Command for Replace {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr replace" "replace"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -40,7 +40,7 @@ impl Command for Replace {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Replaces string", description: "Replaces string",
example: "[abc abc abc] | dfr to-df | dfr replace -p ab -r AB", example: "[abc abc abc] | to-df | replace -p ab -r AB",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -56,6 +56,14 @@ impl Command for Replace {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct ReplaceAll;
impl Command for ReplaceAll { impl Command for ReplaceAll {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr replace-all" "replace-all"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -40,7 +40,7 @@ impl Command for ReplaceAll {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Replaces string", description: "Replaces string",
example: "[abac abac abac] | dfr to-df | dfr replace-all -p a -r A", example: "[abac abac abac] | to-df | replace-all -p a -r A",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -56,6 +56,14 @@ impl Command for ReplaceAll {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct StrLengths;
impl Command for StrLengths { impl Command for StrLengths {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr str-lengths" "str-lengths"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for StrLengths {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Returns string lengths", description: "Returns string lengths",
example: "[a ab abc] | dfr to-df | dfr str-lengths", example: "[a ab abc] | to-df | str-lengths",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -38,6 +38,14 @@ impl Command for StrLengths {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct StrSlice;
impl Command for StrSlice { impl Command for StrSlice {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr str-slice" "str-slice"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -30,7 +30,7 @@ impl Command for StrSlice {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Creates slices from the strings", description: "Creates slices from the strings",
example: "[abcded abc321 abc123] | dfr to-df | dfr str-slice 1 -l 2", example: "[abcded abc321 abc123] | to-df | str-slice 1 -l 2",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -46,6 +46,14 @@ impl Command for StrSlice {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -13,7 +13,7 @@ pub struct StrFTime;
impl Command for StrFTime { impl Command for StrFTime {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr strftime" "strftime"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -30,8 +30,8 @@ impl Command for StrFTime {
vec![Example { vec![Example {
description: "Formats date", description: "Formats date",
example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC'); example: r#"let dt = ('2020-08-04T16:39:18+00:00' | into datetime -z 'UTC');
let df = ([$dt $dt] | dfr to-df); let df = ([$dt $dt] | to-df);
$df | dfr strftime "%Y/%m/%d""#, $df | strftime "%Y/%m/%d""#,
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -46,6 +46,14 @@ impl Command for StrFTime {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct ToLowerCase;
impl Command for ToLowerCase { impl Command for ToLowerCase {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-lowercase" "to-lowercase"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ToLowerCase {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Modifies strings to lowercase", description: "Modifies strings to lowercase",
example: "[Abc aBc abC] | dfr to-df | dfr to-lowercase", example: "[Abc aBc abC] | to-df | to-lowercase",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -42,6 +42,14 @@ impl Command for ToLowerCase {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
use polars::prelude::IntoSeries; use polars::prelude::IntoSeries;
@ -12,7 +12,7 @@ pub struct ToUpperCase;
impl Command for ToUpperCase { impl Command for ToUpperCase {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr to-uppercase" "to-uppercase"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ToUpperCase {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Modifies strings to uppercase", description: "Modifies strings to uppercase",
example: "[Abc aBc abC] | dfr to-df | dfr to-uppercase", example: "[Abc aBc abC] | to-df | to-uppercase",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -42,6 +42,14 @@ impl Command for ToUpperCase {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -6,7 +6,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, Value, Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
}; };
use polars::prelude::{IntoSeries, UniqueKeepStrategy}; use polars::prelude::{IntoSeries, UniqueKeepStrategy};
@ -15,11 +15,11 @@ pub struct Unique;
impl Command for Unique { impl Command for Unique {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr unique" "unique"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
"Returns unique values from a series" "Returns unique values from a dataframe"
} }
fn signature(&self) -> Signature { fn signature(&self) -> Signature {
@ -40,14 +40,14 @@ impl Command for Unique {
"Keep the same order as the original DataFrame (lazy df)", "Keep the same order as the original DataFrame (lazy df)",
Some('k'), Some('k'),
) )
.category(Category::Custom("dataframe or expression".into())) .category(Category::Custom("dataframe or lazyframe".into()))
} }
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![ vec![
Example { Example {
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] | to-df | unique",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "0".to_string(),
@ -59,12 +59,20 @@ impl Command for Unique {
}, },
Example { Example {
description: "Creates a is unique expression from a column", description: "Creates a is unique expression from a column",
example: "dfr col a | dfr unique", example: "col a | unique",
result: None, result: None,
}, },
] ]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,
@ -77,16 +85,9 @@ impl Command for Unique {
if NuLazyFrame::can_downcast(&value) { if NuLazyFrame::can_downcast(&value) {
let df = NuLazyFrame::try_from_value(value)?; let df = NuLazyFrame::try_from_value(value)?;
command_lazy(engine_state, stack, call, df) command_lazy(engine_state, stack, call, df)
} else if NuDataFrame::can_downcast(&value) { } else {
let df = NuDataFrame::try_from_value(value)?; let df = NuDataFrame::try_from_value(value)?;
command_eager(engine_state, stack, call, df) command_eager(engine_state, stack, call, df)
} else {
Err(ShellError::CantConvert(
"expression or query".into(),
value.get_type().to_string(),
value.span()?,
None,
))
} }
} }
} }

View File

@ -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, Value, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
}; };
#[derive(Clone)] #[derive(Clone)]
@ -11,7 +11,7 @@ pub struct ValueCount;
impl Command for ValueCount { impl Command for ValueCount {
fn name(&self) -> &str { fn name(&self) -> &str {
"dfr value-counts" "value-counts"
} }
fn usage(&self) -> &str { fn usage(&self) -> &str {
@ -25,7 +25,7 @@ impl Command for ValueCount {
fn examples(&self) -> Vec<Example> { fn examples(&self) -> Vec<Example> {
vec![Example { vec![Example {
description: "Calculates value counts", description: "Calculates value counts",
example: "[5 5 5 5 6 6] | dfr to-df | dfr value-counts", example: "[5 5 5 5 6 6] | to-df | value-counts",
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![ NuDataFrame::try_from_columns(vec![
Column::new( Column::new(
@ -43,6 +43,14 @@ impl Command for ValueCount {
}] }]
} }
fn input_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn output_type(&self) -> Type {
Type::Custom("dataframe".into())
}
fn run( fn run(
&self, &self,
engine_state: &EngineState, engine_state: &EngineState,

View File

@ -6,6 +6,7 @@ use nu_protocol::{
}; };
use super::eager::ToDataFrame; use super::eager::ToDataFrame;
use super::expressions::ExprCol;
use super::lazy::{LazyCollect, ToLazyFrame}; use super::lazy::{LazyCollect, ToLazyFrame};
use crate::Let; use crate::Let;
@ -26,6 +27,7 @@ pub fn test_dataframe(cmds: Vec<Box<dyn Command + 'static>>) {
working_set.add_decl(Box::new(ToDataFrame)); working_set.add_decl(Box::new(ToDataFrame));
working_set.add_decl(Box::new(ToLazyFrame)); working_set.add_decl(Box::new(ToLazyFrame));
working_set.add_decl(Box::new(LazyCollect)); working_set.add_decl(Box::new(LazyCollect));
working_set.add_decl(Box::new(ExprCol));
// Adding the command that is being tested to the working set // Adding the command that is being tested to the working set
for cmd in cmds { for cmd in cmds {

View File

@ -174,7 +174,16 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
let cols = vec!["expr".to_string(), "value".to_string()]; let cols = vec!["expr".to_string(), "value".to_string()];
match expr { match expr {
Expr::Not(_) => todo!(), Expr::Not(expr) => {
let expr = expr_to_value(expr.as_ref(), span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::Alias(expr, alias) => { Expr::Alias(expr, alias) => {
let expr = expr_to_value(expr.as_ref(), span); let expr = expr_to_value(expr.as_ref(), span);
let alias = Value::String { let alias = Value::String {
@ -182,7 +191,7 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
span, span,
}; };
let cols = vec!["expr".to_string(), "alias".to_string()]; let cols = vec!["expr".into(), "alias".into()];
Value::Record { Value::Record {
cols, cols,
@ -192,7 +201,7 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
} }
Expr::Column(name) => { Expr::Column(name) => {
let expr_type = Value::String { let expr_type = Value::String {
val: "column".into(), val: "column".to_string(),
span, span,
}; };
let value = Value::String { let value = Value::String {
@ -222,7 +231,6 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
let vals = vec![expr_type, value]; let vals = vec![expr_type, value];
Value::Record { cols, vals, span } Value::Record { cols, vals, span }
} }
Expr::DtypeColumn(_) => todo!(),
Expr::Literal(literal) => { Expr::Literal(literal) => {
let expr_type = Value::String { let expr_type = Value::String {
val: "literal".into(), val: "literal".into(),
@ -245,7 +253,7 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
span, span,
}; };
let cols = vec!["left".to_string(), "op".to_string(), "right".to_string()]; let cols = vec!["left".into(), "op".into(), "right".into()];
Value::Record { Value::Record {
cols, cols,
@ -262,11 +270,7 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
let truthy = expr_to_value(truthy.as_ref(), span); let truthy = expr_to_value(truthy.as_ref(), span);
let falsy = expr_to_value(falsy.as_ref(), span); let falsy = expr_to_value(falsy.as_ref(), span);
let cols = vec![ let cols = vec!["predicate".into(), "truthy".into(), "falsy".into()];
"predicate".to_string(),
"truthy".to_string(),
"falsy".to_string(),
];
Value::Record { Value::Record {
cols, cols,
@ -289,7 +293,29 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
| AggExpr::AggGroups(expr) | AggExpr::AggGroups(expr)
| AggExpr::Std(expr) | AggExpr::Std(expr)
| AggExpr::Var(expr) => expr_to_value(expr.as_ref(), span), | AggExpr::Var(expr) => expr_to_value(expr.as_ref(), span),
AggExpr::Quantile { .. } => todo!(), AggExpr::Quantile {
expr,
quantile,
interpol,
} => {
let expr = expr_to_value(expr.as_ref(), span);
let quantile = Value::Float {
val: *quantile,
span,
};
let interpol = Value::String {
val: format!("{:?}", interpol),
span,
};
let cols = vec!["expr".into(), "quantile".into(), "interpol".into()];
Value::Record {
cols,
vals: vec![expr, quantile, interpol],
span,
}
}
}; };
let expr_type = Value::String { let expr_type = Value::String {
@ -300,27 +326,371 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Value {
let vals = vec![expr_type, value]; let vals = vec![expr_type, value];
Value::Record { cols, vals, span } Value::Record { cols, vals, span }
} }
Expr::IsNotNull(_) => todo!(), Expr::IsNotNull(expr) => {
Expr::IsNull(_) => todo!(), let expr = expr_to_value(expr.as_ref(), span);
Expr::Cast { .. } => todo!(), let cols = vec!["expr".into()];
Expr::Sort { .. } => todo!(),
Expr::Take { .. } => todo!(), Value::Record {
Expr::SortBy { .. } => todo!(), cols,
Expr::Function { .. } => todo!(), vals: vec![expr],
Expr::Shift { .. } => todo!(), span,
Expr::Reverse(_) => todo!(), }
Expr::Duplicated(_) => todo!(), }
Expr::IsUnique(_) => todo!(), Expr::IsNull(expr) => {
Expr::Explode(_) => todo!(), let expr = expr_to_value(expr.as_ref(), span);
Expr::Filter { .. } => todo!(), let cols = vec!["expr".into()];
Expr::Window { .. } => todo!(),
Expr::Wildcard => todo!(), Value::Record {
Expr::Slice { .. } => todo!(), cols,
Expr::Exclude(_, _) => todo!(), vals: vec![expr],
Expr::KeepName(_) => todo!(), span,
Expr::RenameAlias { .. } => todo!(), }
Expr::Count => todo!(), }
Expr::Nth(_) => todo!(), Expr::Count => {
Expr::AnonymousFunction { .. } => todo!(), let expr = Value::String {
val: "count".into(),
span,
};
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::Wildcard => {
let expr = Value::String {
val: "wildcard".into(),
span,
};
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::Reverse(expr) => {
let expr = expr_to_value(expr.as_ref(), span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::Duplicated(expr) => {
let expr = expr_to_value(expr.as_ref(), span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::IsUnique(expr) => {
let expr = expr_to_value(expr.as_ref(), span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::Explode(expr) => {
let expr = expr_to_value(expr.as_ref(), span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::KeepName(expr) => {
let expr = expr_to_value(expr.as_ref(), span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::Nth(i) => {
let expr = Value::int(*i, span);
let cols = vec!["expr".into()];
Value::Record {
cols,
vals: vec![expr],
span,
}
}
Expr::DtypeColumn(dtypes) => {
let vals = dtypes
.iter()
.map(|d| Value::String {
val: format!("{}", d),
span,
})
.collect();
Value::List { vals, span }
}
Expr::Sort { expr, options } => {
let expr = expr_to_value(expr.as_ref(), span);
let options = Value::String {
val: format!("{:?}", options),
span,
};
let cols = vec!["expr".into(), "options".into()];
Value::Record {
cols,
vals: vec![expr, options],
span,
}
}
Expr::Cast {
expr,
data_type,
strict,
} => {
let expr = expr_to_value(expr.as_ref(), span);
let dtype = Value::String {
val: format!("{:?}", data_type),
span,
};
let strict = Value::Bool { val: *strict, span };
let cols = vec!["expr".into(), "dtype".into(), "strict".into()];
Value::Record {
cols,
vals: vec![expr, dtype, strict],
span,
}
}
Expr::Take { expr, idx } => {
let expr = expr_to_value(expr.as_ref(), span);
let idx = expr_to_value(idx.as_ref(), span);
let cols = vec!["expr".into(), "idx".into()];
Value::Record {
cols,
vals: vec![expr, idx],
span,
}
}
Expr::SortBy { expr, by, reverse } => {
let expr = expr_to_value(expr.as_ref(), span);
let by: Vec<Value> = by.iter().map(|b| expr_to_value(b, span)).collect();
let by = Value::List { vals: by, span };
let reverse: Vec<Value> = reverse
.iter()
.map(|r| Value::Bool { val: *r, span })
.collect();
let reverse = Value::List {
vals: reverse,
span,
};
let cols = vec!["expr".into(), "by".into(), "reverse".into()];
Value::Record {
cols,
vals: vec![expr, by, reverse],
span,
}
}
Expr::Shift { input, periods } => {
let expr = expr_to_value(input.as_ref(), span);
let periods = Value::Int {
val: *periods,
span,
};
let cols = vec!["expr".into(), "periods".into()];
Value::Record {
cols,
vals: vec![expr, periods],
span,
}
}
Expr::Filter { input, by } => {
let input = expr_to_value(input.as_ref(), span);
let by = expr_to_value(by.as_ref(), span);
let cols = vec!["input".into(), "by".into()];
Value::Record {
cols,
vals: vec![input, by],
span,
}
}
Expr::Slice {
input,
offset,
length,
} => {
let input = expr_to_value(input.as_ref(), span);
let offset = expr_to_value(offset.as_ref(), span);
let length = expr_to_value(length.as_ref(), span);
let cols = vec!["input".into(), "offset".into(), "length".into()];
Value::Record {
cols,
vals: vec![input, offset, length],
span,
}
}
Expr::Exclude(expr, excluded) => {
let expr = expr_to_value(expr.as_ref(), span);
let excluded = excluded
.iter()
.map(|e| Value::String {
val: format!("{:?}", e),
span,
})
.collect();
let excluded = Value::List {
vals: excluded,
span,
};
let cols = vec!["expr".into(), "excluded".into()];
Value::Record {
cols,
vals: vec![expr, excluded],
span,
}
}
Expr::RenameAlias { expr, function } => {
let expr = expr_to_value(expr.as_ref(), span);
let function = Value::String {
val: format!("{:?}", function),
span,
};
let cols = vec!["expr".into(), "function".into()];
Value::Record {
cols,
vals: vec![expr, function],
span,
}
}
Expr::AnonymousFunction {
input,
function,
output_type,
options,
} => {
let input: Vec<Value> = input.iter().map(|e| expr_to_value(e, span)).collect();
let input = Value::List { vals: input, span };
let function = Value::String {
val: format!("{:?}", function),
span,
};
let output_type = Value::String {
val: format!("{:?}", output_type),
span,
};
let options = Value::String {
val: format!("{:?}", options),
span,
};
let cols = vec![
"input".into(),
"function".into(),
"output_type".into(),
"options".into(),
];
Value::Record {
cols,
vals: vec![input, function, output_type, options],
span,
}
}
Expr::Function {
input,
function,
options,
} => {
let input: Vec<Value> = input.iter().map(|e| expr_to_value(e, span)).collect();
let input = Value::List { vals: input, span };
let function = Value::String {
val: format!("{:?}", function),
span,
};
let options = Value::String {
val: format!("{:?}", options),
span,
};
let cols = vec!["input".into(), "function".into(), "options".into()];
Value::Record {
cols,
vals: vec![input, function, options],
span,
}
}
Expr::Window {
function,
partition_by,
order_by,
options,
} => {
let function = expr_to_value(function, span);
let partition_by: Vec<Value> = partition_by
.iter()
.map(|e| expr_to_value(e, span))
.collect();
let partition_by = Value::List {
vals: partition_by,
span,
};
let order_by = order_by
.as_ref()
.map(|e| expr_to_value(e.as_ref(), span))
.unwrap_or_else(|| Value::nothing(span));
let options = Value::String {
val: format!("{:?}", options),
span,
};
let cols = vec![
"function".into(),
"partition_by".into(),
"order_by".into(),
"options".into(),
];
Value::Record {
cols,
vals: vec![function, partition_by, order_by, options],
span,
}
}
} }
} }

View File

@ -400,9 +400,6 @@ pub fn create_default_context(cwd: impl AsRef<Path>) -> EngineState {
KeepWhileDeprecated, KeepWhileDeprecated,
}; };
#[cfg(feature = "dataframe")]
bind_command!(DataframeDeprecated);
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
bind_command!(Register); bind_command!(Register);

View File

@ -1,36 +0,0 @@
use nu_protocol::{
ast::Call,
engine::{Command, EngineState, Stack},
Category, PipelineData, Signature,
};
#[derive(Clone)]
pub struct DataframeDeprecated;
impl Command for DataframeDeprecated {
fn name(&self) -> &str {
"dataframe"
}
fn signature(&self) -> Signature {
Signature::build(self.name()).category(Category::Deprecated)
}
fn usage(&self) -> &str {
"Deprecated command"
}
fn run(
&self,
_engine_state: &EngineState,
_stack: &mut Stack,
call: &Call,
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
Err(nu_protocol::ShellError::DeprecatedCommand(
self.name().to_string(),
"dfr".to_string(),
call.head,
))
}
}

View File

@ -21,9 +21,3 @@ pub use str_decimal::StrDecimalDeprecated;
pub use str_find_replace::StrFindReplaceDeprecated; pub use str_find_replace::StrFindReplaceDeprecated;
pub use str_int::StrIntDeprecated; pub use str_int::StrIntDeprecated;
pub use unalias::UnaliasDeprecated; pub use unalias::UnaliasDeprecated;
#[cfg(feature = "dataframe")]
mod dataframe;
#[cfg(feature = "dataframe")]
pub use dataframe::DataframeDeprecated;

View File

@ -21,7 +21,7 @@ use crate::{
parser::{ parser::{
check_call, check_name, garbage, garbage_pipeline, parse, parse_block_expression, check_call, check_name, garbage, garbage_pipeline, parse, parse_block_expression,
parse_internal_call, parse_multispan_value, parse_signature, parse_string, parse_internal_call, parse_multispan_value, parse_signature, parse_string,
parse_var_with_opt_type, trim_quotes, parse_var_with_opt_type, trim_quotes, ParsedInternalCall,
}, },
unescape_unquote_string, ParseError, unescape_unquote_string, ParseError,
}; };
@ -127,13 +127,18 @@ pub fn parse_for(
} }
Some(decl_id) => { Some(decl_id) => {
working_set.enter_scope(); working_set.enter_scope();
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
decl_id, decl_id,
expand_aliases_denylist, expand_aliases_denylist,
); );
working_set.exit_scope(); working_set.exit_scope();
let call_span = span(spans); let call_span = span(spans);
@ -165,7 +170,7 @@ pub fn parse_for(
Expression { Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}, },
err, err,
@ -296,13 +301,18 @@ pub fn parse_def(
} }
Some(decl_id) => { Some(decl_id) => {
working_set.enter_scope(); working_set.enter_scope();
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
decl_id, decl_id,
expand_aliases_denylist, expand_aliases_denylist,
); );
working_set.exit_scope(); working_set.exit_scope();
let call_span = span(spans); let call_span = span(spans);
@ -334,7 +344,7 @@ pub fn parse_def(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -439,7 +449,9 @@ pub fn parse_extern(
} }
Some(decl_id) => { Some(decl_id) => {
working_set.enter_scope(); working_set.enter_scope();
let (call, err) = parse_internal_call( let ParsedInternalCall {
call, error: err, ..
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -521,7 +533,7 @@ pub fn parse_alias(
} }
if let Some(decl_id) = working_set.find_decl(b"alias", &Type::Any) { if let Some(decl_id) = working_set.find_decl(b"alias", &Type::Any) {
let (call, _) = parse_internal_call( let ParsedInternalCall { call, output, .. } = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -534,7 +546,7 @@ pub fn parse_alias(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: span(spans), span: span(spans),
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
None, None,
@ -1243,7 +1255,11 @@ pub fn parse_use(
let (call, call_span, use_decl_id) = match working_set.find_decl(b"use", &Type::Any) { let (call, call_span, use_decl_id) = match working_set.find_decl(b"use", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -1260,7 +1276,7 @@ pub fn parse_use(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -1476,7 +1492,11 @@ pub fn parse_hide(
let (call, call_span, hide_decl_id) = match working_set.find_decl(b"hide", &Type::Any) { let (call, call_span, hide_decl_id) = match working_set.find_decl(b"hide", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -1493,7 +1513,7 @@ pub fn parse_hide(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -1701,7 +1721,11 @@ pub fn parse_overlay(
// TODO: Abstract this code blob, it's repeated all over the place: // TODO: Abstract this code blob, it's repeated all over the place:
let call = match working_set.find_decl(b"overlay list", &Type::Any) { let call = match working_set.find_decl(b"overlay list", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
span(&spans[..2]), span(&spans[..2]),
if spans.len() > 2 { &spans[2..] } else { &[] }, if spans.len() > 2 { &spans[2..] } else { &[] },
@ -1718,7 +1742,7 @@ pub fn parse_overlay(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -1760,7 +1784,11 @@ pub fn parse_overlay(
let call = match working_set.find_decl(b"overlay", &Type::Any) { let call = match working_set.find_decl(b"overlay", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -1777,7 +1805,7 @@ pub fn parse_overlay(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -1825,7 +1853,11 @@ pub fn parse_overlay_new(
let (call, call_span) = match working_set.find_decl(b"overlay new", &Type::Any) { let (call, call_span) = match working_set.find_decl(b"overlay new", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
span(&spans[0..2]), span(&spans[0..2]),
&spans[2..], &spans[2..],
@ -1842,7 +1874,7 @@ pub fn parse_overlay_new(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -1916,7 +1948,11 @@ pub fn parse_overlay_add(
// TODO: Allow full import pattern as argument (requires custom naming of module/overlay) // TODO: Allow full import pattern as argument (requires custom naming of module/overlay)
let (call, call_span) = match working_set.find_decl(b"overlay add", &Type::Any) { let (call, call_span) = match working_set.find_decl(b"overlay add", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
span(&spans[0..2]), span(&spans[0..2]),
&spans[2..], &spans[2..],
@ -1933,7 +1969,7 @@ pub fn parse_overlay_add(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -2103,7 +2139,11 @@ pub fn parse_overlay_remove(
let call = match working_set.find_decl(b"overlay remove", &Type::Any) { let call = match working_set.find_decl(b"overlay remove", &Type::Any) {
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
span(&spans[0..2]), span(&spans[0..2]),
&spans[2..], &spans[2..],
@ -2120,7 +2160,7 @@ pub fn parse_overlay_remove(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,
@ -2247,7 +2287,6 @@ pub fn parse_let(
error = error.or(err); error = error.or(err);
let var_id = lvalue.as_var(); let var_id = lvalue.as_var();
let rhs_type = rvalue.ty.clone(); let rhs_type = rvalue.ty.clone();
if let Some(var_id) = var_id { if let Some(var_id) = var_id {
@ -2277,7 +2316,11 @@ pub fn parse_let(
} }
} }
} }
let (call, err) = parse_internal_call( let ParsedInternalCall {
call,
error: err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -2290,7 +2333,7 @@ pub fn parse_let(
expressions: vec![Expression { expressions: vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: nu_protocol::span(spans), span: nu_protocol::span(spans),
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}], }],
}, },
@ -2320,7 +2363,11 @@ pub fn parse_source(
let cwd = working_set.get_cwd(); let cwd = working_set.get_cwd();
// Is this the right call to be using here? // Is this the right call to be using here?
// Some of the others (`parse_let`) use it, some of them (`parse_hide`) don't. // Some of the others (`parse_let`) use it, some of them (`parse_hide`) don't.
let (call, err) = parse_internal_call( let ParsedInternalCall {
call,
error: err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -2334,7 +2381,7 @@ pub fn parse_source(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: span(spans), span: span(spans),
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
error, error,
@ -2459,7 +2506,11 @@ pub fn parse_register(
) )
} }
Some(decl_id) => { Some(decl_id) => {
let (call, mut err) = parse_internal_call( let ParsedInternalCall {
call,
error: mut err,
output,
} = parse_internal_call(
working_set, working_set,
spans[0], spans[0],
&spans[1..], &spans[1..],
@ -2476,7 +2527,7 @@ pub fn parse_register(
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(call),
span: call_span, span: call_span,
ty: Type::Any, ty: output,
custom_completion: None, custom_completion: None,
}]), }]),
err, err,

View File

@ -724,13 +724,19 @@ pub fn parse_multispan_value(
} }
} }
pub struct ParsedInternalCall {
pub call: Box<Call>,
pub output: Type,
pub error: Option<ParseError>,
}
pub fn parse_internal_call( pub fn parse_internal_call(
working_set: &mut StateWorkingSet, working_set: &mut StateWorkingSet,
command_span: Span, command_span: Span,
spans: &[Span], spans: &[Span],
decl_id: usize, decl_id: usize,
expand_aliases_denylist: &[usize], expand_aliases_denylist: &[usize],
) -> (Box<Call>, Option<ParseError>) { ) -> ParsedInternalCall {
trace!("parsing: internal call (decl id: {})", decl_id); trace!("parsing: internal call (decl id: {})", decl_id);
let mut error = None; let mut error = None;
@ -742,7 +748,8 @@ pub fn parse_internal_call(
let decl = working_set.get_decl(decl_id); let decl = working_set.get_decl(decl_id);
let signature = decl.signature(); let signature = decl.signature();
let output = decl.output_type(); let output = decl.output_type();
working_set.found_outputs.push(output);
working_set.type_scope.add_type(output.clone());
if signature.creates_scope { if signature.creates_scope {
working_set.enter_scope(); working_set.enter_scope();
@ -925,8 +932,11 @@ pub fn parse_internal_call(
working_set.exit_scope(); working_set.exit_scope();
} }
// FIXME: output type unknown ParsedInternalCall {
(Box::new(call), error) call: Box::new(call),
output,
error,
}
} }
pub fn parse_call( pub fn parse_call(
@ -1012,7 +1022,7 @@ pub fn parse_call(
pos += 1; pos += 1;
} }
let input = working_set.found_outputs.last().unwrap_or(&Type::Any); let input = working_set.type_scope.get_previous();
let mut maybe_decl_id = working_set.find_decl(&name, input); let mut maybe_decl_id = working_set.find_decl(&name, input);
while maybe_decl_id.is_none() { while maybe_decl_id.is_none() {
@ -1060,21 +1070,22 @@ pub fn parse_call(
trace!("parsing: internal call"); trace!("parsing: internal call");
// parse internal command // parse internal command
let (call, err) = parse_internal_call( let parsed_call = parse_internal_call(
working_set, working_set,
span(&spans[cmd_start..pos]), span(&spans[cmd_start..pos]),
&spans[pos..], &spans[pos..],
decl_id, decl_id,
expand_aliases_denylist, expand_aliases_denylist,
); );
( (
Expression { Expression {
expr: Expr::Call(call), expr: Expr::Call(parsed_call.call),
span: span(spans), span: span(spans),
ty: Type::Any, // FIXME: calls should have known output types ty: parsed_call.output,
custom_completion: None, custom_completion: None,
}, },
err, parsed_call.error,
) )
} else { } else {
// We might be parsing left-unbounded range ("..10") // We might be parsing left-unbounded range ("..10")
@ -1853,8 +1864,14 @@ pub fn parse_full_cell_path(
let (output, err) = lite_parse(&output); let (output, err) = lite_parse(&output);
error = error.or(err); error = error.or(err);
// Creating a Type scope to parse the new block. This will keep track of
// the previous input type found in that block
let (output, err) = let (output, err) =
parse_block(working_set, &output, true, expand_aliases_denylist, true); parse_block(working_set, &output, true, expand_aliases_denylist, true);
working_set
.type_scope
.add_type(working_set.type_scope.get_last_output());
error = error.or(err); error = error.or(err);
let block_id = working_set.add_block(output); let block_id = working_set.add_block(output);
@ -1864,7 +1881,7 @@ pub fn parse_full_cell_path(
Expression { Expression {
expr: Expr::Subexpression(block_id), expr: Expr::Subexpression(block_id),
span: head_span, span: head_span,
ty: Type::Any, // FIXME ty: working_set.type_scope.get_last_output(),
custom_completion: None, custom_completion: None,
}, },
true, true,
@ -1929,8 +1946,8 @@ pub fn parse_full_cell_path(
if !tail.is_empty() { if !tail.is_empty() {
( (
Expression { Expression {
ty: head.ty.clone(), // FIXME. How to access the last type of tail?
expr: Expr::FullCellPath(Box::new(FullCellPath { head, tail })), expr: Expr::FullCellPath(Box::new(FullCellPath { head, tail })),
ty: Type::Any,
span: full_cell_span, span: full_cell_span,
custom_completion: None, custom_completion: None,
}, },
@ -4581,6 +4598,9 @@ pub fn parse_variable(
if is_variable(bytes) { if is_variable(bytes) {
if let Some(var_id) = working_set.find_variable(bytes) { if let Some(var_id) = working_set.find_variable(bytes) {
let input = working_set.get_variable(var_id).ty.clone();
working_set.type_scope.add_type(input);
(Some(var_id), None) (Some(var_id), None)
} else { } else {
(None, None) (None, None)
@ -4612,19 +4632,20 @@ pub fn parse_builtin_commands(
b"source" => parse_source(working_set, &lite_command.parts, expand_aliases_denylist), b"source" => parse_source(working_set, &lite_command.parts, expand_aliases_denylist),
b"export" => { b"export" => {
if let Some(decl_id) = working_set.find_decl(b"alias", &Type::Any) { if let Some(decl_id) = working_set.find_decl(b"alias", &Type::Any) {
let (call, _) = parse_internal_call( let parsed_call = parse_internal_call(
working_set, working_set,
lite_command.parts[0], lite_command.parts[0],
&lite_command.parts[1..], &lite_command.parts[1..],
decl_id, decl_id,
expand_aliases_denylist, expand_aliases_denylist,
); );
if call.has_flag("help") {
if parsed_call.call.has_flag("help") {
( (
Pipeline::from_vec(vec![Expression { Pipeline::from_vec(vec![Expression {
expr: Expr::Call(call), expr: Expr::Call(parsed_call.call),
span: span(&lite_command.parts), span: span(&lite_command.parts),
ty: Type::Any, ty: parsed_call.output,
custom_completion: None, custom_completion: None,
}]), }]),
None, None,
@ -4759,6 +4780,7 @@ pub fn parse_block(
if scoped { if scoped {
working_set.enter_scope(); working_set.enter_scope();
} }
working_set.type_scope.enter_scope();
let mut error = None; let mut error = None;
@ -4789,6 +4811,8 @@ pub fn parse_block(
let (expr, err) = let (expr, err) =
parse_expression(working_set, &command.parts, expand_aliases_denylist); parse_expression(working_set, &command.parts, expand_aliases_denylist);
working_set.type_scope.add_type(expr.ty.clone());
if error.is_none() { if error.is_none() {
error = err; error = err;
} }
@ -4872,6 +4896,7 @@ pub fn parse_block(
if scoped { if scoped {
working_set.exit_scope(); working_set.exit_scope();
} }
working_set.type_scope.exit_scope();
(block, error) (block, error)
} }

Some files were not shown because too many files have changed in this diff Show More