diff --git a/native/explorer/Cargo.lock b/native/explorer/Cargo.lock index 69e12af52..bf4c6ae3b 100644 --- a/native/explorer/Cargo.lock +++ b/native/explorer/Cargo.lock @@ -171,6 +171,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bitflags" version = "1.3.2" @@ -197,9 +203,9 @@ dependencies = [ [[package]] name = "brotli" -version = "3.5.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d640d25bc63c50fb1f0b545ffd80207d2e10a4c965530809b40ba3386825c391" +checksum = "19483b140a7ac7174d34b5a581b406c64f84da5409d3e09cf4fff604f9270e67" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -208,9 +214,9 @@ dependencies = [ [[package]] name = "brotli-decompressor" -version = "2.5.1" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e2e4afe60d7dd600fdd3de8d0f08c2b7ec039712e3b6137ff98b7004e82de4f" +checksum = "9a45bd2e4095a8b518033b128020dd4a55aab1c0a381ba4404a472630f4bc362" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -707,6 +713,7 @@ dependencies = [ "ahash", "allocator-api2", "rayon", + "serde", ] [[package]] @@ -1194,7 +1201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8718f8b65fdf67a45108d1548347d4af7d71fb81ce727bbf9e3b2535e079db3" dependencies = [ "async-trait", - "base64", + "base64 0.21.7", "bytes", "chrono", "futures", @@ -1344,9 +1351,9 @@ dependencies = [ [[package]] name = "polars" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea21b858b16b9c0e17a12db2800d11aa5b4bd182be6b3022eb537bbfc1f2db5" +checksum = "e148396dca5496566880fa19374f3f789a29db94e3eb458afac1497b4bac5442" dependencies = [ "getrandom", "polars-arrow", @@ -1364,9 +1371,9 @@ dependencies = [ [[package]] name = "polars-arrow" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "725b09f2b5ef31279b66e27bbab63c58d49d8f6696b66b1f46c7eaab95e80f75" +checksum = "1cb5e11cd0752ae022fa6ca3afa50a14b0301b7ce53c0135828fbb0f4fa8303e" dependencies = [ "ahash", "atoi", @@ -1411,9 +1418,9 @@ dependencies = [ [[package]] name = "polars-compute" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a796945b14b14fbb79b91ef0406e6fddca2be636e889f81ea5d6ee7d36efb4fe" +checksum = "89fc4578f826234cdecb782952aa9c479dc49373f81694a7b439c70b6f609ba0" dependencies = [ "bytemuck", "either", @@ -1427,9 +1434,9 @@ dependencies = [ [[package]] name = "polars-core" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "465f70d3e96b6d0b1a43c358ba451286b8c8bd56696feff020d65702aa33e35c" +checksum = "e490c6bace1366a558feea33d1846f749a8ca90bd72a6748752bc65bb4710b2a" dependencies = [ "ahash", "bitflags 2.5.0", @@ -1459,9 +1466,9 @@ dependencies = [ [[package]] name = "polars-error" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5224d5d05e6b8a6f78b75951ae1b5f82c8ab1979e11ffaf5fd41941e3d5b0757" +checksum = "08888f58e61599b00f5ea0c2ccdc796b54b9859559cc0d4582733509451fa01a" dependencies = [ "object_store", "polars-arrow-format", @@ -1470,11 +1477,31 @@ dependencies = [ "thiserror", ] +[[package]] +name = "polars-expr" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4173591920fe56ad55af025f92eb0d08421ca85705c326a640c43856094e3484" +dependencies = [ + "ahash", + "bitflags 2.5.0", + "once_cell", + "polars-arrow", + "polars-core", + "polars-io", + "polars-ops", + "polars-plan", + "polars-time", + "polars-utils", + "rayon", + "smartstring", +] + [[package]] name = "polars-io" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2c8589e418cbe4a48228d64b2a8a40284a82ec3c98817c0c2bcc0267701338b" +checksum = "5842896aea46d975b425d63f156f412aed3cfde4c257b64fb1f43ceea288074e" dependencies = [ "ahash", "async-trait", @@ -1517,9 +1544,9 @@ dependencies = [ [[package]] name = "polars-json" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81224492a649a12b668480c0cf219d703f432509765d2717e72fe32ad16fc701" +checksum = "160cbad0145b93ac6a88639aadfa6f7d7c769d05a8674f9b7e895b398cae9901" dependencies = [ "ahash", "chrono", @@ -1538,9 +1565,9 @@ dependencies = [ [[package]] name = "polars-lazy" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2632b1af668e2058d5f8f916d8fbde3cac63d03ae29a705f598e41dcfeb7f" +checksum = "e805ea2ebbc6b7749b0afb31b7fc5d32b42b57ba29b984549d43d3a16114c4a5" dependencies = [ "ahash", "bitflags 2.5.0", @@ -1549,6 +1576,7 @@ dependencies = [ "once_cell", "polars-arrow", "polars-core", + "polars-expr", "polars-io", "polars-json", "polars-ops", @@ -1564,13 +1592,13 @@ dependencies = [ [[package]] name = "polars-ops" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efdbdb4d9a92109bc2e0ce8e17af5ae8ab643bb5b7ee9d1d74f0aeffd1fbc95f" +checksum = "7b0aed7e169c81b98457641cf82b251f52239a668916c2e683abd1f38df00d58" dependencies = [ "ahash", "argminmax", - "base64", + "base64 0.22.1", "bytemuck", "chrono", "chrono-tz 0.8.6", @@ -1599,13 +1627,13 @@ dependencies = [ [[package]] name = "polars-parquet" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b421d2196f786fdfe162db614c8485f8308fe41575d4de634a39bbe460d1eb6a" +checksum = "c70670a9e51cac66d0e77fd20b5cc957dbcf9f2660d410633862bb72f846d5b8" dependencies = [ "ahash", "async-stream", - "base64", + "base64 0.22.1", "brotli", "ethnum", "flate2", @@ -1625,9 +1653,9 @@ dependencies = [ [[package]] name = "polars-pipe" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48700f1d5bd56a15451e581f465c09541492750360f18637b196f995470a015c" +checksum = "0a40ae1b3c74ee07e2d1f7cbf56c5d6e15969e45d9b6f0903bd2acaf783ba436" dependencies = [ "crossbeam-channel", "crossbeam-queue", @@ -1638,6 +1666,7 @@ dependencies = [ "polars-arrow", "polars-compute", "polars-core", + "polars-expr", "polars-io", "polars-ops", "polars-plan", @@ -1652,13 +1681,14 @@ dependencies = [ [[package]] name = "polars-plan" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fb8e2302e20c44defd5be8cad9c96e75face63c3a5f609aced8c4ec3b3ac97d" +checksum = "8daa3541ae7e9af311a4389bc2b21f83349c34c723cc67fa524cdefdaa172d90" dependencies = [ "ahash", "bytemuck", "chrono-tz 0.8.6", + "either", "futures", "hashbrown", "once_cell", @@ -1681,9 +1711,9 @@ dependencies = [ [[package]] name = "polars-row" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a515bdc68c2ae3702e3de70d89601f3b71ca8137e282a226dddb53ee4bacfa2e" +checksum = "deb285f2f3a65b00dd06bef16bb9f712dbb5478f941dab5cf74f9f016d382e40" dependencies = [ "bytemuck", "polars-arrow", @@ -1693,11 +1723,12 @@ dependencies = [ [[package]] name = "polars-sql" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4bb7cc1c04c3023d1953b2f1dec50515e8fd8169a5a2bf4967b3b082232db7" +checksum = "a724f699d194cb02c25124d3832f7d4d77f387f1a89ee42f6b9e88ec561d4ad9" dependencies = [ "hex", + "once_cell", "polars-arrow", "polars-core", "polars-error", @@ -1711,11 +1742,12 @@ dependencies = [ [[package]] name = "polars-time" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efc18e3ad92eec55db89d88f16c22d436559ba7030cf76f86f6ed7a754b673f1" +checksum = "87ebec238d8b6200d9f0c3ce411c8441e950bd5a7df7806b8172d06c1d5a4b97" dependencies = [ "atoi", + "bytemuck", "chrono", "chrono-tz 0.8.6", "now", @@ -1731,9 +1763,9 @@ dependencies = [ [[package]] name = "polars-utils" -version = "0.39.2" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c760b6c698cfe2fbbbd93d6cfb408db14ececfe1d92445dae2229ce1b5b21ae8" +checksum = "34e1a907c63abf71e5f21467e2e4ff748896c28196746f631c6c25512ec6102c" dependencies = [ "ahash", "bytemuck", @@ -1955,7 +1987,7 @@ version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -2076,7 +2108,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", ] [[package]] @@ -2360,9 +2392,9 @@ checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ "heck 0.4.1", "proc-macro2", diff --git a/native/explorer/Cargo.toml b/native/explorer/Cargo.toml index aa64018a3..13b77b419 100644 --- a/native/explorer/Cargo.toml +++ b/native/explorer/Cargo.toml @@ -38,7 +38,7 @@ object_store = { version = "0.9", default-features = false, optional = true } mimalloc = { version = "*", default-features = false } [dependencies.polars] -version = "0.39" +version = "0.40" default-features = false features = [ "abs", @@ -86,7 +86,7 @@ features = [ ] [dependencies.polars-ops] -version = "0.39" +version = "0.40" features = ["abs", "ewma", "cum_agg", "cov"] [features] diff --git a/native/explorer/src/dataframe.rs b/native/explorer/src/dataframe.rs index a8fb819b1..10161b979 100644 --- a/native/explorer/src/dataframe.rs +++ b/native/explorer/src/dataframe.rs @@ -315,9 +315,7 @@ pub fn df_sort_with( .with_order_descendings(directions); let new_df = if groups.is_empty() { - df.lazy() - .sort_by_exprs(exprs, sort_options) - .collect()? + df.lazy().sort_by_exprs(exprs, sort_options).collect()? } else { df.group_by_stable(groups)?.apply(|df| { df.lazy() diff --git a/native/explorer/src/dataframe/io.rs b/native/explorer/src/dataframe/io.rs index 83fe7f55f..752afb6ff 100644 --- a/native/explorer/src/dataframe/io.rs +++ b/native/explorer/src/dataframe/io.rs @@ -44,24 +44,29 @@ pub fn df_from_csv( _ => CsvEncoding::Utf8, }; - let reader = CsvReader::from_path(filename)? - .infer_schema(infer_schema_length) - .has_header(has_header) - .truncate_ragged_lines(true) - .with_try_parse_dates(parse_dates) + let dataframe = CsvReadOptions::default() + .with_infer_schema_length(infer_schema_length) + .with_has_header(has_header) .with_n_rows(stop_after_n_rows) - .with_separator(delimiter_as_byte) .with_skip_rows(skip_rows) .with_skip_rows_after_header(skip_rows_after_header) - .with_projection(projection) + .with_projection(projection.map(Arc::new)) .with_rechunk(do_rechunk) - .with_encoding(encoding) - .with_columns(column_names) - .with_dtypes(Some(schema_from_dtypes_pairs(dtypes)?)) - .with_null_values(Some(NullValues::AllColumns(null_vals))) - .with_end_of_line_char(eol_delimiter.unwrap_or(b'\n')); - - Ok(ExDataFrame::new(reader.finish()?)) + .with_columns(column_names.map(Arc::new)) + .with_schema_overwrite(Some(schema_from_dtypes_pairs(dtypes)?)) + .with_parse_options( + CsvParseOptions::default() + .with_encoding(encoding) + .with_truncate_ragged_lines(true) + .with_try_parse_dates(parse_dates) + .with_separator(delimiter_as_byte) + .with_eol_char(eol_delimiter.unwrap_or(b'\n')) + .with_null_values(Some(NullValues::AllColumns(null_vals))), + ) + .try_into_reader_with_file_path(Some(filename.into()))? + .finish(); + + Ok(ExDataFrame::new(dataframe?)) } pub fn schema_from_dtypes_pairs( @@ -154,23 +159,28 @@ pub fn df_load_csv( let cursor = Cursor::new(binary.as_slice()); - let reader = CsvReader::new(cursor) - .infer_schema(infer_schema_length) - .has_header(has_header) - .with_try_parse_dates(parse_dates) + let dataframe = CsvReadOptions::default() + .with_has_header(has_header) + .with_infer_schema_length(infer_schema_length) .with_n_rows(stop_after_n_rows) - .with_separator(delimiter_as_byte) + .with_columns(column_names.map(Arc::new)) .with_skip_rows(skip_rows) .with_skip_rows_after_header(skip_rows_after_header) - .with_projection(projection) + .with_projection(projection.map(Arc::new)) .with_rechunk(do_rechunk) - .with_encoding(encoding) - .with_columns(column_names) - .with_dtypes(Some(schema_from_dtypes_pairs(dtypes)?)) - .with_null_values(Some(NullValues::AllColumns(null_vals))) - .with_end_of_line_char(eol_delimiter.unwrap_or(b'\n')); - - Ok(ExDataFrame::new(reader.finish()?)) + .with_schema(Some(schema_from_dtypes_pairs(dtypes)?)) + .with_parse_options( + CsvParseOptions::default() + .with_separator(delimiter_as_byte) + .with_encoding(encoding) + .with_null_values(Some(NullValues::AllColumns(null_vals))) + .with_try_parse_dates(parse_dates) + .with_eol_char(eol_delimiter.unwrap_or(b'\n')), + ) + .into_reader_with_file_handle(cursor) + .finish(); + + Ok(ExDataFrame::new(dataframe?)) } // ============ Parquet ============ // diff --git a/native/explorer/src/expressions.rs b/native/explorer/src/expressions.rs index 4949ddd39..a9d35130e 100644 --- a/native/explorer/src/expressions.rs +++ b/native/explorer/src/expressions.rs @@ -4,16 +4,11 @@ // or an expression and returns an expression that is // wrapped in an Elixir struct. -use polars::error::PolarsError; - -use polars::prelude::{GetOutput, IntoSeries, Utf8JsonPathImpl}; -use polars::series::Series; - use crate::datatypes::{ ExCorrelationMethod, ExDate, ExDuration, ExNaiveDateTime, ExRankMethod, ExSeriesDtype, ExValidValue, }; -use crate::series::{cast_str_to_f64, ewm_opts, rolling_opts}; +use crate::series::{cast_str_to_f64, ewm_opts, rolling_opts_fixed_window}; use crate::{ExDataFrame, ExExpr, ExSeries}; use polars::lazy::dsl; use polars::prelude::{ @@ -654,7 +649,7 @@ macro_rules! init_window_expr_fun { center: bool, ) -> ExExpr { let expr = data.clone_inner(); - let opts = rolling_opts(window_size, weights, min_periods, center); + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); ExExpr::new(expr.$fun(opts)) } }; @@ -675,7 +670,7 @@ pub fn expr_window_standard_deviation( center: bool, ) -> ExExpr { let expr = data.clone_inner(); - let opts = rolling_opts(window_size, weights, min_periods, center); + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); ExExpr::new(expr.rolling_std(opts).cast(DataType::Float64)) } @@ -827,7 +822,10 @@ pub fn expr_unary_not(expr: ExExpr) -> ExExpr { pub fn expr_describe_filter_plan(data: ExDataFrame, expr: ExExpr) -> String { let df = data.clone(); let expressions = expr.clone_inner(); - df.lazy().filter(expressions).describe_plan() + df.lazy() + .filter(expressions) + .describe_plan() + .expect("error") } #[rustler::nif] @@ -1115,18 +1113,8 @@ pub fn expr_json_decode(expr: ExExpr, ex_dtype: ExSeriesDtype) -> ExExpr { } #[rustler::nif] -pub fn expr_json_path_match(expr: ExExpr, json_path: &str) -> ExExpr { - let p = json_path.to_owned(); - let function = move |s: Series| { - let ca = s.str()?; - match ca.json_path_match(&p) { - Ok(ca) => Ok(Some(ca.into_series())), - Err(e) => Err(PolarsError::ComputeError(format!("{e:?}").into())), - } - }; - let expr = expr - .clone_inner() - .map(function, GetOutput::from_type(DataType::String)); +pub fn expr_json_path_match(expr: ExExpr, json_path: String) -> ExExpr { + let expr = expr.clone_inner().str().json_path_match(json_path.lit()); ExExpr::new(expr) } diff --git a/native/explorer/src/lazyframe.rs b/native/explorer/src/lazyframe.rs index 11ec919a3..aa894c013 100644 --- a/native/explorer/src/lazyframe.rs +++ b/native/explorer/src/lazyframe.rs @@ -24,7 +24,7 @@ pub fn lf_describe_plan(data: ExLazyFrame, optimized: bool) -> Result lf.describe_optimized_plan()?, - false => lf.describe_plan(), + false => lf.describe_plan().expect("error"), }; Ok(plan) } @@ -151,9 +151,7 @@ pub fn lf_sort_with( .with_maintain_order(maintain_order) .with_order_descendings(directions); - let ldf = data - .clone_inner() - .sort_by_exprs(exprs, sort_options); + let ldf = data.clone_inner().sort_by_exprs(exprs, sort_options); Ok(ExLazyFrame::new(ldf)) } @@ -290,7 +288,7 @@ pub fn lf_join( let how = match how { "left" => JoinType::Left, "inner" => JoinType::Inner, - "outer" => JoinType::Outer { coalesce: false }, + "outer" => JoinType::Outer, "cross" => JoinType::Cross, _ => { return Err(ExplorerError::Other(format!( diff --git a/native/explorer/src/lazyframe/io.rs b/native/explorer/src/lazyframe/io.rs index a075df5d3..6406834c4 100644 --- a/native/explorer/src/lazyframe/io.rs +++ b/native/explorer/src/lazyframe/io.rs @@ -209,7 +209,7 @@ pub fn lf_from_csv( let df = LazyCsvReader::new(filename) .with_infer_schema_length(infer_schema_length) - .has_header(has_header) + .with_has_header(has_header) .with_try_parse_dates(parse_dates) .with_n_rows(stop_after_n_rows) .with_separator(delimiter_as_byte) @@ -217,9 +217,9 @@ pub fn lf_from_csv( .with_skip_rows_after_header(skip_rows_after_header) .with_rechunk(do_rechunk) .with_encoding(encoding) - .with_dtype_overwrite(Some(schema_from_dtypes_pairs(dtypes)?.as_ref())) + .with_dtype_overwrite(Some(schema_from_dtypes_pairs(dtypes)?)) .with_null_values(Some(NullValues::AllColumns(null_vals))) - .with_end_of_line_char(eol_delimiter.unwrap_or(b'\n')) + .with_eol_char(eol_delimiter.unwrap_or(b'\n')) .finish()?; Ok(ExLazyFrame::new(df)) diff --git a/native/explorer/src/series.rs b/native/explorer/src/series.rs index d325e117c..fbcec42ff 100644 --- a/native/explorer/src/series.rs +++ b/native/explorer/src/series.rs @@ -10,7 +10,7 @@ use crate::{ use encoding::encode_naive_datetime; // use encoding::encode_datetime; -use polars::prelude::*; +use polars::prelude::*; //{lazy::dsl::Expr, }; use polars_ops::chunked_array::cov::{cov, pearson_corr}; use polars_ops::prelude::peaks::*; use rustler::{Binary, Encoder, Env, Error, ListIterator, NifResult, Term, TermType}; @@ -796,8 +796,8 @@ pub fn s_window_sum( min_periods: Option, center: bool, ) -> Result { - let opts = rolling_opts(window_size, weights, min_periods, center); - let s1 = series.rolling_sum(opts.try_into()?)?; + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); + let s1 = series.rolling_sum(opts)?; Ok(ExSeries::new(s1)) } @@ -809,8 +809,8 @@ pub fn s_window_mean( min_periods: Option, center: bool, ) -> Result { - let opts = rolling_opts(window_size, weights, min_periods, center); - let s1 = series.rolling_mean(opts.try_into()?)?; + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); + let s1 = series.rolling_mean(opts)?; Ok(ExSeries::new(s1)) } @@ -822,7 +822,7 @@ pub fn s_window_median( min_periods: Option, center: bool, ) -> Result { - let opts = rolling_opts(window_size, weights, min_periods, center); + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); let s1 = series .clone_inner() .into_frame() @@ -842,8 +842,8 @@ pub fn s_window_max( min_periods: Option, center: bool, ) -> Result { - let opts = rolling_opts(window_size, weights, min_periods, center); - let s1 = series.rolling_max(opts.try_into()?)?; + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); + let s1 = series.rolling_max(opts)?; Ok(ExSeries::new(s1)) } @@ -855,8 +855,8 @@ pub fn s_window_min( min_periods: Option, center: bool, ) -> Result { - let opts = rolling_opts(window_size, weights, min_periods, center); - let s1 = series.rolling_min(opts.try_into()?)?; + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); + let s1 = series.rolling_min(opts)?; Ok(ExSeries::new(s1)) } @@ -868,27 +868,27 @@ pub fn s_window_standard_deviation( min_periods: Option, center: bool, ) -> Result { - let opts = rolling_opts(window_size, weights, min_periods, center); - let s1 = series.rolling_std(opts.try_into()?)?; + let opts = rolling_opts_fixed_window(window_size, weights, min_periods, center); + let s1 = series.rolling_std(opts)?; Ok(ExSeries::new(s1)) } // Used for rolling functions - also see "expressions" module -pub fn rolling_opts( +pub fn rolling_opts_fixed_window( window_size: usize, weights: Option>, min_periods: Option, center: bool, -) -> RollingOptions { - let min_periods = if let Some(mp) = min_periods { +) -> RollingOptionsFixedWindow { + let min_periods: usize = if let Some(mp) = min_periods { mp } else { window_size }; - let window_size_duration = Duration::new(window_size as i64); + // let window_size_duration = Duration::new(window_size as i64); - RollingOptions { - window_size: window_size_duration, + RollingOptionsFixedWindow { + window_size, weights, min_periods, center, @@ -1075,7 +1075,16 @@ pub fn s_mode(s: ExSeries) -> Result { #[rustler::nif(schedule = "DirtyCpu")] pub fn s_product(s: ExSeries) -> Result { if s.dtype().is_numeric() { - Ok(ExSeries::new(s.product()?)) + let series = s + .clone_inner() + .into_frame() + .lazy() + .select([col(s.name()).product()]) + .collect()? + .column(s.name())? + .clone(); + + Ok(ExSeries::new(series)) } else { panic!("product/1 not implemented for {:?}", &s.dtype()) } @@ -1235,12 +1244,16 @@ pub fn s_quantile<'a>( .unwrap() .encode(env)), }, - _ => encoding::term_from_value( - s.quantile_as_series(quantile, strategy)? - .cast(dtype)? - .get(0)?, - env, - ), + _ => todo!(), + // _ => + // s.agg_quantile(quantile, strategy) + + // encoding::term_from_value( + // s.quantile_as_series(quantile, strategy)? + // .cast(dtype)? + // .get(0)?, + // env, + // ), } } @@ -1849,26 +1862,17 @@ pub fn s_json_decode(s: ExSeries, ex_dtype: ExSeriesDtype) -> Result Result { - let p = json_path.to_owned(); - let function = move |s: Series| { - let ca = s.str()?; - match ca.json_path_match(&p) { - Ok(ca) => Ok(Some(ca.into_series())), - Err(e) => Err(PolarsError::ComputeError(format!("{e:?}").into())), - } - }; - let s2 = s +pub fn s_json_path_match(s: ExSeries, json_path: String) -> Result { + let var_series = s .clone_inner() .into_frame() .lazy() - .select([col(s.name()) - .map(function, GetOutput::from_type(DataType::String)) - .alias(s.name())]) + .select([col(s.name()).str().json_path_match(json_path.lit())]) .collect()? .column(s.name())? .clone(); - Ok(ExSeries::new(s2)) + + Ok(ExSeries::new(var_series)) } #[rustler::nif]