Skip to content

Commit 2bc71fb

Browse files
ayax79Jack Wright
andauthored
Polars input/output types cleanup (nushell#16819)
Cleans up input output types ahead of the nushell#16079 There will possibly be more breakages, this however should fix most of them. There is only one user facing changes. The polars types will now be prefixed with polars_ (e.g. polars_dataframe) --------- Co-authored-by: Jack Wright <[email protected]>
1 parent 1f68415 commit 2bc71fb

File tree

132 files changed

+1147
-675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+1147
-675
lines changed

crates/nu_plugin_polars/src/cache/get.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use uuid::Uuid;
88

99
use crate::{
1010
PolarsPlugin,
11-
values::{CustomValueSupport, NuDataFrame},
11+
values::{CustomValueSupport, NuDataFrame, PolarsPluginType},
1212
};
1313

1414
#[derive(Clone)]
@@ -28,10 +28,12 @@ impl PluginCommand for CacheGet {
2828
fn signature(&self) -> Signature {
2929
Signature::build(self.name())
3030
.required("key", SyntaxShape::String, "Key of objects to get")
31-
.input_output_types(vec![
32-
(Type::Any, Type::Custom("dataframe".into())),
33-
(Type::Any, Type::Custom("expression".into())),
34-
])
31+
.input_output_types(
32+
PolarsPluginType::types()
33+
.iter()
34+
.map(|t| (Type::Any, Type::from(*t)))
35+
.collect(),
36+
)
3537
.category(Category::Custom("dataframe".into()))
3638
}
3739

crates/nu_plugin_polars/src/dataframe/command/aggregation/agg_groups.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::values::{
44
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
55
};
66
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
7-
use nu_protocol::{
8-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,
9-
};
7+
use nu_protocol::{Category, Example, LabeledError, PipelineData, ShellError, Signature, Span};
108
use polars::df;
119
use polars::series::Series;
1210

@@ -26,8 +24,8 @@ impl PluginCommand for ExprAggGroups {
2624
fn signature(&self) -> Signature {
2725
Signature::build(self.name())
2826
.input_output_types(vec![(
29-
Type::Custom("expression".into()),
30-
Type::Custom("expression".into()),
27+
PolarsPluginType::NuExpression.into(),
28+
PolarsPluginType::NuExpression.into(),
3129
)])
3230
.category(Category::Custom("dataframe".into()))
3331
}

crates/nu_plugin_polars/src/dataframe/command/aggregation/aggregate.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::{
22
PolarsPlugin,
33
dataframe::values::{NuExpression, NuLazyFrame, NuLazyGroupBy},
4-
values::{Column, CustomValueSupport, NuDataFrame},
4+
values::{Column, CustomValueSupport, NuDataFrame, PolarsPluginType},
55
};
66

77
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
88
use nu_protocol::{
9-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
10-
Value,
9+
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
1110
};
1211
use polars::{datatypes::DataType, prelude::Expr};
1312

@@ -32,10 +31,16 @@ impl PluginCommand for LazyAggregate {
3231
SyntaxShape::Any,
3332
"Expression(s) that define the aggregations to be applied",
3433
)
35-
.input_output_type(
36-
Type::Custom("dataframe".into()),
37-
Type::Custom("dataframe".into()),
38-
)
34+
.input_output_types(vec![
35+
(
36+
PolarsPluginType::NuDataFrame.into(),
37+
PolarsPluginType::NuDataFrame.into(),
38+
),
39+
(
40+
PolarsPluginType::NuLazyFrame.into(),
41+
PolarsPluginType::NuLazyFrame.into(),
42+
),
43+
])
3944
.category(Category::Custom("lazyframe".into()))
4045
}
4146

crates/nu_plugin_polars/src/dataframe/command/aggregation/count.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::values::{
44
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
55
};
66
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
7-
use nu_protocol::{
8-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,
9-
};
7+
use nu_protocol::{Category, Example, LabeledError, PipelineData, ShellError, Signature, Span};
108
use polars::df;
119

1210
pub struct ExprCount;
@@ -25,8 +23,8 @@ impl PluginCommand for ExprCount {
2523
fn signature(&self) -> Signature {
2624
Signature::build(self.name())
2725
.input_output_types(vec![(
28-
Type::Custom("expression".into()),
29-
Type::Custom("expression".into()),
26+
PolarsPluginType::NuExpression.into(),
27+
PolarsPluginType::NuExpression.into(),
3028
)])
3129
.category(Category::Custom("dataframe".into()))
3230
}

crates/nu_plugin_polars/src/dataframe/command/aggregation/cumulative.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::values::{
77
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
88
use nu_protocol::{
99
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,
10-
SyntaxShape, Type, Value,
10+
SyntaxShape, Value,
1111
};
1212
use polars::prelude::{DataType, IntoSeries, cum_max, cum_min, cum_sum};
1313

@@ -66,12 +66,16 @@ impl PluginCommand for Cumulative {
6666
.switch("reverse", "Reverse cumulative calculation", Some('r'))
6767
.input_output_types(vec![
6868
(
69-
Type::Custom("dataframe".into()),
70-
Type::Custom("dataframe".into()),
69+
PolarsPluginType::NuDataFrame.into(),
70+
PolarsPluginType::NuDataFrame.into(),
7171
),
7272
(
73-
Type::Custom("expression".into()),
74-
Type::Custom("expression".into()),
73+
PolarsPluginType::NuLazyFrame.into(),
74+
PolarsPluginType::NuLazyFrame.into(),
75+
),
76+
(
77+
PolarsPluginType::NuExpression.into(),
78+
PolarsPluginType::NuExpression.into(),
7579
),
7680
])
7781
.category(Category::Custom("dataframe".into()))

crates/nu_plugin_polars/src/dataframe/command/aggregation/groupby.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::{
22
PolarsPlugin,
33
dataframe::values::{NuDataFrame, NuExpression, NuLazyFrame, NuLazyGroupBy},
4-
values::CustomValueSupport,
4+
values::{CustomValueSupport, PolarsPluginType},
55
};
66
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
77
use nu_protocol::{
8-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
9-
Value,
8+
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Value,
109
};
1110
use polars::{df, prelude::Expr};
1211

@@ -35,10 +34,16 @@ impl PluginCommand for ToLazyGroupBy {
3534
"maintain-order",
3635
"Ensure that the order of the groups is consistent with the input data. This is slower than a default group by and cannot be run on the streaming engine.",
3736
Some('m'))
38-
.input_output_type(
39-
Type::Custom("dataframe".into()),
40-
Type::Custom("dataframe".into()),
41-
)
37+
.input_output_types(vec![
38+
(
39+
PolarsPluginType::NuDataFrame.into(),
40+
PolarsPluginType::NuDataFrame.into(),
41+
),
42+
(
43+
PolarsPluginType::NuLazyFrame.into(),
44+
PolarsPluginType::NuLazyFrame.into(),
45+
),
46+
])
4247
.category(Category::Custom("lazyframe".into()))
4348
}
4449

crates/nu_plugin_polars/src/dataframe/command/aggregation/horizontal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
PolarsPlugin,
3-
values::{Column, CustomValueSupport, NuDataFrame, NuExpression},
3+
values::{Column, CustomValueSupport, NuDataFrame, NuExpression, PolarsPluginType},
44
};
55

66
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
@@ -59,7 +59,7 @@ impl PluginCommand for Horizontal {
5959

6060
fn signature(&self) -> Signature {
6161
Signature::build(self.name())
62-
.input_output_type(Type::Any, Type::Custom("expression".into()))
62+
.input_output_type(Type::Any, PolarsPluginType::NuExpression.into())
6363
.required(
6464
"type",
6565
SyntaxShape::String,

crates/nu_plugin_polars/src/dataframe/command/aggregation/implode.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::values::{
44
CustomValueSupport, NuDataFrame, PolarsPluginObject, PolarsPluginType, cant_convert_err,
55
};
66
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
7-
use nu_protocol::{
8-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type,
9-
};
7+
use nu_protocol::{Category, Example, LabeledError, PipelineData, ShellError, Signature, Span};
108
use polars::df;
119
use polars::series::Series;
1210

@@ -26,8 +24,8 @@ impl PluginCommand for ExprImplode {
2624
fn signature(&self) -> Signature {
2725
Signature::build(self.name())
2826
.input_output_type(
29-
Type::Custom("expression".into()),
30-
Type::Custom("expression".into()),
27+
PolarsPluginType::NuExpression.into(),
28+
PolarsPluginType::NuExpression.into(),
3129
)
3230
.category(Category::Custom("dataframe".into()))
3331
}

crates/nu_plugin_polars/src/dataframe/command/aggregation/max.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::values::{
66
};
77
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
88
use nu_protocol::{
9-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
9+
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Value,
1010
};
1111

1212
pub struct ExprMax;
@@ -26,12 +26,16 @@ impl PluginCommand for ExprMax {
2626
Signature::build(self.name())
2727
.input_output_types(vec![
2828
(
29-
Type::Custom("expression".into()),
30-
Type::Custom("expression".into()),
29+
PolarsPluginType::NuExpression.into(),
30+
PolarsPluginType::NuExpression.into(),
3131
),
3232
(
33-
Type::Custom("dataframe".into()),
34-
Type::Custom("dataframe".into()),
33+
PolarsPluginType::NuDataFrame.into(),
34+
PolarsPluginType::NuDataFrame.into(),
35+
),
36+
(
37+
PolarsPluginType::NuLazyFrame.into(),
38+
PolarsPluginType::NuLazyFrame.into(),
3539
),
3640
])
3741
.category(Category::Custom("dataframe".into()))

crates/nu_plugin_polars/src/dataframe/command/aggregation/mean.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::values::{
66
};
77
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
88
use nu_protocol::{
9-
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Type, Value,
9+
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Value,
1010
};
1111

1212
pub struct ExprMean;
@@ -26,12 +26,16 @@ impl PluginCommand for ExprMean {
2626
Signature::build(self.name())
2727
.input_output_types(vec![
2828
(
29-
Type::Custom("expression".into()),
30-
Type::Custom("expression".into()),
29+
PolarsPluginType::NuExpression.into(),
30+
PolarsPluginType::NuExpression.into(),
3131
),
3232
(
33-
Type::Custom("dataframe".into()),
34-
Type::Custom("dataframe".into()),
33+
PolarsPluginType::NuDataFrame.into(),
34+
PolarsPluginType::NuDataFrame.into(),
35+
),
36+
(
37+
PolarsPluginType::NuLazyFrame.into(),
38+
PolarsPluginType::NuLazyFrame.into(),
3539
),
3640
])
3741
.category(Category::Custom("dataframe".into()))

0 commit comments

Comments
 (0)