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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 73 additions and 58 deletions

63
Cargo.lock generated
View File

@ -131,9 +131,9 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
[[package]] [[package]]
name = "arrow-format" name = "arrow-format"
version = "0.4.0" version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2333f8ccf0d597ba779863c57a0b61f635721187fb2fdeabae92691d7d582fe5" checksum = "216249afef413d7e9e9b4b543e73b3e371ace3a812380af98f1c871521572cdd"
dependencies = [ dependencies = [
"planus", "planus",
"serde", "serde",
@ -141,26 +141,24 @@ dependencies = [
[[package]] [[package]]
name = "arrow2" name = "arrow2"
version = "0.11.2" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b040061368d1314b0fd8b8f1fde0671eba1afc63a1c61a4dafaf2d4fc10c96f9" checksum = "5feafd6df4e3f577529e6aa2b9b7cdb3c9fe8e8f66ebc8dc29abbe71a7e968f0"
dependencies = [ dependencies = [
"arrow-format", "arrow-format",
"base64", "base64",
"bytemuck", "bytemuck",
"chrono", "chrono",
"csv-core",
"either", "either",
"fallible-streaming-iterator", "fallible-streaming-iterator",
"futures", "futures",
"hash_hasher", "hash_hasher",
"indexmap", "indexmap",
"json-deserializer",
"lexical-core", "lexical-core",
"multiversion", "multiversion",
"num-traits", "num-traits",
"parquet2", "parquet2",
"serde",
"serde_json",
"simdutf8", "simdutf8",
"streaming-iterator", "streaming-iterator",
"strength_reduce", "strength_reduce",
@ -1875,6 +1873,12 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
[[package]]
name = "json-deserializer"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47631885425c482fcf2dc4b182fc973c3c5b81a8f43a028055559bd24cccfa6e"
[[package]] [[package]]
name = "kernel32-sys" name = "kernel32-sys"
version = "0.2.2" version = "0.2.2"
@ -3145,9 +3149,9 @@ dependencies = [
[[package]] [[package]]
name = "parquet2" name = "parquet2"
version = "0.12.1" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbacca5619bdee7f942938890451dea1a61f082c682aac913d7b4e326e66d7b4" checksum = "73fd2690ad041f9296876daef1f2706f6347073bdbcc719090887f1691e4a09d"
dependencies = [ dependencies = [
"async-stream", "async-stream",
"bitpacking", "bitpacking",
@ -3319,9 +3323,9 @@ dependencies = [
[[package]] [[package]]
name = "polars" name = "polars"
version = "0.21.1" version = "0.22.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b140da767e129c60c41c8e1968ffab5f114bcf823182edb7fa900464a31bf421" checksum = "3d175c67e80ceaef7219258cfc3a8686531d9510875b0cefa25404e5b80a7933"
dependencies = [ dependencies = [
"polars-core", "polars-core",
"polars-io", "polars-io",
@ -3332,9 +3336,9 @@ dependencies = [
[[package]] [[package]]
name = "polars-arrow" name = "polars-arrow"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d27df11ee28956bd6f5aed54e7e05ce87b886871995e1da501134627ec89077" checksum = "f66c7d3da2c10a09131294dbe7802fac792f570be639dc6ebf207bfc3e144287"
dependencies = [ dependencies = [
"arrow2", "arrow2",
"hashbrown 0.12.1", "hashbrown 0.12.1",
@ -3345,9 +3349,9 @@ dependencies = [
[[package]] [[package]]
name = "polars-core" name = "polars-core"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdf8d12cb7ec278516228fc86469f98c62ab81ca31e4e76d2c0ccf5a09c70491" checksum = "f7f15f443a90d5367c4fbbb151e203f03b5b96055c8b928c6bc30655a3644f13"
dependencies = [ dependencies = [
"ahash", "ahash",
"anyhow", "anyhow",
@ -3356,8 +3360,8 @@ dependencies = [
"comfy-table", "comfy-table",
"hashbrown 0.12.1", "hashbrown 0.12.1",
"indexmap", "indexmap",
"lazy_static",
"num 0.4.0", "num 0.4.0",
"once_cell",
"polars-arrow", "polars-arrow",
"polars-utils", "polars-utils",
"rand 0.8.5", "rand 0.8.5",
@ -3371,20 +3375,21 @@ dependencies = [
[[package]] [[package]]
name = "polars-io" name = "polars-io"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdd4b762e5694f359ded21ca0627b5bc95b6eb49f6b330569afc1d20f0564b01" checksum = "058d0a847ce5009b974c69ec878ed416e306436f21b626543019f738cee12315"
dependencies = [ dependencies = [
"ahash", "ahash",
"anyhow", "anyhow",
"arrow2", "arrow2",
"csv-core", "csv-core",
"dirs", "dirs",
"lazy_static",
"lexical", "lexical",
"lexical-core",
"memchr", "memchr",
"memmap2", "memmap2",
"num 0.4.0", "num 0.4.0",
"once_cell",
"polars-arrow", "polars-arrow",
"polars-core", "polars-core",
"polars-time", "polars-time",
@ -3398,9 +3403,9 @@ dependencies = [
[[package]] [[package]]
name = "polars-lazy" name = "polars-lazy"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eedc21001f05611e41bb7439b38d0f4ef9406aa49c17f3b289b5f57d8fa40c59" checksum = "dad86a4ce7e32540ff12089bce6f77270fd133a5b263328a92be61defdd6b151"
dependencies = [ dependencies = [
"ahash", "ahash",
"glob", "glob",
@ -3408,6 +3413,7 @@ dependencies = [
"polars-arrow", "polars-arrow",
"polars-core", "polars-core",
"polars-io", "polars-io",
"polars-ops",
"polars-time", "polars-time",
"polars-utils", "polars-utils",
"rayon", "rayon",
@ -3416,31 +3422,33 @@ dependencies = [
[[package]] [[package]]
name = "polars-ops" name = "polars-ops"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fae68f0992955f224f09d1f15648a6fb76d8e3b962efac2f97ccc2aa58977a" checksum = "030ecd473be113cd0264f1bc19de39a844fa12fa565db9dc52c859cbc292cf04"
dependencies = [ dependencies = [
"polars-arrow",
"polars-core", "polars-core",
] ]
[[package]] [[package]]
name = "polars-time" name = "polars-time"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be499f73749e820f96689c5f9ec59669b7cdd551d864358e2bdaebb5944e4bfb" checksum = "94047b20d2da3bcc55c421be187a0c6f316cf1eea7fe7ed7347c1160a32d017c"
dependencies = [ dependencies = [
"chrono", "chrono",
"lexical", "lexical",
"polars-arrow", "polars-arrow",
"polars-core", "polars-core",
"polars-utils",
"serde", "serde",
] ]
[[package]] [[package]]
name = "polars-utils" name = "polars-utils"
version = "0.21.1" version = "0.22.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f4cd569d383f5f000abbd6d5146550e6cb4e43fac30d1af98699499a440d56" checksum = "fcd3d0238462d5d9f7fbeaaea46e73ed4d58f6fae8b70d53cbe51d7538cc43f5"
dependencies = [ dependencies = [
"parking_lot 0.12.1", "parking_lot 0.12.1",
"rayon", "rayon",
@ -4224,7 +4232,6 @@ version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
dependencies = [ dependencies = [
"indexmap",
"itoa 1.0.2", "itoa 1.0.2",
"ryu", "ryu",
"serde", "serde",

View File

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

View File

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

View File

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

View File

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

View File

@ -32,7 +32,7 @@ impl Command for GetWeekDay {
result: Some( result: Some(
NuDataFrame::try_from_columns(vec![Column::new( NuDataFrame::try_from_columns(vec![Column::new(
"0".to_string(), "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") .expect("simple df for test should not fail")
.into_value(Span::test_data()), .into_value(Span::test_data()),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ use nu_protocol::{ast::Operator, span, ShellError, Span, Spanned, Value};
use num::Zero; use num::Zero;
use polars::prelude::{ use polars::prelude::{
BooleanType, ChunkCompare, ChunkedArray, DataType, Float64Type, Int64Type, IntoSeries, 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}; use std::ops::{Add, BitAnd, BitOr, Div, Mul, Sub};