Skip to content

Commit 9ebb02d

Browse files
ayax79Jack Wright
andauthored
Polars 50.1 upgrade (nushell#16703)
Upgrade for polars 0.51.0 ## Release notes summary - What our users need to know - `polars fetch` has been removed due to no longer being supported on LazyFrame - introduced flag `--drop-nulls` to `polars dummies` - introduced flag `--separator` to `polars dummies` - introduced flag `--strict` to `polars integer` - introduced flag `--base` to `polars integer` - introduced flag `--dtype` to `polars integer` - introduced flag `--stable` to `polars pivot` - polars pivot will no longer perform a stable pivot by default, the flag `--stable` must be passed in to perform a stable pivot. - Introduced flag `--time-zone` to `polars as-datetime` - Introduced flag `--time-unit` to `polars as-datetime` --------- Co-authored-by: Jack Wright <[email protected]>
1 parent d1a8249 commit 9ebb02d

File tree

33 files changed

+726
-655
lines changed

33 files changed

+726
-655
lines changed

Cargo.lock

Lines changed: 226 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/nu_plugin_polars/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ indexmap = { version = "2.11" }
3333
num = { version = "0.4" }
3434
serde = { version = "1.0", features = ["derive"] }
3535
sqlparser = { version = "=0.53.0" }
36-
polars-io = { version = "=0.49.1", features = ["avro", "cloud", "aws"] }
37-
polars-arrow = { version = "=0.49.1" }
38-
polars-ops = { version = "=0.49.1", features = ["pivot", "cutqcut"] }
39-
polars-plan = { version = "=0.49.1", features = ["regex"] }
40-
polars-utils = { version = "=0.49.1" }
36+
polars-io = { version = "=0.51.0", features = ["avro", "cloud", "aws"] }
37+
polars-arrow = { version = "=0.51.0" }
38+
polars-ops = { version = "=0.51.0", features = ["pivot", "cutqcut"] }
39+
polars-plan = { version = "=0.51.0", features = ["regex"] }
40+
polars-utils = { version = "=0.51.0" }
41+
polars-lazy = { version = "=0.51.0" }
4142
planus = { version = "=1.1.1" } # Temporarily here to convince cargo not to upgrade planus to 1.2.0
4243
typetag = "0.2"
4344
env_logger = "0.11.3"
@@ -100,7 +101,7 @@ features = [
100101
"trigonometry",
101102
]
102103
optional = false
103-
version = "0.49"
104+
version = "=0.51.0"
104105

105106
[dev-dependencies]
106107
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.107.1" }

crates/nu_plugin_polars/src/cloud/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use nu_protocol::ShellError;
2+
use polars::prelude::PlPath;
23
use polars_io::cloud::CloudOptions;
3-
use url::Url;
4+
use polars_utils::plpath::CloudScheme;
45

56
use crate::PolarsPlugin;
67

@@ -10,18 +11,18 @@ enum CloudType {
1011
Aws,
1112
}
1213

13-
fn determine_cloud_type(url: &Url) -> Option<CloudType> {
14-
match url.scheme() {
15-
"s3" | "s3a" => Some(CloudType::Aws),
14+
fn determine_cloud_type(plpath: &PlPath) -> Option<CloudType> {
15+
match plpath.cloud_scheme() {
16+
Some(CloudScheme::S3) | Some(CloudScheme::S3a) => Some(CloudType::Aws),
1617
_ => None,
1718
}
1819
}
1920

2021
pub(crate) fn build_cloud_options(
2122
plugin: &PolarsPlugin,
22-
url: &Url,
23+
path: &PlPath,
2324
) -> Result<Option<CloudOptions>, ShellError> {
24-
match determine_cloud_type(url) {
25+
match determine_cloud_type(path) {
2526
Some(CloudType::Aws) => aws::build_cloud_options(plugin).map(Some),
2627
_ => Ok(None),
2728
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn get_col_name(expr: &Expr) -> Option<String> {
170170
| polars::prelude::AggExpr::Last(e)
171171
| polars::prelude::AggExpr::Mean(e)
172172
| polars::prelude::AggExpr::Implode(e)
173-
| polars::prelude::AggExpr::Count(e, _)
173+
| polars::prelude::AggExpr::Count { input: e, .. }
174174
| polars::prelude::AggExpr::Sum(e)
175175
| polars::prelude::AggExpr::AggGroups(e)
176176
| polars::prelude::AggExpr::Std(e, _)
@@ -183,26 +183,21 @@ fn get_col_name(expr: &Expr) -> Option<String> {
183183
| Expr::Sort { expr, .. }
184184
| Expr::Gather { expr, .. }
185185
| Expr::SortBy { expr, .. }
186-
| Expr::Exclude(expr, _)
187-
| Expr::Alias(expr, _)
188186
| Expr::KeepName(expr)
189187
| Expr::Explode { input: expr, .. } => get_col_name(expr.as_ref()),
190188
Expr::Ternary { .. }
191189
| Expr::AnonymousFunction { .. }
192190
| Expr::Function { .. }
193-
| Expr::Columns(_)
194-
| Expr::DtypeColumn(_)
195191
| Expr::Literal(_)
196192
| Expr::BinaryExpr { .. }
197193
| Expr::Window { .. }
198-
| Expr::Wildcard
199194
| Expr::RenameAlias { .. }
200195
| Expr::Len
201-
| Expr::Nth(_)
202196
| Expr::SubPlan(_, _)
203-
| Expr::IndexColumn(_)
204197
| Expr::Selector(_)
205198
| Expr::Field(_)
199+
| Expr::Alias(_, _)
200+
| Expr::DataTypeFunction(_)
206201
| Expr::Eval { .. } => None,
207202
}
208203
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use nu_protocol::{
99
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,
1010
SyntaxShape, Type, Value,
1111
};
12-
use polars::prelude::{DataType, IntoSeries};
13-
use polars_ops::prelude::{cum_max, cum_min, cum_sum};
12+
use polars::prelude::{DataType, IntoSeries, cum_max, cum_min, cum_sum};
1413

1514
enum CumulativeType {
1615
Min,

crates/nu_plugin_polars/src/dataframe/command/computation/math.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use nu_protocol::{
99
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, Spanned,
1010
SyntaxShape, Type, Value,
1111
};
12-
use num::ToPrimitive;
13-
use polars::prelude::df;
12+
use polars::prelude::{Expr, Literal, df};
1413

1514
enum FunctionType {
1615
Abs,
@@ -206,30 +205,28 @@ fn command_expr(
206205
FunctionType::Abs => res.abs(),
207206
FunctionType::Cos => res.cos(),
208207
FunctionType::Dot => {
209-
let expr = match call.rest::<Value>(1)?.first() {
210-
None => Err(ShellError::GenericError { error: "Second expression to compute dot product with must be provided".into(), msg: "".into(), span: Some(call.head), help: None, inner: vec![] }),
211-
Some(value) => {
212-
match PolarsPluginObject::try_from_value(plugin, value)? {
213-
PolarsPluginObject::NuExpression(expr) => {
214-
Ok(expr.into_polars())
215-
}
216-
_ => Err(cant_convert_err(value, &[PolarsPluginType::NuExpression]))
217-
}
208+
let expr: Expr = match call.rest::<Value>(1)?.first() {
209+
None => {
210+
return Err(ShellError::GenericError {
211+
error: "Second expression to compute dot product with must be provided"
212+
.into(),
213+
msg: "".into(),
214+
span: Some(call.head),
215+
help: None,
216+
inner: vec![],
217+
});
218218
}
219-
}?;
219+
Some(value) => NuExpression::try_from_value(plugin, value)?.into_polars(),
220+
};
220221
res.dot(expr)
221222
}
222223
FunctionType::Exp => res.exp(),
223224
FunctionType::Log => {
224-
let base = match call.rest::<Value>(1)?.first() {
225+
let base: Expr = match call.rest::<Value>(1)?.first() {
225226
// default natural log
226-
None => Ok(std::f64::consts::E),
227-
Some(value) => match value {
228-
Value::Float { val, .. } => Ok(*val),
229-
Value::Int { val, .. } => Ok(val.to_f64().expect("i64 to f64 conversion should not panic")),
230-
_ => Err(ShellError::GenericError { error: "log base must be a float or integer. Leave base unspecified for natural log".into(), msg: "".into(), span: Some(value.span()), help: None, inner: vec![] }),
231-
},
232-
}?;
227+
None => std::f64::consts::E.lit(),
228+
Some(value) => NuExpression::try_from_value(plugin, value)?.into_polars(),
229+
};
233230

234231
res.log(base)
235232
}

crates/nu_plugin_polars/src/dataframe/command/core/fetch.rs

Lines changed: 0 additions & 104 deletions
This file was deleted.

crates/nu_plugin_polars/src/dataframe/command/core/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
mod cache;
22
mod columns;
3-
mod fetch;
43
mod open;
54
mod profile;
65
mod resource;
@@ -17,7 +16,6 @@ mod to_schema;
1716

1817
pub use self::open::OpenDataFrame;
1918
use crate::PolarsPlugin;
20-
use fetch::LazyFetch;
2119
use nu_plugin::PluginCommand;
2220
pub use schema::SchemaCmd;
2321
pub use shape::ShapeDF;
@@ -31,7 +29,6 @@ pub(crate) fn core_commands() -> Vec<Box<dyn PluginCommand<Plugin = PolarsPlugin
3129
vec![
3230
Box::new(columns::ColumnsDF),
3331
Box::new(cache::LazyCache),
34-
Box::new(LazyFetch),
3532
Box::new(OpenDataFrame),
3633
Box::new(profile::ProfileDF),
3734
Box::new(Summary),

0 commit comments

Comments
 (0)