update polars (#5791)

This commit is contained in:
Fernando Herrera
2022-06-15 11:45:03 -05:00
committed by GitHub
parent cb66d2bcad
commit 38f3957edf
16 changed files with 73 additions and 58 deletions

View File

@ -97,7 +97,7 @@ version = "2.1.3"
optional = true
[dependencies.polars]
version = "0.21.1"
version = "0.22.8"
# path = "../../../../polars/polars"
optional = true
features = [
@ -105,7 +105,7 @@ features = [
"object", "checked_arithmetic", "strings", "cum_agg", "is_in",
"rolling_window", "strings", "rows", "random",
"dtype-datetime", "dtype-struct", "lazy", "cross_join",
"dynamic_groupby"
"dynamic_groupby", "dtype-categorical"
]
[target.'cfg(windows)'.dependencies.windows]

View File

@ -155,7 +155,7 @@ fn from_json(
call: &Call,
) -> Result<polars::prelude::DataFrame, ShellError> {
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let mut file = File::open(&file.item).map_err(|e| {
let file = File::open(&file.item).map_err(|e| {
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
@ -165,7 +165,7 @@ fn from_json(
)
})?;
let buf_reader = BufReader::new(&mut file);
let buf_reader = BufReader::new(file);
let reader = JsonReader::new(buf_reader);
reader.finish().map_err(|e| {

View File

@ -40,6 +40,7 @@ impl Command for SampleDF {
Some('s'),
)
.switch("replace", "sample with replace", Some('e'))
.switch("shuffle", "shuffle sample", Some('u'))
.category(Category::Custom("dataframe".into()))
}
@ -89,22 +90,26 @@ fn command(
.get_flag::<i64>(engine_state, stack, "seed")?
.map(|val| val as u64);
let replace: bool = call.has_flag("replace");
let shuffle: bool = call.has_flag("shuffle");
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
match (rows, fraction) {
(Some(rows), None) => df.as_ref().sample_n(rows.item, replace, seed).map_err(|e| {
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
Some(rows.span),
None,
Vec::new(),
)
}),
(Some(rows), None) => df
.as_ref()
.sample_n(rows.item, replace, shuffle, seed)
.map_err(|e| {
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
Some(rows.span),
None,
Vec::new(),
)
}),
(None, Some(frac)) => df
.as_ref()
.sample_frac(frac.item, replace, seed)
.sample_frac(frac.item, replace, shuffle, seed)
.map_err(|e| {
ShellError::GenericError(
"Error creating sample".into(),

View File

@ -99,7 +99,7 @@ fn command(
writer.has_header(true)
};
let writer = match delimiter {
let mut writer = match delimiter {
None => writer,
Some(d) => {
if d.item.len() != 1 {

View File

@ -32,7 +32,7 @@ impl Command for GetWeekDay {
result: Some(
NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(),
vec![Value::test_int(1), Value::test_int(1)],
vec![Value::test_int(2), Value::test_int(2)],
)])
.expect("simple df for test should not fail")
.into_value(Span::test_data()),

View File

@ -7,7 +7,7 @@ use nu_protocol::{
Category, Example, PipelineData, ShellError, Signature, Span, Spanned, SyntaxShape, Type,
Value,
};
use polars::prelude::{DataType, IntoSeries, RollingOptions};
use polars::prelude::{DataType, Duration, IntoSeries, RollingOptionsImpl, SeriesOpsTime};
enum RollType {
Min,
@ -127,7 +127,7 @@ fn command(
input: PipelineData,
) -> Result<PipelineData, ShellError> {
let roll_type: Spanned<String> = call.req(engine_state, stack, 0)?;
let window_size: usize = call.req(engine_state, stack, 1)?;
let window_size: i64 = call.req(engine_state, stack, 1)?;
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
@ -144,11 +144,14 @@ fn command(
let roll_type = RollType::from_str(&roll_type.item, roll_type.span)?;
let rolling_opts = RollingOptions {
window_size,
min_periods: window_size,
let rolling_opts = RollingOptionsImpl {
window_size: Duration::new(window_size),
min_periods: window_size as usize,
weights: None,
center: false,
by: None,
closed_window: None,
tu: None,
};
let res = match roll_type {
RollType::Max => series.rolling_max(rolling_opts),

View File

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct Concatenate;

View File

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct Contains;

View File

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct Replace;

View File

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct ReplaceAll;

View File

@ -5,7 +5,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct StrLengths;

View File

@ -6,7 +6,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct StrSlice;

View File

@ -5,7 +5,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct ToLowerCase;

View File

@ -5,7 +5,7 @@ use nu_protocol::{
engine::{Command, EngineState, Stack},
Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
};
use polars::prelude::IntoSeries;
use polars::prelude::{IntoSeries, Utf8NameSpaceImpl};
#[derive(Clone)]
pub struct ToUpperCase;

View File

@ -4,7 +4,7 @@ use nu_protocol::{ast::Operator, span, ShellError, Span, Spanned, Value};
use num::Zero;
use polars::prelude::{
BooleanType, ChunkCompare, ChunkedArray, DataType, Float64Type, Int64Type, IntoSeries,
NumOpsDispatchChecked, PolarsError, Series, TimeUnit,
NumOpsDispatchChecked, PolarsError, Series, TimeUnit, Utf8NameSpaceImpl,
};
use std::ops::{Add, BitAnd, BitOr, Div, Mul, Sub};