Rust 1.85, edition=2024 (#15741)

This commit is contained in:
Jack Wright
2025-05-13 07:49:30 -07:00
committed by GitHub
parent 1a0986903f
commit c2ac8f730e
793 changed files with 4276 additions and 3687 deletions

View File

@ -7,8 +7,8 @@ use polars::{prelude::NamedFrom, series::Series};
use uuid::Uuid;
use crate::{
values::{CustomValueSupport, NuDataFrame},
PolarsPlugin,
values::{CustomValueSupport, NuDataFrame},
};
#[derive(Clone)]

View File

@ -1,9 +1,9 @@
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, IntoPipelineData, LabeledError, PipelineData, Signature, Value,
Category, Example, IntoPipelineData, LabeledError, PipelineData, Signature, Value, record,
};
use crate::{values::PolarsPluginObject, PolarsPlugin};
use crate::{PolarsPlugin, values::PolarsPluginObject};
#[derive(Clone)]
pub struct ListDF;

View File

@ -13,7 +13,7 @@ use nu_plugin::{EngineInterface, PluginCommand};
use nu_protocol::{LabeledError, ShellError, Span};
use uuid::Uuid;
use crate::{values::PolarsPluginObject, EngineWrapper, PolarsPlugin};
use crate::{EngineWrapper, PolarsPlugin, values::PolarsPluginObject};
use log::debug;

View File

@ -1,7 +1,7 @@
use std::error::Error;
use aws_config::{BehaviorVersion, SdkConfig};
use aws_credential_types::{provider::ProvideCredentials, Credentials};
use aws_credential_types::{Credentials, provider::ProvideCredentials};
use nu_protocol::ShellError;
use object_store::aws::AmazonS3ConfigKey;
use polars_io::cloud::CloudOptions;

View File

@ -1,8 +1,8 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType,
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::{NuExpression, NuLazyFrame, NuLazyGroupBy},
values::{Column, CustomValueSupport, NuDataFrame},
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};

View File

@ -1,8 +1,8 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType,
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,

View File

@ -1,7 +1,7 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use crate::values::{
cant_convert_err, Column, NuDataFrame, NuExpression, PolarsPluginObject, PolarsPluginType,
Column, NuDataFrame, NuExpression, PolarsPluginObject, PolarsPluginType, cant_convert_err,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::{NuDataFrame, NuExpression, NuLazyFrame, NuLazyGroupBy},
values::CustomValueSupport,
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

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

View File

@ -1,8 +1,8 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType,
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,
@ -37,11 +37,14 @@ impl PluginCommand for ExprImplode {
description: "Create two lists for columns a and b with all the rows as values.",
example: "[[a b]; [1 4] [2 5] [3 6]] | polars into-df | polars select (polars col '*' | polars implode) | polars collect",
result: Some(
NuDataFrame::from(df!(
"a"=> [[1i64, 2, 3].iter().collect::<Series>()],
"b"=> [[4i64, 5, 6].iter().collect::<Series>()],
).expect("should not fail"))
.into_value(Span::unknown())
NuDataFrame::from(
df!(
"a"=> [[1i64, 2, 3].iter().collect::<Series>()],
"b"=> [[4i64, 5, 6].iter().collect::<Series>()],
)
.expect("should not fail"),
)
.into_value(Span::unknown()),
),
}]
}

View File

@ -1,9 +1,9 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject,
PolarsPluginType,
Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,

View File

@ -1,9 +1,9 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject,
PolarsPluginType,
Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,

View File

