Polars command reorg (#13798)

# Description
House keeping. Restructures polars modules as discussed in:
https://docs.google.com/spreadsheets/d/1gyA58i_yTXKCJ5DbO_RxBNAlK6S7C1M22ppKwVLZltc/edit?usp=sharing
This commit is contained in:
Jack Wright 2024-09-06 13:46:37 -07:00 committed by GitHub
parent edd69aa283
commit f531cc2058
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
127 changed files with 958 additions and 918 deletions

View File

@ -1,263 +1,10 @@
/// Definition of multiple Expression commands using a macro rule
/// All of these expressions have an identical body and only require
/// to have a change in the name, description and expression function
use crate::dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame};
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use crate::{expr_command, lazy_expr_command};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{Category, Example, LabeledError, PipelineData, Signature, Span, Type, Value};
// The structs defined in this file are structs that form part of other commands
// since they share a similar name
macro_rules! expr_command {
($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident, $test: ident) => {
#[derive(Clone)]
pub struct $command;
impl PluginCommand for $command {
type Plugin = PolarsPlugin;
fn name(&self) -> &str {
$name
}
fn description(&self) -> &str {
$desc
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.description($desc)
.input_output_type(
Type::Custom("expression".into()),
Type::Custom("expression".into()),
)
.category(Category::Custom("expression".into()))
}
fn examples(&self) -> Vec<Example> {
$examples
}
fn run(
&self,
plugin: &Self::Plugin,
engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,
) -> Result<PipelineData, LabeledError> {
let expr = NuExpression::try_from_pipeline(plugin, input, call.head)
.map_err(LabeledError::from)?;
let expr: NuExpression = expr.into_polars().$func().into();
expr.to_pipeline_data(plugin, engine, call.head)
.map_err(LabeledError::from)
}
}
#[cfg(test)]
mod $test {
use super::*;
use crate::test::test_polars_plugin_command;
use nu_protocol::ShellError;
#[test]
fn test_examples() -> Result<(), ShellError> {
test_polars_plugin_command(&$command)
}
}
};
($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident, $test: ident, $ddof: expr) => {
#[derive(Clone)]
pub struct $command;
impl PluginCommand for $command {
type Plugin = PolarsPlugin;
fn signature(&self) -> Signature {
Signature::build(self.name())
.description($desc)
.input_output_type(
Type::Custom("expression".into()),
Type::Custom("expression".into()),
)
.category(Category::Custom("expression".into()))
.plugin_examples($examples)
}
fn run(
&self,
_plugin: &Self::Plugin,
engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,
) -> Result<PipelineData, LabeledError> {
let expr = NuExpression::try_from_pipeline(input, call.head)
.map_err(LabeledError::from)?;
let expr: NuExpression = expr.into_polars().$func($ddof).into();
expr.to_pipeline_data(plugin, engine, call.head)
.map_err(LabeledError::from)
}
}
#[cfg(test)]
mod $test {
use super::*;
use crate::test::test_polars_plugin_command;
#[test]
fn test_examples() -> Result<(), ShellError> {
test_polars_plugin_command(&$command)
}
}
};
}
// The structs defined in this file are structs that form part of other commands
// since they share a similar name
macro_rules! lazy_expr_command {
($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident, $test: ident) => {
#[derive(Clone)]
pub struct $command;
impl PluginCommand for $command {
type Plugin = PolarsPlugin;
fn name(&self) -> &str {
$name
}
fn description(&self) -> &str {
$desc
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.description($desc)
.input_output_types(vec![
(
Type::Custom("expression".into()),
Type::Custom("expression".into()),
),
(
Type::Custom("dataframe".into()),
Type::Custom("dataframe".into()),
),
])
.category(Category::Custom("expression".into()))
}
fn examples(&self) -> Vec<Example> {
$examples
}
fn run(
&self,
plugin: &Self::Plugin,
engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,
) -> Result<PipelineData, LabeledError> {
let value = input.into_value(call.head)?;
if NuDataFrame::can_downcast(&value) || NuLazyFrame::can_downcast(&value) {
let lazy = NuLazyFrame::try_from_value_coerce(plugin, &value)
.map_err(LabeledError::from)?;
let lazy = NuLazyFrame::new(lazy.from_eager, lazy.to_polars().$func());
lazy.to_pipeline_data(plugin, engine, call.head)
.map_err(LabeledError::from)
} else {
let expr =
NuExpression::try_from_value(plugin, &value).map_err(LabeledError::from)?;
let expr: NuExpression = expr.into_polars().$func().into();
expr.to_pipeline_data(plugin, engine, call.head)
.map_err(LabeledError::from)
}
}
}
#[cfg(test)]
mod $test {
use super::*;
use crate::test::test_polars_plugin_command;
use nu_protocol::ShellError;
#[test]
fn test_examples() -> Result<(), ShellError> {
test_polars_plugin_command(&$command)
}
}
};
($command: ident, $name: expr, $desc: expr, $examples: expr, $func: ident, $test: ident, $ddof: expr) => {
#[derive(Clone)]
pub struct $command;
impl PluginCommand for $command {
type Plugin = PolarsPlugin;
fn name(&self) -> &str {
$name
}
fn description(&self) -> &str {
$desc
}
fn signature(&self) -> Signature {
Signature::build(self.name())
.input_output_types(vec![
(
Type::Custom("expression".into()),
Type::Custom("expression".into()),
),
(
Type::Custom("dataframe".into()),
Type::Custom("dataframe".into()),
),
])
.category(Category::Custom("expression".into()))
}
fn examples(&self) -> Vec<Example> {
$examples
}
fn run(
&self,
plugin: &Self::Plugin,
engine: &EngineInterface,
call: &EvaluatedCall,
input: PipelineData,
) -> Result<PipelineData, LabeledError> {
let value = input.into_value(call.head)?;
if NuDataFrame::can_downcast(&value) || NuLazyFrame::can_downcast(&value) {
let lazy = NuLazyFrame::try_from_value_coerce(plugin, &value)
.map_err(LabeledError::from)?;
let lazy = NuLazyFrame::new(lazy.from_eager, lazy.to_polars().$func($ddof));
lazy.to_pipeline_data(plugin, engine, call.head)
.map_err(LabeledError::from)
} else {
let expr = NuExpression::try_from_value(plugin, &value)?;
let expr: NuExpression = expr.into_polars().$func($ddof).into();
expr.to_pipeline_data(plugin, engine, call.head)
.map_err(LabeledError::from)
}
}
}
#[cfg(test)]
mod $test {
use super::*;
use crate::test::test_polars_plugin_command;
use nu_protocol::ShellError;
#[test]
fn test_examples() -> Result<(), ShellError> {
test_polars_plugin_command(&$command)
}
}
};
}
// ExprList command
// Expands to a command definition for a list expression
expr_command!(
@ -303,21 +50,6 @@ expr_command!(
test_count
);
// ExprNot command
// Expands to a command definition for a not expression
expr_command!(
ExprNot,
"polars expr-not",
"Creates a not expression.",
vec![Example {
description: "Creates a not expression",
example: "(polars col a) > 2) | polars expr-not",
result: None,
},],
not,
test_not
);
// ExprMax command
// Expands to a command definition for max aggregation
lazy_expr_command!(

View File

@ -1,6 +1,6 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -0,0 +1,44 @@
mod aggregate;
mod aggregation_commands;
mod cumulative;
pub mod groupby;
mod median;
mod n_null;
mod n_unique;
mod quantile;
mod rolling;
mod value_counts;
use crate::PolarsPlugin;
use nu_plugin::PluginCommand;
pub use aggregate::LazyAggregate;
pub use aggregation_commands::*;
pub use cumulative::Cumulative;
pub use n_null::NNull;
pub use n_unique::NUnique;
pub use rolling::Rolling;
pub use value_counts::ValueCount;
pub(crate) fn aggregation_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin>>> {
vec![
Box::new(Cumulative),
Box::new(ExprAggGroups),
Box::new(ExprCount),
Box::new(ExprList),
Box::new(ExprMax),
Box::new(ExprMin),
Box::new(ExprSum),
Box::new(ExprMean),
Box::new(ExprStd),
Box::new(ExprVar),
Box::new(LazyAggregate),
Box::new(median::LazyMedian),
Box::new(quantile::LazyQuantile),
Box::new(groupby::ToLazyGroupBy),
Box::new(Rolling),
Box::new(ValueCount),
Box::new(NNull),
Box::new(NUnique),
]
}

View File

@ -1,6 +1,6 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -3,7 +3,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame, NuExpression};
use crate::values::{Column, NuDataFrame, NuExpression};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,

View File

@ -1,7 +1,6 @@
use crate::values::{Column, NuDataFrame};
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,

View File

@ -1,6 +1,5 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, CustomValueSupport, NuDataFrame};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,6 +1,5 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, CustomValueSupport, NuDataFrame};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,6 +1,5 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, CustomValueSupport, NuDataFrame};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -0,0 +1,21 @@
use crate::expr_command;
use crate::values::CustomValueSupport;
use crate::values::NuExpression;
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{Category, Example, LabeledError, PipelineData, Signature, Type};
// ExprNot command
// Expands to a command definition for a not expression
expr_command!(
ExprNot,
"polars expr-not",
"Creates a not expression.",
vec![Example {
description: "Creates a not expression",
example: "(polars col a) > 2) | polars expr-not",
result: None,
},],
not,
test_not
);

