mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 21:27:45 +02:00
Dataframe commands (#3502)
* Sample command * Join command with checks * More dataframes commands * Groupby and aggregate commands * Missing feature dataframe flag * Renamed file * New commands for dataframes * error parser and df reference * filter command for dataframes * removed name from nu_dataframe * commands to save to parquet and csv
This commit is contained in:
@ -46,15 +46,11 @@ type ColumnMap = HashMap<String, ColumnValues>;
|
||||
pub struct NuDataFrame {
|
||||
#[serde(skip_serializing)]
|
||||
pub dataframe: Option<DataFrame>,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Default for NuDataFrame {
|
||||
fn default() -> Self {
|
||||
NuDataFrame {
|
||||
dataframe: None,
|
||||
name: String::from("From Stream"),
|
||||
}
|
||||
NuDataFrame { dataframe: None }
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,14 +58,6 @@ impl NuDataFrame {
|
||||
pub fn new(df: polars::prelude::DataFrame) -> Self {
|
||||
NuDataFrame {
|
||||
dataframe: Some(df),
|
||||
name: String::from("dataframe"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_name(df: polars::prelude::DataFrame, name: String) -> Self {
|
||||
NuDataFrame {
|
||||
dataframe: Some(df),
|
||||
name,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -225,6 +213,24 @@ impl NuDataFrame {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<polars::prelude::DataFrame> for NuDataFrame {
|
||||
fn as_ref(&self) -> &polars::prelude::DataFrame {
|
||||
match &self.dataframe {
|
||||
Some(df) => df,
|
||||
None => unreachable!("Accessing ref to dataframe from nu_dataframe"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<polars::prelude::DataFrame> for NuDataFrame {
|
||||
fn as_mut(&mut self) -> &mut polars::prelude::DataFrame {
|
||||
match &mut self.dataframe {
|
||||
Some(df) => df,
|
||||
None => unreachable!("Accessing mut ref to dataframe from nu_dataframe"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adds a separator to the vector of values using the column names from the
|
||||
// dataframe to create the Values Row
|
||||
fn add_separator(values: &mut Vec<Value>, df: &DataFrame) {
|
||||
@ -430,7 +436,6 @@ fn from_parsed_columns(column_values: ColumnMap, tag: &Tag) -> Result<NuDataFram
|
||||
match df {
|
||||
Ok(df) => Ok(NuDataFrame {
|
||||
dataframe: Some(df),
|
||||
name: "From stream".to_string(),
|
||||
}),
|
||||
Err(e) => {
|
||||
return Err(ShellError::labeled_error(
|
||||
|
@ -39,11 +39,6 @@ impl NuGroupBy {
|
||||
pub fn print(&self) -> Result<Vec<Value>, ShellError> {
|
||||
let mut values: Vec<Value> = Vec::new();
|
||||
|
||||
let mut data = TaggedDictBuilder::new(Tag::unknown());
|
||||
data.insert_value("property", "dataframe");
|
||||
data.insert_value("value", self.dataframe.name.as_ref());
|
||||
values.push(data.into_value());
|
||||
|
||||
let mut data = TaggedDictBuilder::new(Tag::unknown());
|
||||
data.insert_value("property", "group by");
|
||||
data.insert_value("value", self.by.join(", "));
|
||||
@ -52,3 +47,12 @@ impl NuGroupBy {
|
||||
Ok(values)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<polars::prelude::DataFrame> for NuGroupBy {
|
||||
fn as_ref(&self) -> &polars::prelude::DataFrame {
|
||||
match &self.dataframe.dataframe {
|
||||
Some(df) => df,
|
||||
None => unreachable!("Accessing reference to dataframe from nu_groupby"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user