Dataframe commands name (#457)

* corrected missing shellerror type

* batch dataframe commands

* removed option to find declaration with input

* ordered dataframe folders

* dataframe command name
This commit is contained in:
Fernando Herrera 2021-12-10 00:17:11 +00:00 committed by GitHub
parent 7319b6b168
commit 865906e450
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 64 additions and 22 deletions

View file

@ -12,7 +12,7 @@ pub struct AppendDF;
impl Command for AppendDF {
fn name(&self) -> &str {
"append-df"
"dataframe append"
}
fn usage(&self) -> &str {
@ -30,8 +30,8 @@ impl Command for AppendDF {
vec![
Example {
description: "Appends a dataframe as new columns",
example: r#"let a = ([[a b]; [1 2] [3 4]] | to df);
$a | append-df $a"#,
example: r#"let a = ([[a b]; [1 2] [3 4]] | dataframe to-df);
$a | dataframe append $a"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![1.into(), 3.into()]),
@ -46,8 +46,8 @@ $a | append-df $a"#,
Example {
description: "Appends a dataframe merging at the end of columns",
//example: r#"let a = ([[a b]; [1 2] [3 4]] | to df); $a | append-df $a -col"#,
example: r#"let a = ([[a b]; [1 2] [3 4]] | to df);
$a | append-df $a --col"#,
example: r#"let a = ([[a b]; [1 2] [3 4]] | dataframe to-df);
$a | dataframe append $a --col"#,
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(

View file

@ -12,7 +12,7 @@ pub struct ColumnDF;
impl Command for ColumnDF {
fn name(&self) -> &str {
"column"
"dataframe column"
}
fn usage(&self) -> &str {
@ -28,7 +28,7 @@ impl Command for ColumnDF {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Returns the selected column as series",
example: "[[a b]; [1 2] [3 4]] | to df | column a",
example: "[[a b]; [1 2] [3 4]] | dataframe to-df | dataframe column a",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"a".to_string(),

View file

@ -0,0 +1,37 @@
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 {
"dataframe"
}
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),
span: call.head,
}
.into_pipeline_data())
}
}

View file

@ -17,7 +17,7 @@ pub struct DescribeDF;
impl Command for DescribeDF {
fn name(&self) -> &str {
"describe-df"
"dataframe describe"
}
fn usage(&self) -> &str {
@ -31,7 +31,7 @@ impl Command for DescribeDF {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "dataframe description",
example: "[[a b]; [1 1] [1 1]] | to df | describe-df",
example: "[[a b]; [1 1] [1 1]] | dataframe to-df | dataframe describe",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(

View file

@ -13,7 +13,7 @@ pub struct DropDF;
impl Command for DropDF {
fn name(&self) -> &str {
"drop-df"
"dataframe drop"
}
fn usage(&self) -> &str {
@ -29,7 +29,7 @@ impl Command for DropDF {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "drop column a",
example: "[[a b]; [1 2] [3 4]] | to df | drop-df a",
example: "[[a b]; [1 2] [3 4]] | dataframe to-df | dataframe drop a",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"b".to_string(),

View file

@ -10,7 +10,7 @@ pub struct DataTypes;
impl Command for DataTypes {
fn name(&self) -> &str {
"dtypes"
"dataframe dtypes"
}
fn usage(&self) -> &str {
@ -24,7 +24,7 @@ impl Command for DataTypes {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Dataframe dtypes",
example: "[[a b]; [1 2] [3 4]] | to df | dtypes",
example: "[[a b]; [1 2] [3 4]] | dataframe to-df | dataframe dtypes",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(

View file

@ -1,7 +1,9 @@
mod series;
mod values;
mod append;
mod column;
mod command;
mod describe;
mod drop;
mod dtypes;
@ -10,6 +12,7 @@ mod to_df;
pub use append::AppendDF;
pub use column::ColumnDF;
pub use command::Dataframe;
pub use describe::DescribeDF;
pub use drop::DropDF;
pub use dtypes::DataTypes;
@ -31,6 +34,7 @@ pub fn add_dataframe_decls(working_set: &mut StateWorkingSet) {
bind_command!(
AppendDF,
ColumnDF,
Dataframe,
DataTypes,
DescribeDF,
DropDF,

View file

@ -14,7 +14,7 @@ pub struct OpenDataFrame;
impl Command for OpenDataFrame {
fn name(&self) -> &str {
"open-df"
"dataframe open"
}
fn usage(&self) -> &str {
@ -63,7 +63,7 @@ impl Command for OpenDataFrame {
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Takes a file name and creates a dataframe",
example: "open-df test.csv",
example: "dataframe open test.csv",
result: None,
}]
}

View file

@ -0,0 +1 @@

View file

@ -11,7 +11,7 @@ pub struct ToDataFrame;
impl Command for ToDataFrame {
fn name(&self) -> &str {
"to df"
"dataframe to-df"
}
fn usage(&self) -> &str {
@ -26,7 +26,7 @@ impl Command for ToDataFrame {
vec![
Example {
description: "Takes a dictionary and creates a dataframe",
example: "[[a b];[1 2] [3 4]] | to df",
example: "[[a b];[1 2] [3 4]] | dataframe to-df",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![1.into(), 3.into()]),
@ -38,7 +38,7 @@ impl Command for ToDataFrame {
},
Example {
description: "Takes a list of tables and creates a dataframe",
example: "[[1 2 a] [3 4 b] [5 6 c]] | to df",
example: "[[1 2 a] [3 4 b] [5 6 c]] | dataframe to-df",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("0".to_string(), vec![1.into(), 3.into(), 5.into()]),
@ -58,7 +58,7 @@ impl Command for ToDataFrame {
},
Example {
description: "Takes a list and creates a dataframe",
example: "[a b c] | to df",
example: "[a b c] | dataframe to-df",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
@ -74,7 +74,7 @@ impl Command for ToDataFrame {
},
Example {
description: "Takes a list of booleans and creates a dataframe",
example: "[$true $true $false] | to df",
example: "[$true $true $false] | dataframe to-df",
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),

View file

@ -273,7 +273,7 @@ fn get_flags_section(signature: &Signature) -> String {
if let Some(short) = flag.short {
if flag.required {
format!(
" -{}{} (required parameter){:?} {}\n",
" -{}{} (required parameter) {:?} {}\n",
short,
if !flag.long.is_empty() {
format!(", --{}", flag.long)
@ -298,7 +298,7 @@ fn get_flags_section(signature: &Signature) -> String {
}
} else if flag.required {
format!(
" --{} (required parameter){:?} {}\n",
" --{} (required parameter) {:?} {}\n",
flag.long, arg, flag.desc
)
} else {