View File

@ -0,0 +1,46 @@
mod all_false;
mod all_true;
mod arg_true;
mod expr_not;
mod is_duplicated;
mod is_in;
mod is_not_null;
mod is_null;
mod is_unique;
mod not;
pub(crate) mod otherwise;
mod set;
mod when;
use crate::PolarsPlugin;
use nu_plugin::PluginCommand;
pub use all_false::AllFalse;
pub use arg_true::ArgTrue;
pub use is_duplicated::IsDuplicated;
pub use is_in::ExprIsIn;
pub use is_not_null::IsNotNull;
pub use is_null::IsNull;
pub use is_unique::IsUnique;
pub use not::NotSeries;
pub use otherwise::ExprOtherwise;
pub use set::SetSeries;
pub use when::ExprWhen;
pub(crate) fn boolean_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin>>> {
vec![
Box::new(AllFalse),
Box::new(all_true::AllTrue),
Box::new(ArgTrue),
Box::new(ExprIsIn),
Box::new(ExprOtherwise),
Box::new(ExprWhen),
Box::new(expr_not::ExprNot),
Box::new(IsDuplicated),
Box::new(IsNotNull),
Box::new(IsNull),
Box::new(IsUnique),
Box::new(NotSeries),
Box::new(SetSeries),
]
}

