Bump polars from 0.36 to 0.37 (#11848)

# Description
Bump polars from 0.36 to 0.37

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
This commit is contained in:
nibon7
2024-02-13 20:27:30 +08:00
committed by GitHub
parent db4b3a561d
commit da4c918392
8 changed files with 144 additions and 80 deletions

View File

@ -25,11 +25,11 @@ indexmap = { version = "2.2" }
num = { version = "0.4", optional = true }
serde = { version = "1.0", features = ["derive"] }
sqlparser = { version = "0.43", optional = true }
polars-io = { version = "0.36", features = ["avro"], optional = true }
polars-arrow = { version = "0.36", optional = true }
polars-ops = { version = "0.36", optional = true }
polars-plan = { version = "0.36", optional = true }
polars-utils = { version = "0.36", optional = true }
polars-io = { version = "0.37", features = ["avro"], optional = true }
polars-arrow = { version = "0.37", optional = true }
polars-ops = { version = "0.37", optional = true }
polars-plan = { version = "0.37", features = ["regex"], optional = true }
polars-utils = { version = "0.37", optional = true }
[dependencies.polars]
features = [
@ -63,7 +63,7 @@ features = [
"to_dummies",
]
optional = true
version = "0.36"
version = "0.37"
[features]
dataframe = ["num", "polars", "polars-io", "polars-arrow", "polars-ops", "polars-plan", "polars-utils", "sqlparser"]

View File

@ -154,7 +154,7 @@ fn from_parquet(
cache: true,
parallel: ParallelStrategy::Auto,
rechunk: false,
row_count: None,
row_index: None,
low_memory: false,
cloud_options: None,
use_statistics: false,
@ -252,7 +252,7 @@ fn from_ipc(
n_rows: None,
cache: true,
rechunk: false,
row_count: None,
row_index: None,
memmap: true,
};

View File

@ -86,7 +86,7 @@ impl Command for ExprConcatStr {
let value: Value = call.req(engine_state, stack, 1)?;
let expressions = NuExpression::extract_exprs(value)?;
let expr: NuExpression = concat_str(expressions, &separator).into();
let expr: NuExpression = concat_str(expressions, &separator, false).into();
Ok(PipelineData::Value(expr.into_value(call.head), None))
}

View File

@ -193,7 +193,7 @@ fn get_col_name(expr: &Expr) -> Option<String> {
| Expr::Window { .. }
| Expr::Wildcard
| Expr::RenameAlias { .. }
| Expr::Count
| Expr::Len
| Expr::Nth(_)
| Expr::SubPlan(_, _)
| Expr::Selector(_) => None,

View File

@ -6,7 +6,10 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::{IntoSeries, StringNameSpaceImpl};
use polars::{
prelude::{IntoSeries, NamedFrom, StringNameSpaceImpl},
series::Series,
};
#[derive(Clone)]
pub struct StrSlice;
@ -32,25 +35,46 @@ impl Command for StrSlice {
}
fn examples(&self) -> Vec<Example> {
vec![Example {
description: "Creates slices from the strings",
example: "[abcded abc321 abc123] | dfr into-df | dfr str-slice 1 --length 2",
result: Some(
NuDataFrame::try_from_columns(
vec![Column::new(
"0".to_string(),
vec![
Value::test_string("bc"),
Value::test_string("bc"),
Value::test_string("bc"),
],
)],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
}]
vec![
Example {
description: "Creates slices from the strings",
example: "[abcded abc321 abc123] | dfr into-df | dfr str-slice 1 --length 2",
result: Some(
NuDataFrame::try_from_columns(
vec![Column::new(
"0".to_string(),
vec![
Value::test_string("bc"),
Value::test_string("bc"),
Value::test_string("bc"),
],
)],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
Example {
description: "Creates slices from the strings without length",
example: "[abcded abc321 abc123] | dfr into-df | dfr str-slice 1",
result: Some(
NuDataFrame::try_from_columns(
vec![Column::new(
"0".to_string(),
vec![
Value::test_string("bcded"),
Value::test_string("bc321"),
Value::test_string("bc123"),
],
)],
None,
)
.expect("simple df for test should not fail")
.into_value(Span::test_data()),
),
},
]
}
fn run(
@ -71,9 +95,13 @@ fn command(
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let start: i64 = call.req(engine_state, stack, 0)?;
let start = Series::new("", &[start]);
let length: Option<i64> = call.get_flag(engine_state, stack, "length")?;
let length = length.map(|v| v as u64);
let length = match length {
Some(v) => Series::new("", &[v as u64]),
None => Series::new_null("", 1),
};
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
@ -86,8 +114,16 @@ fn command(
inner: vec![],
})?;
let mut res = chunked.str_slice(start, length);
res.rename(series.name());
let res = chunked
.str_slice(&start, &length)
.map_err(|e| ShellError::GenericError {
error: "Dataframe Error".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.with_name(series.name());
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
.map(|df| PipelineData::Value(NuDataFrame::into_value(df, call.head), None))

View File

@ -1426,7 +1426,7 @@ mod tests {
let test_int_arr = PrimitiveArray::from([Some(1_i32)]);
let test_bool_arr = BooleanArray::from([Some(true)]);
let test_struct_arr = StructArray::new(
DataType::Struct(fields.clone()).to_arrow(),
DataType::Struct(fields.clone()).to_arrow(true),
vec![Box::new(test_int_arr), Box::new(test_bool_arr)],
None,
);

View File

@ -252,7 +252,7 @@ pub fn expr_to_value(expr: &Expr, span: Span) -> Result<Value, ShellError> {
span,
))
}
Expr::Count => Ok(Value::record(
Expr::Len => Ok(Value::record(
record! { "expr" => Value::string("count", span) },
span,
)),