@ -1,9 +1,9 @@
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuLazyFrame},
values::{
cant_convert_err, CustomValueSupport, NuExpression, PolarsPluginObject, PolarsPluginType,
CustomValueSupport, NuExpression, PolarsPluginObject, PolarsPluginType, cant_convert_err,
},
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
@ -68,8 +68,7 @@ impl PluginCommand for LazyMedian {
},
Example {
description: "Median value from columns in a dataframe",
example:
"[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars median | polars collect",
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars median | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![

View File

@ -1,9 +1,9 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject,
PolarsPluginType,
Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,

View File

@ -1,4 +1,4 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use crate::values::{Column, NuDataFrame};

View File

@ -1,6 +1,6 @@
use crate::{
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use crate::values::{Column, NuDataFrame, NuExpression};

View File

@ -1,7 +1,7 @@
use crate::{
dataframe::values::{NuDataFrame, NuExpression},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{NuDataFrame, NuExpression},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,16 +1,16 @@
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuLazyFrame},
values::{
cant_convert_err, CustomValueSupport, NuExpression, PolarsPluginObject, PolarsPluginType,
CustomValueSupport, NuExpression, PolarsPluginObject, PolarsPluginType, cant_convert_err,
},
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
Value,
};
use polars::prelude::{lit, QuantileMethod};
use polars::prelude::{QuantileMethod, lit};
#[derive(Clone)]
pub struct LazyQuantile;

View File

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

View File

@ -1,7 +1,7 @@
use crate::values::{
cant_convert_err, Column, CustomValueSupport, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
};
use crate::PolarsPlugin;
use crate::values::{
Column, CustomValueSupport, NuLazyFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
};
use crate::{dataframe::values::NuExpression, values::NuDataFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
@ -41,8 +41,7 @@ impl PluginCommand for ExprStd {
vec![
Example {
description: "Std value from columns in a dataframe",
example:
"[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars std | polars collect",
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars std | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![

View File

@ -1,9 +1,9 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject,
PolarsPluginType,
Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
@ -41,8 +41,7 @@ impl PluginCommand for ExprSum {
vec![
Example {
description: "Sums all columns in a dataframe",
example:
"[[a b]; [6 2] [1 4] [4 1]] | polars into-df | polars sum | polars collect",
example: "[[a b]; [6 2] [1 4] [4 1]] | polars into-df | polars sum | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![

View File

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

View File

@ -1,9 +1,9 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject,
PolarsPluginType,
Column, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
@ -41,10 +41,8 @@ impl PluginCommand for ExprVar {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description:
"Var value from columns in a dataframe or aggregates columns to their var value",
example:
"[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars var | polars collect",
description: "Var value from columns in a dataframe or aggregates columns to their var value",
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars var | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![

View File

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

View File

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

View File

@ -1,4 +1,4 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use super::super::super::values::{Column, NuDataFrame};
@ -6,7 +6,7 @@ use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
};
use polars::prelude::{arg_where, col, IntoLazy};
use polars::prelude::{IntoLazy, arg_where, col};
#[derive(Clone)]
pub struct ArgTrue;

View File

@ -1,8 +1,8 @@
use crate::PolarsPlugin;
use crate::dataframe::values::NuExpression;
use crate::values::{
cant_convert_err, CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType,
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,

View File

@ -1,4 +1,4 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use super::super::super::values::{Column, NuDataFrame};
@ -58,8 +58,7 @@ impl PluginCommand for IsDuplicated {
},
Example {
description: "Create mask indicating duplicated rows in a dataframe",
example:
"[[a, b]; [1 2] [1 2] [3 3] [3 3] [1 1]] | polars into-df | polars is-duplicated",
example: "[[a, b]; [1 2] [1 2] [3 3] [3 3] [1 1]] | polars into-df | polars is-duplicated",
result: Some(
NuDataFrame::try_from_columns(
vec![Column::new(

View File

@ -1,14 +1,14 @@
use crate::{
dataframe::values::{Column, NuDataFrame, NuExpression},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
Value,
};
use polars::prelude::{is_in, lit, DataType, IntoSeries};
use polars::prelude::{DataType, IntoSeries, is_in, lit};
#[derive(Clone)]
pub struct ExprIsIn;

View File

@ -1,6 +1,6 @@
use crate::{
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use super::super::super::values::{Column, NuDataFrame, NuExpression};

View File

@ -1,8 +1,8 @@
use crate::{
values::{
cant_convert_err, CustomValueSupport, NuExpression, PolarsPluginObject, PolarsPluginType,
},
PolarsPlugin,
values::{
CustomValueSupport, NuExpression, PolarsPluginObject, PolarsPluginType, cant_convert_err,
},
};
use super::super::super::values::{Column, NuDataFrame};

View File

@ -1,4 +1,4 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use super::super::super::values::{Column, NuDataFrame};
@ -58,8 +58,7 @@ impl PluginCommand for IsUnique {
},
Example {
description: "Create mask indicating duplicated rows in a dataframe",
example:
"[[a, b]; [1 2] [1 2] [3 3] [3 3] [1 1]] | polars into-df | polars is-unique",
example: "[[a, b]; [1 2] [1 2] [3 3] [3 3] [1 1]] | polars into-df | polars is-unique",
result: Some(
NuDataFrame::try_from_columns(
vec![Column::new(

View File

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

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression, NuWhen, NuWhenType},
values::CustomValueSupport,
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
@ -41,8 +41,7 @@ impl PluginCommand for ExprOtherwise {
},
Example {
description: "Create a when conditions",
example:
"polars when ((polars col a) > 2) 4 | polars when ((polars col a) < 0) 6 | polars otherwise 0",
example: "polars when ((polars col a) > 2) 4 | polars when ((polars col a) < 0) 6 | polars otherwise 0",
result: None,
},
Example {

View File

@ -1,4 +1,4 @@
use crate::{missing_flag_error, values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, missing_flag_error, values::CustomValueSupport};
use super::super::super::values::{Column, NuDataFrame};

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression, NuWhen},
values::{CustomValueSupport, NuWhenType},
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -3,8 +3,8 @@ use nu_protocol::{Category, Example, LabeledError, PipelineData, Signature, Span
use polars::df;
use crate::{
values::{CustomValueSupport, NuDataFrame, NuLazyFrame},
PolarsPlugin,
values::{CustomValueSupport, NuDataFrame, NuLazyFrame},
};
pub struct LazyCache;

View File

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

View File

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

View File

@ -1,16 +1,16 @@
use crate::{
EngineWrapper, PolarsPlugin,
command::core::resource::Resource,
dataframe::values::NuSchema,
values::{CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsFileType},
EngineWrapper, PolarsPlugin,
};
use log::debug;
use nu_utils::perf;
use nu_plugin::{EvaluatedCall, PluginCommand};
use nu_protocol::{
shell_error::io::IoError, Category, Example, LabeledError, PipelineData, ShellError, Signature,
Span, Spanned, SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,
SyntaxShape, Type, Value, shell_error::io::IoError,
};
use std::{fs::File, io::BufReader, num::NonZeroUsize, path::PathBuf, sync::Arc};
@ -23,7 +23,7 @@ use polars::{
},
};
use polars_io::{avro::AvroReader, csv::read::CsvReadOptions, HiveOptions};
use polars_io::{HiveOptions, avro::AvroReader, csv::read::CsvReadOptions};
const DEFAULT_INFER_SCHEMA: usize = 100;

View File

@ -1,14 +1,14 @@
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Type, Value, record,
};
use crate::{
values::{
cant_convert_err, CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject,
PolarsPluginType,
},
PolarsPlugin,
values::{
CustomValueSupport, NuDataFrame, NuLazyFrame, PolarsPluginObject, PolarsPluginType,
cant_convert_err,
},
};
pub struct ProfileDF;

View File

@ -1,6 +1,6 @@
use std::path::{Component, Path, PathBuf};
use crate::{cloud::build_cloud_options, PolarsPlugin};
use crate::{PolarsPlugin, cloud::build_cloud_options};
use nu_path::expand_path_with;
use nu_protocol::{ShellError, Span, Spanned};
use polars_io::cloud::CloudOptions;

View File

@ -2,8 +2,8 @@ use std::fs::File;
use nu_plugin::EvaluatedCall;
use nu_protocol::ShellError;
use polars_io::avro::{AvroCompression, AvroWriter};
use polars_io::SerWriter;
use polars_io::avro::{AvroCompression, AvroWriter};
use crate::command::core::resource::Resource;
use crate::values::NuDataFrame;

View File

@ -7,16 +7,16 @@ mod parquet;
use std::path::PathBuf;
use crate::{
command::core::resource::Resource,
values::{cant_convert_err, PolarsFileType, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
command::core::resource::Resource,
values::{PolarsFileType, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use log::debug;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
shell_error::io::IoError, Category, Example, LabeledError, PipelineData, ShellError, Signature,
Span, Spanned, SyntaxShape, Type,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,
SyntaxShape, Type, shell_error::io::IoError,
};
use polars::error::PolarsError;
@ -67,8 +67,7 @@ impl PluginCommand for SaveDF {
fn examples(&self) -> Vec<Example> {
vec![
Example {
description:
"Performs a streaming collect and save the output to the specified file",
description: "Performs a streaming collect and save the output to the specified file",
example: "[[a b];[1 2] [3 4]] | polars into-lazy | polars save test.parquet",
result: None,
},

View File

@ -1,11 +1,11 @@
use crate::{
values::{datatype_list, CustomValueSupport, PolarsPluginObject},
PolarsPlugin,
values::{CustomValueSupport, PolarsPluginObject, datatype_list},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value, record,
};
#[derive(Clone)]

View File

@ -3,7 +3,7 @@ use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
};
use crate::{dataframe::values::Column, values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, dataframe::values::Column, values::CustomValueSupport};
use crate::values::NuDataFrame;

View File

@ -1,4 +1,4 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use crate::values::{Column, NuDataFrame};

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::NuSchema,
values::{Column, CustomValueSupport},
PolarsPlugin,
};
use crate::values::NuDataFrame;
@ -162,35 +162,54 @@ impl PluginCommand for ToDataFrame {
description: "Convert to a dataframe and provide a schema",
example: "[[a b c e]; [1 {d: [1 2 3]} [10 11 12] 1.618]]| polars into-df -s {a: u8, b: {d: list<u64>}, c: list<u8>, e: 'decimal<4,3>'}",
result: Some(
NuDataFrame::try_from_series_vec(vec![
Series::new("a".into(), &[1u8]),
{
let dtype = DataType::Struct(vec![Field::new("d".into(), DataType::List(Box::new(DataType::UInt64)))]);
let vals = vec![AnyValue::StructOwned(
Box::new((vec![AnyValue::List(Series::new("d".into(), &[1u64, 2, 3]))], vec![Field::new("d".into(), DataType::String)]))); 1];
Series::from_any_values_and_dtype("b".into(), &vals, &dtype, false)
.expect("Struct series should not fail")
},
{
let dtype = DataType::List(Box::new(DataType::UInt8));
let vals = vec![AnyValue::List(Series::new("c".into(), &[10, 11, 12]))];
Series::from_any_values_and_dtype("c".into(), &vals, &dtype, false)
.expect("List series should not fail")
},
Series::new("e".into(), &[1.618]),
], Span::test_data())
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
NuDataFrame::try_from_series_vec(
vec![
Series::new("a".into(), &[1u8]),
{
let dtype = DataType::Struct(vec![Field::new(
"d".into(),
DataType::List(Box::new(DataType::UInt64)),
)]);
let vals = vec![
AnyValue::StructOwned(Box::new((
vec![AnyValue::List(Series::new(
"d".into(),
&[1u64, 2, 3]
))],
vec![Field::new("d".into(), DataType::String)]
)));
1
];
Series::from_any_values_and_dtype("b".into(), &vals, &dtype, false)
.expect("Struct series should not fail")
},
{
let dtype = DataType::List(Box::new(DataType::UInt8));
let vals =
vec![AnyValue::List(Series::new("c".into(), &[10, 11, 12]))];
Series::from_any_values_and_dtype("c".into(), &vals, &dtype, false)
.expect("List series should not fail")
},
Series::new("e".into(), &[1.618]),
],
Span::test_data(),
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
Example {
description: "Convert to a dataframe and provide a schema that adds a new column",
example: r#"[[a b]; [1 "foo"] [2 "bar"]] | polars into-df -s {a: u8, b:str, c:i64} | polars fill-null 3"#,
result: Some(NuDataFrame::try_from_series_vec(vec![
Series::new("a".into(), [1u8, 2]),
Series::new("b".into(), ["foo", "bar"]),
Series::new("c".into(), [3i64, 3]),
], Span::test_data())
result: Some(
NuDataFrame::try_from_series_vec(
vec![
Series::new("a".into(), [1u8, 2]),
Series::new("b".into(), ["foo", "bar"]),
Series::new("c".into(), [3i64, 3]),
],
Span::test_data(),
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
@ -198,9 +217,11 @@ impl PluginCommand for ToDataFrame {
Example {
description: "If a provided schema specifies a subset of columns, only those columns are selected",
example: r#"[[a b]; [1 "foo"] [2 "bar"]] | polars into-df -s {a: str}"#,
result: Some(NuDataFrame::try_from_series_vec(vec![
Series::new("a".into(), ["1", "2"]),
], Span::test_data())
result: Some(
NuDataFrame::try_from_series_vec(
vec![Series::new("a".into(), ["1", "2"])],
Span::test_data(),
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
@ -208,10 +229,14 @@ impl PluginCommand for ToDataFrame {
Example {
description: "Use a predefined schama",
example: r#"let schema = {a: str, b: str}; [[a b]; [1 "foo"] [2 "bar"]] | polars into-df -s $schema"#,
result: Some(NuDataFrame::try_from_series_vec(vec![
Series::new("a".into(), ["1", "2"]),
Series::new("b".into(), ["foo", "bar"]),
], Span::test_data())
result: Some(
NuDataFrame::try_from_series_vec(
vec![
Series::new("a".into(), ["1", "2"]),
Series::new("b".into(), ["foo", "bar"]),
],
Span::test_data(),
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),

View File

@ -2,8 +2,8 @@ use nu_plugin::PluginCommand;
use nu_protocol::{Category, Example, ShellError, Signature, Span, Type, Value};
use crate::{
values::{CustomValueSupport, NuDataType},
PolarsPlugin,
values::{CustomValueSupport, NuDataType},
};
pub struct ToDataType;

View File

@ -1,11 +1,11 @@
use crate::{dataframe::values::NuSchema, values::CustomValueSupport, Cacheable, PolarsPlugin};
use crate::{Cacheable, PolarsPlugin, dataframe::values::NuSchema, values::CustomValueSupport};
use crate::values::{NuDataFrame, NuLazyFrame};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, Signature, Span, SyntaxShape, Type,
Value,
Category, Example, LabeledError, PipelineData, Signature, Span, SyntaxShape, Type, Value,
record,
};
use polars::prelude::NamedFrom;
use polars::series::Series;
@ -46,15 +46,21 @@ impl PluginCommand for ToLazyFrame {
Example {
description: "Takes a table, creates a lazyframe, assigns column 'b' type str, displays the schema",
example: "[[a b];[1 2] [3 4]] | polars into-lazy --schema {b: str} | polars schema",
result: Some(Value::test_record(record! {"b" => Value::test_string("str")})),
result: Some(Value::test_record(
record! {"b" => Value::test_string("str")},
)),
},
Example {
description: "Use a predefined schama",
example: r#"let schema = {a: str, b: str}; [[a b]; [1 "foo"] [2 "bar"]] | polars into-lazy -s $schema"#,
result: Some(NuDataFrame::try_from_series_vec(vec![
Series::new("a".into(), ["1", "2"]),
Series::new("b".into(), ["foo", "bar"]),
], Span::test_data())
result: Some(
NuDataFrame::try_from_series_vec(
vec![
Series::new("a".into(), ["1", "2"]),
Series::new("b".into(), ["foo", "bar"]),
],
Span::test_data(),
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),

View File

@ -1,12 +1,12 @@
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span,
SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
Value, record,
};
use crate::{
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use crate::values::NuDataFrame;
@ -69,8 +69,7 @@ impl PluginCommand for ToNu {
},
Example {
description: "Shows tail rows from dataframe",
example:
"[[a b]; [1 2] [5 6] [3 4]] | polars into-df | polars into-nu --tail --rows 1 --index",
example: "[[a b]; [1 2] [5 6] [3 4]] | polars into-df | polars into-nu --tail --rows 1 --index",
result: Some(Value::list(vec![rec_3], Span::test_data())),
},
Example {

View File

@ -4,8 +4,8 @@ use nu_protocol::{
};
use crate::{
values::{cant_convert_err, CustomValueSupport, NuLazyFrame, PolarsPluginType},
PolarsPlugin,
values::{CustomValueSupport, NuLazyFrame, PolarsPluginType, cant_convert_err},
};
use crate::values::NuDataFrame;
@ -34,8 +34,7 @@ impl PluginCommand for ToRepr {
vec![
Example {
description: "Shows dataframe in repr format",
example:
"[[a b]; [2025-01-01 2] [2025-01-02 4]] | polars into-df | polars into-repr",
example: "[[a b]; [2025-01-01 2] [2025-01-02 4]] | polars into-df | polars into-repr",
result: Some(Value::string(
r#"
shape: (2, 2)
@ -53,8 +52,7 @@ shape: (2, 2)
},
Example {
description: "Shows lazy dataframe in repr format",
example:
"[[a b]; [2025-01-01 2] [2025-01-02 4]] | polars into-lazy | polars into-repr",
example: "[[a b]; [2025-01-01 2] [2025-01-02 4]] | polars into-lazy | polars into-repr",
result: Some(Value::string(
r#"
shape: (2, 2)

View File

@ -1,9 +1,9 @@
use nu_plugin::PluginCommand;
use nu_protocol::{record, Category, Example, ShellError, Signature, Span, Type, Value};
use nu_protocol::{Category, Example, ShellError, Signature, Span, Type, Value, record};
use crate::{
values::{CustomValueSupport, NuSchema},
PolarsPlugin,
values::{CustomValueSupport, NuSchema},
};
pub struct ToSchema;

View File

@ -1,10 +1,10 @@
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use crate::values::NuExpression;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, Signature, SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, Signature, SyntaxShape, Type, Value, record,
};
#[derive(Clone)]

View File

@ -5,8 +5,8 @@ use nu_protocol::{
};
use crate::{
values::{Axis, Column, CustomValueSupport, NuDataFrame},
PolarsPlugin,
values::{Axis, Column, CustomValueSupport, NuDataFrame},
};
#[derive(Clone)]

View File

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

View File

@ -1,14 +1,14 @@
use crate::{
dataframe::values::{str_to_dtype, NuExpression, NuLazyFrame},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{NuExpression, NuLazyFrame, str_to_dtype},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use crate::values::NuDataFrame;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span,
SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
Value, record,
};
use polars::prelude::*;
@ -66,8 +66,7 @@ impl PluginCommand for CastDF {
},
Example {
description: "Cast a column in a lazy dataframe to a different dtype",
example:
"[[a b]; [1 2] [3 4]] | polars into-df | polars into-lazy | polars cast u8 a | polars schema",
example: "[[a b]; [1 2] [3 4]] | polars into-df | polars into-lazy | polars cast u8 a | polars schema",
result: Some(Value::record(
record! {
"a" => Value::string("u8", Span::test_data()),

View File

@ -1,12 +1,12 @@
use crate::{
dataframe::values::NuExpression,
values::{str_to_dtype, Column, CustomValueSupport, NuDataFrame},
PolarsPlugin,
dataframe::values::NuExpression,
values::{Column, CustomValueSupport, NuDataFrame, str_to_dtype},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span,
SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
Value, record,
};
use polars::prelude::DataType;
@ -55,10 +55,23 @@ impl PluginCommand for ExprCol {
description: "Select all columns using the asterisk wildcard.",
example: "[[a b]; [x 1] [y 2] [z 3]] | polars into-df | polars select (polars col '*') | polars collect",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![Value::test_string("x"), Value::test_string("y"), Value::test_string("z")]),
Column::new("b".to_string(), vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)]),
],None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![
Value::test_string("x"),
Value::test_string("y"),
Value::test_string("z"),
],
),
Column::new(
"b".to_string(),
vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)],
),
],
None,
)
.expect("should not fail")
.into_value(Span::test_data()),
),
@ -67,10 +80,13 @@ impl PluginCommand for ExprCol {
description: "Select multiple columns (cannot be used with asterisk wildcard)",
example: "[[a b c]; [x 1 1.1] [y 2 2.2] [z 3 3.3]] | polars into-df | polars select (polars col b c | polars sum) | polars collect",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("b".to_string(), vec![Value::test_int(6)]),
Column::new("c".to_string(), vec![Value::test_float(6.6)]),
],None)
NuDataFrame::try_from_columns(
vec![
Column::new("b".to_string(), vec![Value::test_int(6)]),
Column::new("c".to_string(), vec![Value::test_float(6.6)]),
],
None,
)
.expect("should not fail")
.into_value(Span::test_data()),
),
@ -79,11 +95,14 @@ impl PluginCommand for ExprCol {
description: "Select multiple columns by types (cannot be used with asterisk wildcard)",
example: "[[a b c]; [x o 1.1] [y p 2.2] [z q 3.3]] | polars into-df | polars select (polars col str f64 --type | polars max) | polars collect",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new("a".to_string(), vec![Value::test_string("z")]),
Column::new("b".to_string(), vec![Value::test_string("q")]),
Column::new("c".to_string(), vec![Value::test_float(3.3)]),
],None)
NuDataFrame::try_from_columns(
vec![
Column::new("a".to_string(), vec![Value::test_string("z")]),
Column::new("b".to_string(), vec![Value::test_string("q")]),
Column::new("c".to_string(), vec![Value::test_float(3.3)]),
],
None,
)
.expect("should not fail")
.into_value(Span::test_data()),
),

View File

@ -1,7 +1,7 @@
use crate::{
dataframe::values::{Column, NuDataFrame},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
Cacheable, PolarsPlugin,
dataframe::values::{Column, NuDataFrame},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};

View File

@ -1,6 +1,6 @@
use crate::{
values::{CustomValueSupport, NuLazyFrame},
PolarsPlugin,
values::{CustomValueSupport, NuLazyFrame},
};
use crate::values::NuDataFrame;

View File

@ -3,8 +3,8 @@ use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Syntax
use polars::prelude::PlSmallStr;
use crate::{
values::{CustomValueSupport, NuDataFrame},
PolarsPlugin,
values::{CustomValueSupport, NuDataFrame},
};
pub struct CutSeries;

View File

@ -4,8 +4,8 @@ use nu_protocol::{
Value,
};
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use crate::values::CustomValueSupport;
use crate::values::utils::convert_columns;
use crate::values::{Column, NuDataFrame};

View File

@ -6,11 +6,11 @@ use nu_protocol::{
use polars::df;
use polars::prelude::UniqueKeepStrategy;
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use crate::values::CustomValueSupport;
use crate::values::utils::convert_columns_string;
use crate::values::NuDataFrame;
use crate::values::utils::convert_columns_string;
#[derive(Clone)]
pub struct DropDuplicates;

View File

@ -4,8 +4,8 @@ use nu_protocol::{
Value,
};
use crate::values::CustomValueSupport;
use crate::PolarsPlugin;
use crate::values::CustomValueSupport;
use crate::values::utils::convert_columns_string;
use crate::values::{Column, NuDataFrame};

View File

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

View File

@ -1,6 +1,6 @@
use crate::PolarsPlugin;
use crate::dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame};
use crate::values::{CustomValueSupport, PolarsPluginObject};
use crate::PolarsPlugin;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
@ -46,58 +46,67 @@ impl PluginCommand for LazyExplode {
vec![
Example {
description: "Explode the specified dataframe",
example: "[[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]]
example:
"[[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]]
| polars into-df
| polars explode hobbies
| polars collect
| polars sort-by [id, name]",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"id".to_string(),
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(2),
Value::test_int(2),
]),
Column::new(
"name".to_string(),
vec![
Value::test_string("Mercy"),
Value::test_string("Mercy"),
Value::test_string("Bob"),
Value::test_string("Bob"),
]),
Column::new(
"hobbies".to_string(),
vec![
Value::test_string("Cycling"),
Value::test_string("Knitting"),
Value::test_string("Skiing"),
Value::test_string("Football"),
]),
], None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"id".to_string(),
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(2),
Value::test_int(2),
],
),
Column::new(
"name".to_string(),
vec![
Value::test_string("Mercy"),
Value::test_string("Mercy"),
Value::test_string("Bob"),
Value::test_string("Bob"),
],
),
Column::new(
"hobbies".to_string(),
vec![
Value::test_string("Cycling"),
Value::test_string("Knitting"),
Value::test_string("Skiing"),
Value::test_string("Football"),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
)
),
},
Example {
description: "Select a column and explode the values",
example: "[[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]] | polars into-df | polars select (polars col hobbies | polars explode)",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
NuDataFrame::try_from_columns(
vec![Column::new(
"hobbies".to_string(),
vec![
Value::test_string("Cycling"),
Value::test_string("Knitting"),
Value::test_string("Skiing"),
Value::test_string("Football"),
]),
], None)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
],
)],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
]

View File

@ -1,7 +1,7 @@
use crate::{
dataframe::values::{Column, NuDataFrame, NuExpression},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,7 +1,7 @@
use crate::{
dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame},
values::CustomValueSupport,
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
@ -42,8 +42,7 @@ impl PluginCommand for LazyFilter {
vec![
Example {
description: "Filter dataframe using an expression",
example:
"[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars filter ((polars col a) >= 4)",
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars filter ((polars col a) >= 4)",
result: Some(
NuDataFrame::try_from_columns(
vec![
@ -64,44 +63,43 @@ impl PluginCommand for LazyFilter {
},
Example {
description: "Filter dataframe for rows where dt is within the last 2 days of the maximum dt value",
example:
"[[dt val]; [2025-04-01 1] [2025-04-02 2] [2025-04-03 3] [2025-04-04 4]] | polars into-df | polars filter ((polars col dt) > ((polars col dt | polars max | $in - 2day)))",
example: "[[dt val]; [2025-04-01 1] [2025-04-02 2] [2025-04-03 3] [2025-04-04 4]] | polars into-df | polars filter ((polars col dt) > ((polars col dt | polars max | $in - 2day)))",
result: Some(
NuDataFrame::try_from_columns(
vec![
Column::new(
"dt".to_string(),
vec![
Value::date(
chrono::DateTime::parse_from_str(
"2025-04-03 00:00:00 +0000",
"%Y-%m-%d %H:%M:%S %z",
)
.expect("date calculation should not fail in test"),
Span::test_data(),
),
Value::date(
chrono::DateTime::parse_from_str(
"2025-04-04 00:00:00 +0000",
"%Y-%m-%d %H:%M:%S %z",
)
.expect("date calculation should not fail in test"),
Span::test_data(),
),
]
),
Column::new(
"val".to_string(),
vec![Value::test_int(3), Value::test_int(4)],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
]
NuDataFrame::try_from_columns(
vec![
Column::new(
"dt".to_string(),
vec![
Value::date(
chrono::DateTime::parse_from_str(
"2025-04-03 00:00:00 +0000",
"%Y-%m-%d %H:%M:%S %z",
)
.expect("date calculation should not fail in test"),
Span::test_data(),
),
Value::date(
chrono::DateTime::parse_from_str(
"2025-04-04 00:00:00 +0000",
"%Y-%m-%d %H:%M:%S %z",
)
.expect("date calculation should not fail in test"),
Span::test_data(),
),
],
),
Column::new(
"val".to_string(),
vec![Value::test_int(3), Value::test_int(4)],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
]
}
fn run(

View File

@ -6,9 +6,9 @@ use nu_protocol::{
use polars::prelude::LazyFrame;
use crate::{
dataframe::values::{NuExpression, NuLazyFrame},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{NuExpression, NuLazyFrame},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use crate::values::{Column, NuDataFrame};

View File

@ -1,6 +1,6 @@
use crate::{
values::{Column, CustomValueSupport, NuLazyFrame, PolarsPluginObject},
PolarsPlugin,
values::{Column, CustomValueSupport, NuLazyFrame, PolarsPluginObject},
};
use crate::values::{NuDataFrame, NuExpression};

View File

@ -4,9 +4,9 @@ use nu_protocol::{
};
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame},
values::CustomValueSupport,
PolarsPlugin,
};
use super::explode::explode;
@ -47,54 +47,62 @@ impl PluginCommand for LazyFlatten {
fn examples(&self) -> Vec<Example> {
vec![
Example {
Example {
description: "Flatten the specified dataframe",
example: "[[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]] | polars into-df | polars flatten hobbies | polars collect",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"id".to_string(),
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(2),
Value::test_int(2),
]),
Column::new(
"name".to_string(),
vec![
Value::test_string("Mercy"),
Value::test_string("Mercy"),
Value::test_string("Bob"),
Value::test_string("Bob"),
]),
Column::new(
"hobbies".to_string(),
vec![
Value::test_string("Cycling"),
Value::test_string("Knitting"),
Value::test_string("Skiing"),
Value::test_string("Football"),
]),
], None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"id".to_string(),
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(2),
Value::test_int(2),
],
),
Column::new(
"name".to_string(),
vec![
Value::test_string("Mercy"),
Value::test_string("Mercy"),
Value::test_string("Bob"),
Value::test_string("Bob"),
],
),
Column::new(
"hobbies".to_string(),
vec![
Value::test_string("Cycling"),
Value::test_string("Knitting"),
Value::test_string("Skiing"),
Value::test_string("Football"),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
)
),
},
Example {
Example {
description: "Select a column and flatten the values",
example: "[[id name hobbies]; [1 Mercy [Cycling Knitting]] [2 Bob [Skiing Football]]] | polars into-df | polars select (polars col hobbies | polars flatten)",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"hobbies".to_string(),
NuDataFrame::try_from_columns(
vec![Column::new(
"hobbies".to_string(),
vec![
Value::test_string("Cycling"),
Value::test_string("Knitting"),
Value::test_string("Skiing"),
Value::test_string("Football"),
]),
], None)
],
)],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),

View File

@ -5,7 +5,7 @@ use nu_protocol::{
};
use crate::{
dataframe::values::utils::convert_columns_string, values::CustomValueSupport, PolarsPlugin,
PolarsPlugin, dataframe::values::utils::convert_columns_string, values::CustomValueSupport,
};
use crate::values::{Column, NuDataFrame};

View File

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

View File

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

View File

@ -1,9 +1,9 @@
use crate::{
values::{Column, CustomValueSupport, NuLazyFrame, PolarsPluginObject},
PolarsPlugin,
values::{Column, CustomValueSupport, NuLazyFrame, PolarsPluginObject},
};
use crate::values::{utils::DEFAULT_ROWS, NuDataFrame, NuExpression};
use crate::values::{NuDataFrame, NuExpression, utils::DEFAULT_ROWS};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,

View File

@ -1,6 +1,6 @@
use crate::{
values::{Column, CustomValueSupport, NuDataFrame, NuExpression},
PolarsPlugin,
values::{Column, CustomValueSupport, NuDataFrame, NuExpression},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
@ -33,9 +33,7 @@ impl PluginCommand for ExprLen {
example: "[[a b]; [1 2] [3 4]] | polars into-df | polars select (polars len) | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![
Column::new("len".to_string(), vec![Value::test_int(2)]),
],
vec![Column::new("len".to_string(), vec![Value::test_int(2)])],
None,
)
.expect("simple df for test should not fail")

View File

@ -1,7 +1,7 @@
use crate::{dataframe::values::NuExpression, values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, dataframe::values::NuExpression, values::CustomValueSupport};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, Signature, SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, Signature, SyntaxShape, Type, Value, record,
};
#[derive(Clone)]

View File

@ -5,12 +5,12 @@ use nu_protocol::{
};
use chrono::DateTime;
use polars_ops::pivot::{pivot, PivotAgg};
use polars_ops::pivot::{PivotAgg, pivot};
use crate::{
PolarsPlugin,
dataframe::values::utils::convert_columns_string,
values::{Column, CustomValueSupport, PolarsPluginObject},
PolarsPlugin,
};
use crate::values::NuDataFrame;
@ -88,7 +88,10 @@ impl PluginCommand for PivotDF {
vec![
Column::new(
"name".to_string(),
vec![Value::string("Cady", Span::test_data()), Value::string("Karen", Span::test_data())],
vec![
Value::string("Cady", Span::test_data()),
Value::string("Karen", Span::test_data()),
],
),
Column::new(
"date".to_string(),
@ -113,18 +116,24 @@ impl PluginCommand for PivotDF {
),
Column::new(
"maths".to_string(),
vec![Value::int(98, Span::test_data()), Value::int(61, Span::test_data())],
vec![
Value::int(98, Span::test_data()),
Value::int(61, Span::test_data()),
],
),
Column::new(
"physics".to_string(),
vec![Value::int(99, Span::test_data()), Value::int(58, Span::test_data())],
vec![
Value::int(99, Span::test_data()),
Value::int(58, Span::test_data()),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::unknown())
)
.into_value(Span::unknown()),
),
},
Example {
description: "Perform a pivot with multiple `values` columns with a separator",
@ -134,31 +143,46 @@ impl PluginCommand for PivotDF {
vec![
Column::new(
"name".to_string(),
vec![Value::string("Cady", Span::test_data()), Value::string("Karen", Span::test_data())],
vec![
Value::string("Cady", Span::test_data()),
Value::string("Karen", Span::test_data()),
],
),
Column::new(
"test_1/maths".to_string(),
vec![Value::int(98, Span::test_data()), Value::int(61, Span::test_data())],
vec![
Value::int(98, Span::test_data()),
Value::int(61, Span::test_data()),
],
),
Column::new(
"test_1/physics".to_string(),
vec![Value::int(99, Span::test_data()), Value::int(58, Span::test_data())],
vec![
Value::int(99, Span::test_data()),
Value::int(58, Span::test_data()),
],
),
Column::new(
"grade_1/maths".to_string(),
vec![Value::string("A", Span::test_data()), Value::string("D", Span::test_data())],
vec![
Value::string("A", Span::test_data()),
Value::string("D", Span::test_data()),
],
),
Column::new(
"grade_1/physics".to_string(),
vec![Value::string("A", Span::test_data()), Value::string("D", Span::test_data())],
vec![
Value::string("A", Span::test_data()),
Value::string("D", Span::test_data()),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::unknown())
)
}
.into_value(Span::unknown()),
),
},
]
}

View File

@ -3,8 +3,8 @@ use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Syntax
use polars::prelude::PlSmallStr;
use crate::{
values::{CustomValueSupport, NuDataFrame},
PolarsPlugin,
values::{CustomValueSupport, NuDataFrame},
};
pub struct QCutSeries;

View File

@ -1,9 +1,9 @@
use super::sql_context::SQLContext;
use crate::PolarsPlugin;
use crate::dataframe::values::Column;
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::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,

View File

@ -5,9 +5,9 @@ use nu_protocol::{
};
use crate::{
PolarsPlugin,
dataframe::{utils::extract_strings, values::NuLazyFrame},
values::{CustomValueSupport, PolarsPluginObject},
PolarsPlugin,
};
use crate::values::{Column, NuDataFrame};
@ -90,8 +90,7 @@ impl PluginCommand for RenameDF {
},
Example {
description: "Renames two dataframe columns",
example:
"[[a b]; [1 2] [3 4]] | polars into-df | polars rename [a b] [a_new b_new]",
example: "[[a b]; [1 2] [3 4]] | polars into-df | polars rename [a b] [a_new b_new]",
result: Some(
NuDataFrame::try_from_columns(
vec![

View File

@ -2,8 +2,8 @@ use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{Category, Example, LabeledError, PipelineData, Signature, Span, Type, Value};
use crate::{
values::{Column, CustomValueSupport, NuDataFrame, NuLazyFrame},
PolarsPlugin,
values::{Column, CustomValueSupport, NuDataFrame, NuLazyFrame},
};
pub struct LazyReverse;

View File

@ -6,7 +6,7 @@ use nu_protocol::{
use polars::prelude::NamedFrom;
use polars::series::Series;
use crate::{values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, values::CustomValueSupport};
use crate::values::{Column, NuDataFrame};
@ -62,14 +62,12 @@ impl PluginCommand for SampleDF {
},
Example {
description: "Shows sample row using fraction and replace",
example:
"[[a b]; [1 2] [3 4] [5 6]] | polars into-df | polars sample --fraction 0.5 --replace",
example: "[[a b]; [1 2] [3 4] [5 6]] | polars into-df | polars sample --fraction 0.5 --replace",
result: None, // No expected value because sampling is random
},
Example {
description: "Shows sample row using using predefined seed 1",
example:
"[[a b]; [1 2] [3 4] [5 6]] | polars into-df | polars sample --seed 1 --n-rows 1",
example: "[[a b]; [1 2] [3 4] [5 6]] | polars into-df | polars sample --seed 1 --n-rows 1",
result: Some(
NuDataFrame::try_from_columns(
vec![
@ -80,9 +78,8 @@ impl PluginCommand for SampleDF {
)
.expect("should not fail")
.into_value(Span::test_data()),
)
),
},
]
}

View File

@ -1,7 +1,7 @@
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression, NuLazyFrame},
values::CustomValueSupport,
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
@ -43,12 +43,10 @@ impl PluginCommand for LazySelect {
example: "[[a b]; [6 2] [4 2] [2 2]] | polars into-df | polars select a",
result: Some(
NuDataFrame::try_from_columns(
vec![
Column::new(
vec![Column::new(
"a".to_string(),
vec![Value::test_int(6), Value::test_int(4), Value::test_int(2)],
)
],
)],
None,
)
.expect("simple df for test should not fail")
@ -77,14 +75,17 @@ impl PluginCommand for LazySelect {
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(6), Value::test_int(4), Value::test_int(2)]),
"a".to_string(),
vec![Value::test_int(6), Value::test_int(4), Value::test_int(2)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2), Value::test_int(2)]),
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2), Value::test_int(2)],
),
Column::new(
"c".to_string(),
vec![Value::test_int(36), Value::test_int(16), Value::test_int(4)])
"c".to_string(),
vec![Value::test_int(36), Value::test_int(16), Value::test_int(4)],
),
],
None,
)

View File

@ -1,7 +1,7 @@
use crate::{
dataframe::values::{NuExpression, NuLazyFrame},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::{NuExpression, NuLazyFrame},
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use crate::values::{Column, NuDataFrame};
@ -63,8 +63,7 @@ impl PluginCommand for Shift {
},
Example {
description: "Shifts the values by a given period, fill absent values with 0",
example:
"[1 2 2 3 3] | polars into-lazy | polars shift 2 --fill 0 | polars collect",
example: "[1 2 2 3 3] | polars into-lazy | polars shift 2 --fill 0 | polars collect",
result: Some(
NuDataFrame::try_from_columns(
vec![Column::new(

View File

@ -4,7 +4,7 @@ use nu_protocol::{
Value,
};
use crate::{dataframe::values::Column, values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, dataframe::values::Column, values::CustomValueSupport};
use crate::values::NuDataFrame;

View File

@ -1,8 +1,8 @@
use crate::values::NuLazyFrame;
use crate::{
PolarsPlugin,
dataframe::values::{Column, NuDataFrame, NuExpression},
values::CustomValueSupport,
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
@ -57,45 +57,50 @@ impl PluginCommand for LazySortBy {
description: "Sort dataframe by one column",
example: "[[a b]; [6 2] [1 4] [4 1]] | polars into-df | polars sort-by a",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(4), Value::test_int(6)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(4), Value::test_int(1), Value::test_int(2)],
),
], None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(4), Value::test_int(6)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(4), Value::test_int(1), Value::test_int(2)],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
Example {
description: "Sort column using two columns",
example:
"[[a b]; [6 2] [1 1] [1 4] [2 4]] | polars into-df | polars sort-by [a b] -r [false true]",
example: "[[a b]; [6 2] [1 1] [1 4] [2 4]] | polars into-df | polars sort-by [a b] -r [false true]",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"a".to_string(),
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(2),
Value::test_int(6),
],
),
Column::new(
"b".to_string(),
vec![
Value::test_int(4),
Value::test_int(1),
Value::test_int(4),
Value::test_int(2),
],
),
], None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"a".to_string(),
vec![
Value::test_int(1),
Value::test_int(1),
Value::test_int(2),
Value::test_int(6),
],
),
Column::new(
"b".to_string(),
vec![
Value::test_int(4),
Value::test_int(1),
Value::test_int(4),
Value::test_int(2),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),

View File

@ -1,6 +1,6 @@
use crate::dataframe::command::data::sql_expr::parse_sql_expr;
use polars::error::{ErrString, PolarsError};
use polars::prelude::{col, DataFrame, DataType, IntoLazy, LazyFrame};
use polars::prelude::{DataFrame, DataType, IntoLazy, LazyFrame, col};
use sqlparser::ast::{
Expr as SqlExpr, GroupByExpr, Select, SelectItem, SetExpr, Statement, TableFactor,
Value as SQLValue,
@ -198,7 +198,7 @@ impl SQLContext {
_ => {
return Err(PolarsError::ComputeError(
"INSERT, UPDATE is not supported for polars".into(),
))
));
}
};
match &query.limit {
@ -214,14 +214,14 @@ impl SQLContext {
_ => {
return Err(PolarsError::ComputeError(
"Only support number argument to LIMIT clause".into(),
))
));
}
}
}
_ => {
return Err(PolarsError::ComputeError(
format!("Statement type {ast:?} is not supported").into(),
))
));
}
})
}

View File

@ -1,5 +1,5 @@
use polars::error::PolarsError;
use polars::prelude::{col, lit, DataType, Expr, LiteralValue, PolarsResult as Result, TimeUnit};
use polars::prelude::{DataType, Expr, LiteralValue, PolarsResult as Result, TimeUnit, col, lit};
use sqlparser::ast::{
ArrayElemTypeDef, BinaryOperator as SQLBinaryOperator, DataType as SQLDataType,
@ -40,13 +40,13 @@ fn map_sql_polars_datatype(data_type: &SQLDataType) -> Result<DataType> {
_ => {
return Err(PolarsError::ComputeError(
"SQL Datatype Array(None) was not supported in polars-sql yet!".into(),
))
));
}
},
_ => {
return Err(PolarsError::ComputeError(
format!("SQL Datatype {data_type:?} was not supported in polars-sql yet!").into(),
))
));
}
})
}
@ -78,7 +78,7 @@ fn binary_op_(left: Expr, right: Expr, op: &SQLBinaryOperator) -> Result<Expr> {
_ => {
return Err(PolarsError::ComputeError(
format!("SQL Operator {op:?} was not supported in polars-sql yet!").into(),
))
));
}
})
}
@ -106,7 +106,7 @@ fn literal_expr(value: &SqlValue) -> Result<Expr> {
_ => {
return Err(PolarsError::ComputeError(
format!("Parsing SQL Value {value:?} was not supported in polars-sql yet!").into(),
))
));
}
})
}
@ -128,7 +128,7 @@ pub fn parse_sql_expr(expr: &SqlExpr) -> Result<Expr> {
_ => {
return Err(PolarsError::ComputeError(
format!("Expression: {expr:?} was not supported in polars-sql yet!").into(),
))
));
}
})
}
@ -150,7 +150,7 @@ fn apply_window_spec(expr: Expr, window_type: Option<&WindowType>) -> Result<Exp
WindowType::NamedWindow(_named) => {
return Err(PolarsError::ComputeError(
format!("Expression: {expr:?} was not supported in polars-sql yet!").into(),
))
));
}
},
None => expr,
@ -179,31 +179,23 @@ fn parse_sql_function(sql_function: &SQLFunction) -> Result<Expr> {
FunctionArg::ExprNamed { arg, .. } => arg,
})
.collect::<Vec<_>>();
Ok(
match (
function_name.as_str(),
args.as_slice(),
distinct,
) {
("sum", [FunctionArgExpr::Expr(ref expr)], false) => {
apply_window_spec(parse_sql_expr(expr)?, sql_function.over.as_ref())?.sum()
}
("count", [FunctionArgExpr::Expr(ref expr)], false) => {
apply_window_spec(parse_sql_expr(expr)?, sql_function.over.as_ref())?.count()
}
("count", [FunctionArgExpr::Expr(ref expr)], true) => {
apply_window_spec(parse_sql_expr(expr)?, sql_function.over.as_ref())?.n_unique()
}
// Special case for wildcard args to count function.
("count", [FunctionArgExpr::Wildcard], false) => lit(1i32).count(),
_ => {
return Err(PolarsError::ComputeError(
format!(
"Function {function_name:?} with args {args:?} was not supported in polars-sql yet!"
)
.into(),
))
}
},
)
Ok(match (function_name.as_str(), args.as_slice(), distinct) {
("sum", [FunctionArgExpr::Expr(expr)], false) => {
apply_window_spec(parse_sql_expr(expr)?, sql_function.over.as_ref())?.sum()
}
("count", [FunctionArgExpr::Expr(expr)], false) => {
apply_window_spec(parse_sql_expr(expr)?, sql_function.over.as_ref())?.count()
}
("count", [FunctionArgExpr::Expr(expr)], true) => {
apply_window_spec(parse_sql_expr(expr)?, sql_function.over.as_ref())?.n_unique()
}
// Special case for wildcard args to count function.
("count", [FunctionArgExpr::Wildcard], false) => lit(1i32).count(),
_ => return Err(PolarsError::ComputeError(
format!(
"Function {function_name:?} with args {args:?} was not supported in polars-sql yet!"
)
.into(),
)),
})
}

View File

@ -3,8 +3,8 @@ use nu_protocol::{Category, Example, LabeledError, PipelineData, Signature, Span
use polars::df;
use crate::{
values::{CustomValueSupport, NuDataFrame, NuExpression},
PolarsPlugin,
values::{CustomValueSupport, NuDataFrame, NuExpression},
};
#[derive(Clone)]

View File

@ -5,7 +5,7 @@ use nu_protocol::{
};
use polars::prelude::DataType;
use crate::{dataframe::values::Column, values::CustomValueSupport, PolarsPlugin};
use crate::{PolarsPlugin, dataframe::values::Column, values::CustomValueSupport};
use crate::values::NuDataFrame;

View File

@ -1,10 +1,10 @@
use crate::{
PolarsPlugin,
dataframe::{
utils::{extract_sm_strs, extract_strings},
values::NuLazyFrame,
},
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use crate::values::{Column, NuDataFrame};
@ -77,16 +77,16 @@ impl PluginCommand for Unique {
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(1), Value::test_int(2)]
vec![Value::test_int(1), Value::test_int(2)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2)]
vec![Value::test_int(2), Value::test_int(2)],
),
Column::new(
"c".to_string(),
vec![Value::test_int(1), Value::test_int(2)]
)
vec![Value::test_int(1), Value::test_int(2)],
),
],
None,
)
@ -105,16 +105,16 @@ impl PluginCommand for Unique {
vec![
Column::new(
"a".to_string(),
vec![Value::test_int(2), Value::test_int(3)]
vec![Value::test_int(2), Value::test_int(3)],
),
Column::new(
"b".to_string(),
vec![Value::test_int(2), Value::test_int(2)]
vec![Value::test_int(2), Value::test_int(2)],
),
Column::new(
"c".to_string(),
vec![Value::test_int(2), Value::test_int(1)]
)
vec![Value::test_int(2), Value::test_int(1)],
),
],
None,
)

View File

@ -5,8 +5,8 @@ use nu_protocol::{
use polars::df;
use crate::{
values::{CustomValueSupport, NuLazyFrame, PolarsPluginObject},
PolarsPlugin,
values::{CustomValueSupport, NuLazyFrame, PolarsPluginObject},
};
use crate::values::NuDataFrame;

View File

@ -7,9 +7,9 @@ use polars::{frame::explode::UnpivotArgsIR, prelude::UnpivotArgsDSL};
use polars_ops::pivot::UnpivotDF;
use crate::{
dataframe::values::utils::convert_columns_string,
values::{utils::convert_columns_sm_str, CustomValueSupport, NuLazyFrame, PolarsPluginObject},
PolarsPlugin,
dataframe::values::utils::convert_columns_string,
values::{CustomValueSupport, NuLazyFrame, PolarsPluginObject, utils::convert_columns_sm_str},
};
use crate::values::{Column, NuDataFrame};
@ -65,114 +65,118 @@ impl PluginCommand for Unpivot {
vec![
Example {
description: "unpivot on an eager dataframe",
example:
"[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | polars into-df | polars unpivot -i [b c] -o [a d]",
example: "[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | polars into-df | polars unpivot -i [b c] -o [a d]",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"b".to_string(),
vec![
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
],
),
Column::new(
"c".to_string(),
vec![
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
],
),
Column::new(
"variable".to_string(),
vec![
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("d"),
Value::test_string("d"),
Value::test_string("d"),
],
),
Column::new(
"value".to_string(),
vec![
Value::test_string("x"),
Value::test_string("y"),
Value::test_string("z"),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
),
], None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"b".to_string(),
vec![
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
],
),
Column::new(
"c".to_string(),
vec![
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
],
),
Column::new(
"variable".to_string(),
vec![
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("d"),
Value::test_string("d"),
Value::test_string("d"),
],
),
Column::new(
"value".to_string(),
vec![
Value::test_string("x"),
Value::test_string("y"),
Value::test_string("z"),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
Example {
description: "unpivot on a lazy dataframe",
example:
"[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | polars into-lazy | polars unpivot -i [b c] -o [a d] | polars collect",
example: "[[a b c d]; [x 1 4 a] [y 2 5 b] [z 3 6 c]] | polars into-lazy | polars unpivot -i [b c] -o [a d] | polars collect",
result: Some(
NuDataFrame::try_from_columns(vec![
Column::new(
"b".to_string(),
vec![
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
],
),
Column::new(
"c".to_string(),
vec![
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
],
),
Column::new(
"variable".to_string(),
vec![
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("d"),
Value::test_string("d"),
Value::test_string("d"),
],
),
Column::new(
"value".to_string(),
vec![
Value::test_string("x"),
Value::test_string("y"),
Value::test_string("z"),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
),
], None)
NuDataFrame::try_from_columns(
vec![
Column::new(
"b".to_string(),
vec![
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
Value::test_int(1),
Value::test_int(2),
Value::test_int(3),
],
),
Column::new(
"c".to_string(),
vec![
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
Value::test_int(4),
Value::test_int(5),
Value::test_int(6),
],
),
Column::new(
"variable".to_string(),
vec![
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("a"),
Value::test_string("d"),
Value::test_string("d"),
Value::test_string("d"),
],
),
Column::new(
"value".to_string(),
vec![
Value::test_string("x"),
Value::test_string("y"),
Value::test_string("z"),
Value::test_string("a"),
Value::test_string("b"),
Value::test_string("c"),
],
),
],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
}
},
]
}

View File

@ -1,8 +1,8 @@
use crate::values::{Column, NuDataFrame};
use crate::{
PolarsPlugin,
dataframe::values::{NuExpression, NuLazyFrame},
values::{CustomValueSupport, PolarsPluginObject},
PolarsPlugin,
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{

View File

@ -1,19 +1,19 @@
use crate::{
values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuExpression, NuLazyFrame,
NuSchema, PolarsPluginObject, PolarsPluginType,
},
PolarsPlugin,
values::{
Column, CustomValueSupport, NuDataFrame, NuExpression, NuLazyFrame, NuSchema,
PolarsPluginObject, PolarsPluginType, cant_convert_err,
},
};
use chrono::DateTime;
use std::sync::Arc;
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{
record, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span,
SyntaxShape, Type, Value,
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
Value, record,
};
use polars::prelude::{col, DataType, Field, IntoSeries, Schema, StringMethods, StrptimeOptions};
use polars::prelude::{DataType, Field, IntoSeries, Schema, StringMethods, StrptimeOptions, col};
#[derive(Clone)]
pub struct AsDate;

View File

@ -1,9 +1,9 @@
use crate::{
values::{
cant_convert_err, Column, CustomValueSupport, NuDataFrame, NuExpression, NuLazyFrame,
NuSchema, PolarsPluginObject, PolarsPluginType,
},
PolarsPlugin,
values::{
Column, CustomValueSupport, NuDataFrame, NuExpression, NuLazyFrame, NuSchema,
PolarsPluginObject, PolarsPluginType, cant_convert_err,
},
};
use chrono::DateTime;
use std::sync::Arc;
@ -14,8 +14,8 @@ use nu_protocol::{
Value,
};
use polars::prelude::{
col, DataType, Expr, Field, IntoSeries, LiteralValue, PlSmallStr, Schema, StringMethods,
StrptimeOptions, TimeUnit,
DataType, Expr, Field, IntoSeries, LiteralValue, PlSmallStr, Schema, StringMethods,
StrptimeOptions, TimeUnit, col,
};
#[derive(Clone)]
@ -138,10 +138,7 @@ impl PluginCommand for AsDateTime {
Some(NuSchema::new(Arc::new(Schema::from_iter(vec![
Field::new(
"datetime".into(),
DataType::Datetime(
TimeUnit::Nanoseconds,
None
),
DataType::Datetime(TimeUnit::Nanoseconds, None),
),
])))),
)
@ -156,24 +153,19 @@ impl PluginCommand for AsDateTime {
NuDataFrame::try_from_columns(
vec![Column::new(
"datetime".to_string(),
vec![
Value::date(
DateTime::parse_from_str(
"2021-12-30 00:00:00 +0000",
"%Y-%m-%d %H:%M:%S %z",
)
.expect("date calculation should not fail in test"),
Span::test_data(),
),
],
vec![Value::date(
DateTime::parse_from_str(
"2021-12-30 00:00:00 +0000",
"%Y-%m-%d %H:%M:%S %z",
)
.expect("date calculation should not fail in test"),
Span::test_data(),
)],
)],
Some(NuSchema::new(Arc::new(Schema::from_iter(vec![
Field::new(
"datetime".into(),
DataType::Datetime(
TimeUnit::Nanoseconds,
None
),
DataType::Datetime(TimeUnit::Nanoseconds, None),
),
])))),
)
@ -197,7 +189,6 @@ impl PluginCommand for AsDateTime {
.expect("date calculation should not fail in test"),
Span::test_data(),
),
Value::date(
DateTime::parse_from_str(
"2025-11-02 01:00:00 +0000",
@ -227,10 +218,7 @@ impl PluginCommand for AsDateTime {
Some(NuSchema::new(Arc::new(Schema::from_iter(vec![
Field::new(
"datetime".into(),
DataType::Datetime(
TimeUnit::Nanoseconds,
None
),
DataType::Datetime(TimeUnit::Nanoseconds, None),
),
])))),
)

View File

@ -1,8 +1,8 @@
use crate::values::{Column, NuDataFrame, NuSchema};
use crate::{
dataframe::values::NuExpression,
values::{cant_convert_err, CustomValueSupport, PolarsPluginObject, PolarsPluginType},
PolarsPlugin,
dataframe::values::NuExpression,
values::{CustomValueSupport, PolarsPluginObject, PolarsPluginType, cant_convert_err},
};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};

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