View File

@ -0,0 +1,16 @@
use crate::lazy_command;
// LazyCache command
// Expands to a command definition for cache
lazy_command!(
LazyCache,
"polars cache",
"Caches operations in a new LazyFrame.",
vec![Example {
description: "Caches the result into a new LazyFrame",
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars reverse | polars cache",
result: None,
}],
cache,
test_cache
);

View File

@ -1,6 +1,6 @@
use crate::values::NuDataFrame;
use crate::PolarsPlugin;
use super::super::values::NuDataFrame;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,

View File

@ -0,0 +1,39 @@
mod cache;
mod columns;
mod fetch;
mod open;
mod save;
mod schema;
mod shape;
mod summary;
mod to_df;
mod to_lazy;
mod to_nu;
use crate::PolarsPlugin;
use nu_plugin::PluginCommand;
pub use self::open::OpenDataFrame;
use fetch::LazyFetch;
pub use schema::SchemaCmd;
pub use shape::ShapeDF;
pub use summary::Summary;
pub use to_df::ToDataFrame;
pub use to_lazy::ToLazyFrame;
pub use to_nu::ToNu;
pub(crate) fn core_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin>>> {
vec![
Box::new(columns::ColumnsDF),
Box::new(cache::LazyCache),
Box::new(LazyFetch),
Box::new(OpenDataFrame),
Box::new(Summary),
Box::new(ShapeDF),
Box::new(SchemaCmd),
Box::new(ToNu),
Box::new(ToDataFrame),
Box::new(save::SaveDF),
Box::new(ToLazyFrame),
]
}

View File

@ -1,12 +1,11 @@
use crate::{
dataframe::values::NuSchema,
values::{CustomValueSupport, NuLazyFrame, PolarsFileType},
values::{CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsFileType},
EngineWrapper, PolarsPlugin,
};
use nu_path::expand_path_with;
use nu_utils::perf;
use super::super::values::NuDataFrame;
use nu_plugin::PluginCommand;
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,

View File

@ -48,7 +48,7 @@ pub(crate) fn command_eager(
#[cfg(test)]
pub mod test {
use crate::eager::save::test::{test_eager_save, test_lazy_save};
use crate::command::core::save::test::{test_eager_save, test_lazy_save};
#[test]
pub fn test_arrow_eager_save() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -60,7 +60,7 @@ pub(crate) fn command_eager(
#[cfg(test)]
pub mod test {
use crate::eager::save::test::{test_eager_save, test_lazy_save};
use crate::command::core::save::test::{test_eager_save, test_lazy_save};
#[test]
pub fn test_avro_eager_save() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -97,7 +97,7 @@ pub(crate) fn command_eager(
#[cfg(test)]
pub mod test {
use crate::eager::save::test::{test_eager_save, test_lazy_save};
use crate::command::core::save::test::{test_eager_save, test_lazy_save};
#[test]
pub fn test_csv_eager_save() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -49,7 +49,7 @@ pub(crate) fn command_eager(
#[cfg(test)]
pub mod test {
use crate::eager::save::test::{test_eager_save, test_lazy_save};
use crate::command::core::save::test::{test_eager_save, test_lazy_save};
#[test]
pub fn test_arrow_eager_save() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -48,7 +48,7 @@ pub(crate) fn command_eager(
#[cfg(test)]
pub(crate) mod test {
use crate::eager::save::test::{test_eager_save, test_lazy_save};
use crate::command::core::save::test::{test_eager_save, test_lazy_save};
#[test]
pub fn test_parquet_eager_save() -> Result<(), Box<dyn std::error::Error>> {

View File

@ -5,7 +5,7 @@ use nu_protocol::{
use crate::{dataframe::values::Column, values::CustomValueSupport, PolarsPlugin};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
#[derive(Clone)]
pub struct ShapeDF;

View File

@ -1,6 +1,6 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -4,7 +4,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,6 +1,6 @@
use crate::{dataframe::values::NuSchema, values::CustomValueSupport, Cacheable, PolarsPlugin};
use super::super::values::{NuDataFrame, NuLazyFrame};
use crate::values::{NuDataFrame, NuLazyFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{Category, Example, LabeledError, PipelineData, Signature, SyntaxShape, Type};

View File

@ -10,7 +10,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
#[derive(Clone)]
pub struct ToNu;

View File

@ -1,6 +1,6 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::NuExpression;
use crate::values::NuExpression;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -4,7 +4,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span,

View File

@ -7,8 +7,8 @@ use nu_protocol::{
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use super::super::values::utils::convert_columns;
use super::super::values::{Column, NuDataFrame};
use crate::values::utils::convert_columns;
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct DropDF;

View File

@ -8,8 +8,8 @@ use polars::prelude::UniqueKeepStrategy;
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use super::super::values::utils::convert_columns_string;
use super::super::values::{Column, NuDataFrame};
use crate::values::utils::convert_columns_string;
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct DropDuplicates;

View File

@ -7,8 +7,8 @@ use nu_protocol::{
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use super::super::values::utils::convert_columns_string;
use super::super::values::{Column, NuDataFrame};
use crate::values::utils::convert_columns_string;
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct DropNulls;

View File

@ -1,4 +1,4 @@
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
use crate::{values::CustomValueSupport, PolarsPlugin};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -11,7 +11,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct FilterWith;

View File

@ -3,7 +3,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{NuDataFrame, NuExpression};
use crate::values::{NuDataFrame, NuExpression};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,

View File

@ -8,7 +8,7 @@ use crate::{
dataframe::values::utils::convert_columns_string, values::CustomValueSupport, PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct GetDF;

View File

@ -3,7 +3,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{utils::DEFAULT_ROWS, NuDataFrame, NuExpression};
use crate::values::{utils::DEFAULT_ROWS, NuDataFrame, NuExpression};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,

View File

@ -0,0 +1,109 @@
mod alias;
mod append;
mod arg_where;
mod cast;
mod col;
mod collect;
mod drop;
mod drop_duplicates;
mod drop_nulls;
mod dummies;
mod explode;
mod fill_nan;
mod fill_null;
mod filter;
mod filter_with;
mod first;
mod flatten;
mod get;
mod join;
mod last;
mod lit;
mod pivot;
mod query_df;
mod rename;
mod reverse;
mod sample;
mod select;
mod slice;
mod sort_by_expr;
pub mod sql_context;
pub mod sql_expr;
mod take;
mod unpivot;
mod with_column;
use filter::LazyFilter;
mod shift;
mod unique;
use crate::PolarsPlugin;
use nu_plugin::PluginCommand;
pub use alias::ExprAlias;
pub use append::AppendDF;
pub use arg_where::ExprArgWhere;
pub use cast::CastDF;
pub use col::ExprCol;
pub use collect::LazyCollect;
pub use drop::DropDF;
pub use drop_duplicates::DropDuplicates;
pub use drop_nulls::DropNulls;
pub use dummies::Dummies;
pub use explode::LazyExplode;
use fill_nan::LazyFillNA;
pub use fill_null::LazyFillNull;
pub use first::FirstDF;
use flatten::LazyFlatten;
pub use get::GetDF;
use join::LazyJoin;
pub use last::LastDF;
pub use lit::ExprLit;
use query_df::QueryDf;
pub use rename::RenameDF;
pub use sample::SampleDF;
pub use shift::Shift;
pub use slice::SliceDF;
use sort_by_expr::LazySortBy;
pub use take::TakeDF;
pub use unique::Unique;
pub use unpivot::UnpivotDF;
pub use with_column::WithColumn;
pub(crate) fn data_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin>>> {
vec![
Box::new(AppendDF),
Box::new(CastDF),
Box::new(DropDF),
Box::new(DropDuplicates),
Box::new(DropNulls),
Box::new(Dummies),
Box::new(filter_with::FilterWith),
Box::new(GetDF),
Box::new(pivot::PivotDF),
Box::new(UnpivotDF),
Box::new(FirstDF),
Box::new(LastDF),
Box::new(RenameDF),
Box::new(SampleDF),
Box::new(SliceDF),
Box::new(TakeDF),
Box::new(QueryDf),
Box::new(WithColumn),
Box::new(ExprAlias),
Box::new(ExprArgWhere),
Box::new(ExprLit),
Box::new(ExprCol),
Box::new(LazyCollect),
Box::new(LazyExplode),
Box::new(LazyFillNA),
Box::new(LazyFillNull),
Box::new(LazyFlatten),
Box::new(LazyJoin),
Box::new(reverse::LazyReverse),
Box::new(select::LazySelect),
Box::new(LazySortBy),
Box::new(LazyFilter),
Box::new(Shift),
Box::new(Unique),
]
}

View File

@ -12,7 +12,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
#[derive(Clone)]
pub struct PivotDF;
@ -75,7 +75,7 @@ impl PluginCommand for PivotDF {
vec![
Example {
example: "[[name subject test_1 test_2]; [Cady maths 98 100] [Cady physics 99 100] [Karen maths 61 60] [Karen physics 58 60]] | polars into-df | polars pivot --on [subject] --index [name] --values [test_1]",
description: "Perform a pivot in order to show individuals test score by subject",
description: "Perform a pivot in order to show individuals test score by subject",
result: Some(
NuDataFrame::try_from_columns(
vec![

View File

@ -1,7 +1,8 @@
use super::super::values::NuDataFrame;
use super::sql_context::SQLContext;
use crate::dataframe::values::Column;
use crate::dataframe::{eager::SQLContext, values::NuLazyFrame};
use crate::dataframe::values::NuLazyFrame;
use crate::values::CustomValueSupport;
use crate::values::NuDataFrame;
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -10,7 +10,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct RenameDF;

View File

@ -0,0 +1,37 @@
use nu_protocol::{Span, Value};
use crate::{
lazy_command,
values::{Column, NuDataFrame},
};
// LazyReverse command
// Expands to a command definition for reverse
lazy_command!(
LazyReverse,
"polars reverse",
"Reverses the LazyFrame",
vec![Example {
description: "Reverses the dataframe.",
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars reverse",
result: Some(
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(2), Value::test_int(4), Value::test_int(6),],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2), Value::test_int(2),],
),
],
None
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},],
reverse,
test_reverse
);

View File

@ -8,7 +8,7 @@ use polars::series::Series;
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct SampleDF;

View File

@ -4,7 +4,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -6,7 +6,7 @@ use nu_protocol::{
use crate::{dataframe::values::Column, values::CustomValueSupport, PolarsPlugin};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
#[derive(Clone)]
pub struct SliceDF;

View File

@ -1,4 +1,4 @@
use super::super::values::NuLazyFrame;
use crate::values::NuLazyFrame;
use crate::{
dataframe::values::{Column, NuDataFrame, NuExpression},
values::CustomValueSupport,

View File

@ -1,4 +1,4 @@
use crate::dataframe::eager::sql_expr::parse_sql_expr;
use crate::dataframe::command::data::sql_expr::parse_sql_expr;
use polars::error::{ErrString, PolarsError};
use polars::prelude::{col, DataFrame, DataType, IntoLazy, LazyFrame};
use sqlparser::ast::{

View File

@ -7,7 +7,7 @@ use polars::prelude::DataType;
use crate::{dataframe::values::Column, values::CustomValueSupport, PolarsPlugin};
use super::super::values::NuDataFrame;
use crate::values::NuDataFrame;
#[derive(Clone)]
pub struct TakeDF;

View File

@ -4,7 +4,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -11,7 +11,7 @@ use crate::{
PolarsPlugin,
};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
#[derive(Clone)]
pub struct UnpivotDF;

View File

@ -1,4 +1,4 @@
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use crate::{
dataframe::values::{NuExpression, NuLazyFrame},
values::{CustomValueSupport, PolarsPluginObject},

View File

@ -1,4 +1,4 @@
use super::super::values::NuExpression;
use crate::values::NuExpression;
use crate::{
dataframe::values::{Column, NuDataFrame},

View File

@ -0,0 +1,52 @@
mod as_date;
mod as_datetime;
mod datepart;
mod get_day;
mod get_hour;
mod get_minute;
mod get_month;
mod get_nanosecond;
mod get_ordinal;
mod get_second;
mod get_week;
mod get_weekday;
mod get_year;
use crate::PolarsPlugin;
use nu_plugin::PluginCommand;
pub use as_date::AsDate;
pub use as_datetime::AsDateTime;
pub use datepart::ExprDatePart;
pub use get_day::GetDay;
pub use get_hour::GetHour;
pub use get_minute::GetMinute;
pub use get_month::GetMonth;
pub use get_nanosecond::GetNanosecond;
pub use get_ordinal::GetOrdinal;
pub use get_second::GetSecond;
pub use get_week::GetWeek;
pub use get_weekday::GetWeekDay;
pub use get_year::GetYear;
mod strftime;
pub use strftime::StrFTime;
pub(crate) fn datetime_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin>>> {
vec![
Box::new(ExprDatePart),
Box::new(AsDate),
Box::new(AsDateTime),
Box::new(GetDay),
Box::new(GetHour),
Box::new(GetMinute),
Box::new(GetMonth),
Box::new(GetNanosecond),
Box::new(GetOrdinal),
Box::new(GetSecond),
Box::new(GetWeek),
Box::new(GetWeekDay),
Box::new(GetYear),
Box::new(StrFTime),
]
}

View File

@ -1,6 +1,6 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,6 +1,6 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use super::super::values::{Column, NuDataFrame};
use crate::values::{Column, NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -0,0 +1,24 @@
mod arg_max;
mod arg_min;
mod arg_sort;
mod arg_unique;
mod set_with_idx;
use crate::PolarsPlugin;
use nu_plugin::PluginCommand;
pub use arg_max::ArgMax;
pub use arg_min::ArgMin;
pub use arg_sort::ArgSort;
pub use arg_unique::ArgUnique;
pub use set_with_idx::SetWithIndex;
pub(crate) fn index_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin>>> {
vec![
Box::new(ArgMax),
Box::new(ArgMin),
Box::new(ArgSort),
Box::new(ArgUnique),
Box::new(SetWithIndex),
]
}

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