From 9ed0b3e896c5b84fcb3f78f569a031813e2b9bea Mon Sep 17 00:00:00 2001 From: Darek Date: Wed, 8 Nov 2023 10:50:52 -0500 Subject: [PATCH] Using rs-0.34 and git hashes (#141) * RS changes for 0.34.2 * Fixing tests * Fixing tests * Fixing tests * Upgrading biome * Update Cargo.toml as suggested Co-authored-by: universalmind303 * Removing unused elements * Using rs-0.34 and git hashes --------- Co-authored-by: universalmind303 --- Cargo.toml | 22 ++- __tests__/dataframe.test.ts | 2 +- __tests__/expr.test.ts | 4 +- __tests__/functions.test.ts | 4 +- __tests__/groupby.test.ts | 18 +- __tests__/lazyframe.test.ts | 4 +- __tests__/series.test.ts | 334 ++++++++++++++++++------------------ package.json | 10 +- polars/dataframe.ts | 53 ++++-- polars/groupby.ts | 8 +- polars/io.ts | 1 + polars/lazy/dataframe.ts | 26 +-- polars/lazy/expr/index.ts | 46 +++-- polars/lazy/expr/list.ts | 4 +- polars/lazy/expr/string.ts | 5 +- polars/series/index.ts | 14 +- polars/shared_traits.ts | 1 - rust-toolchain | 2 +- src/dataframe.rs | 24 +-- src/functions.rs | 4 +- src/lazy/dataframe.rs | 32 ++-- src/lazy/dsl.rs | 97 ++++++----- src/lib.rs | 4 +- src/list_construction.rs | 1 + src/prelude.rs | 1 + src/series.rs | 58 +++---- yarn.lock | 100 +++++------ 27 files changed, 444 insertions(+), 435 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce080875..cbe6033a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,10 @@ ahash = "0.8.3" bincode = "1.3.3" napi = {version = "2.13.3", default-features = false, features = ["napi8", "serde-json", "experimental"]} napi-derive = {version = "2.13.0", default-features = false} -polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "ec0c91f93fcd1ac355c667d6c3c3f30b257ea0a6", default-features = false} -polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "ec0c91f93fcd1ac355c667d6c3c3f30b257ea0a6", default-features = false} -polars-lazy = {git = "https://github.com/pola-rs/polars.git", rev = "ec0c91f93fcd1ac355c667d6c3c3f30b257ea0a6", default-features = false} -polars-ops = {git = "https://github.com/pola-rs/polars.git", rev = "ec0c91f93fcd1ac355c667d6c3c3f30b257ea0a6", default-features = false} -thiserror = "1.0.47" +polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "60adaef43e1b3306d5da8cf736accea2e3f03d9b", default-features = false} +polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "60adaef43e1b3306d5da8cf736accea2e3f03d9b", default-features = false} +polars-lazy = {git = "https://github.com/pola-rs/polars.git", rev = "60adaef43e1b3306d5da8cf736accea2e3f03d9b", default-features = false} +thiserror = "1" smartstring = { version = "1" } serde_json = {version = "1"} either = "1.9" @@ -31,7 +30,7 @@ features = [ "binary_encoding", "rolling_window", "json", - "dynamic_groupby", + "dynamic_group_by", "zip_with", "simd", "lazy", @@ -46,7 +45,7 @@ features = [ "round_series", "is_unique", "is_in", - "is_first", + "is_first_distinct", "asof_join", "cross_join", "dot_product", @@ -69,7 +68,6 @@ features = [ "moment", "true_div", "dtype-categorical", - "string_justify", "diagonal_concat", "horizontal_concat", "abs", @@ -92,9 +90,11 @@ features = [ "list_eval", "arg_where", "timezones", + "peaks", + "string_justify", ] git = "https://github.com/pola-rs/polars.git" -rev = "ec0c91f93fcd1ac355c667d6c3c3f30b257ea0a6" +rev = "60adaef43e1b3306d5da8cf736accea2e3f03d9b" [build-dependencies] napi-build = "2.0.1" @@ -105,6 +105,4 @@ lto = "fat" [features] default = ["range"] -range = ["polars-lazy/range"] - -[workspace] +range = ["polars-lazy/range"] \ No newline at end of file diff --git a/__tests__/dataframe.test.ts b/__tests__/dataframe.test.ts index 63c5e09f..fe02dd70 100644 --- a/__tests__/dataframe.test.ts +++ b/__tests__/dataframe.test.ts @@ -916,7 +916,7 @@ describe("dataframe", () => { foo: [1, 2, 3, 1], bar: [6, 7, 8, 1], }) - .shiftAndFill({ periods: -1, fillValue: 99 }); + .shiftAndFill({ n: -1, fillValue: 99 }); const expected = pl.DataFrame({ foo: [2, 3, 1, 99], bar: [7, 8, 1, 99], diff --git a/__tests__/expr.test.ts b/__tests__/expr.test.ts index 4ab7e07a..23a827f7 100644 --- a/__tests__/expr.test.ts +++ b/__tests__/expr.test.ts @@ -365,10 +365,10 @@ describe("expr", () => { const actual = df.select(col("a").isFinite()); expect(actual).toFrameEqual(expected); }); - test("isFirst", () => { + test("isFirstDistinct", () => { const df = pl.DataFrame({ a: [0, 1, 2, 2] }); const expected = pl.DataFrame({ a: [true, true, true, false] }); - const actual = df.select(col("a").isFirst()); + const actual = df.select(col("a").isFirstDistinct()); expect(actual).toFrameEqual(expected); }); test("isIn:list", () => { diff --git a/__tests__/functions.test.ts b/__tests__/functions.test.ts index 4272f77b..6548389c 100644 --- a/__tests__/functions.test.ts +++ b/__tests__/functions.test.ts @@ -134,8 +134,8 @@ describe("horizontal", () => { const df = pl.DataFrame({ a: [1, 2, 3], b: [1.0, 2.0, 3.0] }); const out = df.select( pl.sumHorizontal([pl.col("a"), pl.col("b")]), - pl.maxHorizontal([pl.col("a"), pl.col("b").pow(2)]), - pl.minHorizontal([pl.col("a"), pl.col("b").pow(2)]), + pl.maxHorizontal([pl.col("a"), pl.col("b").pow(2)]).alias("max"), + pl.minHorizontal([pl.col("a"), pl.col("b").pow(2)]).alias("min"), ); expect(out["sum"]).toSeriesEqual(pl.Series("sum", [2.0, 4.0, 6.0])); expect(out["max"]).toSeriesEqual(pl.Series("max", [1.0, 4.0, 9.0])); diff --git a/__tests__/groupby.test.ts b/__tests__/groupby.test.ts index cb418042..a05727a5 100644 --- a/__tests__/groupby.test.ts +++ b/__tests__/groupby.test.ts @@ -194,9 +194,9 @@ describe("groupby ops", () => { }) .agg(pl.col("adm1_code").unique(), pl.col("fatalities").gt(0).sum()); const expected = [ - new Date("2021-04-05"), - new Date("2021-05-05"), - new Date("2021-04-26"), + new Date("2021-04-11"), + new Date("2021-05-29"), + new Date("2021-04-29"), ]; const actual = out.getColumn("event_date"); expect(actual.toArray()).toEqual(expected); @@ -223,9 +223,9 @@ describe("groupby ops", () => { }) .agg(pl.col("adm1_code").unique(), pl.col("fatalities").gt(0).sum()); const expected = [ - new Date("2021-04-05"), - new Date("2021-05-05"), - new Date("2021-04-26"), + new Date("2021-04-11"), + new Date("2021-05-29"), + new Date("2021-04-29"), ]; const actual = out.getColumn("event_date").toArray(); expect(actual).toEqual(expected); @@ -254,9 +254,9 @@ describe("groupby ops", () => { .agg(pl.col("idx")); const expected = pl.DataFrame({ dt: [ - new Date("2022-12-26"), - new Date("2023-01-26"), - new Date("2023-02-26"), + new Date("2023-01-01"), + new Date("2023-02-01"), + new Date("2023-03-01"), ], idx: [[0, 1], [2], [3]], }); diff --git a/__tests__/lazyframe.test.ts b/__tests__/lazyframe.test.ts index c3a7c43a..a68493ac 100644 --- a/__tests__/lazyframe.test.ts +++ b/__tests__/lazyframe.test.ts @@ -883,7 +883,7 @@ describe("lazyframe", () => { bar: [6, 7, 8, 1], }) .lazy() - .shiftAndFill({ periods: -1, fillValue: 99 }) + .shiftAndFill({ n: -1, fillValue: 99 }) .collectSync(); const expected = pl.DataFrame({ foo: [2, 3, 1, 99], @@ -898,7 +898,7 @@ describe("lazyframe", () => { bar: [6, 7, 8, 1], }) .lazy() - .shiftAndFill({ periods: -1, fillValue: pl.lit(99) }) + .shiftAndFill({ n: -1, fillValue: 99 }) .collectSync(); const expected = pl.DataFrame({ foo: [2, 3, 1, 99], diff --git a/__tests__/series.test.ts b/__tests__/series.test.ts index b1dd23e1..987a2bae 100644 --- a/__tests__/series.test.ts +++ b/__tests__/series.test.ts @@ -248,173 +248,173 @@ describe("series", () => { } }); it.each` - series | method | args - ${numSeries()} | ${"abs"} | ${[]} - ${numSeries()} | ${"as"} | ${[chance.string()]} - ${numSeries()} | ${"alias"} | ${[chance.string()]} - ${numSeries()} | ${"append"} | ${[other()]} - ${numSeries()} | ${"argMax"} | ${[]} - ${numSeries()} | ${"argMin"} | ${[]} - ${numSeries()} | ${"argSort"} | ${[]} - ${boolSeries()} | ${"argTrue"} | ${[]} - ${numSeries()} | ${"argUnique"} | ${[]} - ${numSeries()} | ${"cast"} | ${[pl.UInt32]} - ${numSeries()} | ${"chunkLengths"} | ${[]} - ${numSeries()} | ${"clone"} | ${[]} - ${numSeries()} | ${"cumMax"} | ${[]} - ${numSeries()} | ${"cumMin"} | ${[]} - ${numSeries()} | ${"cumProd"} | ${[]} - ${numSeries()} | ${"cumSum"} | ${[]} - ${numSeries()} | ${"describe"} | ${[]} - ${numSeries()} | ${"diff"} | ${[]} - ${numSeries()} | ${"diff"} | ${[{ n: 1, nullBehavior: "drop" }]} - ${numSeries()} | ${"diff"} | ${[{ nullBehavior: "drop" }]} - ${numSeries()} | ${"diff"} | ${[1, "drop"]} - ${numSeries()} | ${"dot"} | ${[other()]} - ${numSeries()} | ${"dropNulls"} | ${[]} - ${numSeries()} | ${"fillNull"} | ${["zero"]} - ${numSeries()} | ${"fillNull"} | ${[{ strategy: "zero" }]} - ${numSeries()} | ${"filter"} | ${[boolSeries()]} - ${fltSeries()} | ${"floor"} | ${[]} - ${numSeries()} | ${"hasValidity"} | ${[]} - ${numSeries()} | ${"hash"} | ${[]} - ${numSeries()} | ${"hash"} | ${[{ k0: 10 }]} - ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29 }]} - ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29, k2: 3 }]} - ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29, k3: 1, k2: 3 }]} - ${numSeries()} | ${"hash"} | ${[1]} - ${numSeries()} | ${"hash"} | ${[1, 2]} - ${numSeries()} | ${"hash"} | ${[1, 2, 3]} - ${numSeries()} | ${"hash"} | ${[1, 2, 3, 4]} - ${numSeries()} | ${"head"} | ${[]} - ${numSeries()} | ${"head"} | ${[1]} - ${numSeries()} | ${"inner"} | ${[]} - ${numSeries()} | ${"interpolate"} | ${[]} - ${numSeries()} | ${"isBoolean"} | ${[]} - ${numSeries()} | ${"isDateTime"} | ${[]} - ${numSeries()} | ${"isDuplicated"} | ${[]} - ${fltSeries()} | ${"isFinite"} | ${[]} - ${numSeries()} | ${"isFirst"} | ${[]} - ${numSeries()} | ${"isFloat"} | ${[]} - ${numSeries()} | ${"isIn"} | ${[other()]} - ${numSeries()} | ${"isIn"} | ${[[1, 2, 3]]} - ${fltSeries()} | ${"isInfinite"} | ${[]} - ${numSeries()} | ${"isNotNull"} | ${[]} - ${numSeries()} | ${"isNull"} | ${[]} - ${numSeries()} | ${"isNaN"} | ${[]} - ${numSeries()} | ${"isNotNaN"} | ${[]} - ${numSeries()} | ${"isNumeric"} | ${[]} - ${numSeries()} | ${"isUnique"} | ${[]} - ${numSeries()} | ${"isUtf8"} | ${[]} - ${numSeries()} | ${"kurtosis"} | ${[]} - ${numSeries()} | ${"kurtosis"} | ${[{ fisher: true, bias: true }]} - ${numSeries()} | ${"kurtosis"} | ${[{ bias: false }]} - ${numSeries()} | ${"kurtosis"} | ${[{ fisher: false }]} - ${numSeries()} | ${"kurtosis"} | ${[false, false]} - ${numSeries()} | ${"kurtosis"} | ${[false]} - ${numSeries()} | ${"len"} | ${[]} - ${numSeries()} | ${"limit"} | ${[]} - ${numSeries()} | ${"limit"} | ${[2]} - ${numSeries()} | ${"max"} | ${[]} - ${numSeries()} | ${"mean"} | ${[]} - ${numSeries()} | ${"median"} | ${[]} - ${numSeries()} | ${"min"} | ${[]} - ${numSeries()} | ${"mode"} | ${[]} - ${numSeries()} | ${"nChunks"} | ${[]} - ${numSeries()} | ${"nUnique"} | ${[]} - ${numSeries()} | ${"nullCount"} | ${[]} - ${numSeries()} | ${"peakMax"} | ${[]} - ${numSeries()} | ${"peakMin"} | ${[]} - ${numSeries()} | ${"quantile"} | ${[0.4]} - ${numSeries()} | ${"rank"} | ${[]} - ${numSeries()} | ${"rank"} | ${["average"]} - ${numSeries()} | ${"rechunk"} | ${[]} - ${numSeries()} | ${"rechunk"} | ${[true]} - ${numSeries()} | ${"rename"} | ${["new name"]} - ${numSeries()} | ${"rename"} | ${["new name", true]} - ${numSeries()} | ${"rename"} | ${[{ name: "new name" }]} - ${numSeries()} | ${"rename"} | ${[{ name: "new name", inPlace: true }]} - ${numSeries()} | ${"rename"} | ${[{ name: "new name" }]} - ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1 }]} - ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.33] }]} - ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} - ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} - ${numSeries()} | ${"rollingMax"} | ${[1]} - ${numSeries()} | ${"rollingMax"} | ${[1, [0.11]]} - ${numSeries()} | ${"rollingMax"} | ${[1, [0.11], 1]} - ${numSeries()} | ${"rollingMax"} | ${[1, [0.23], 1, true]} - ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1 }]} - ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.33] }]} - ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} - ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} - ${numSeries()} | ${"rollingMean"} | ${[1]} - ${numSeries()} | ${"rollingMean"} | ${[1, [0.11]]} - ${numSeries()} | ${"rollingMean"} | ${[1, [0.11], 1]} - ${numSeries()} | ${"rollingMean"} | ${[1, [0.23], 1, true]} - ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1 }]} - ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.33] }]} - ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} - ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} - ${numSeries()} | ${"rollingMin"} | ${[1]} - ${numSeries()} | ${"rollingMin"} | ${[1, [0.11]]} - ${numSeries()} | ${"rollingMin"} | ${[1, [0.11], 1]} - ${numSeries()} | ${"rollingMin"} | ${[1, [0.23], 1, true]} - ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1 }]} - ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.33] }]} - ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} - ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} - ${numSeries()} | ${"rollingSum"} | ${[1]} - ${numSeries()} | ${"rollingSum"} | ${[1, [0.11]]} - ${numSeries()} | ${"rollingSum"} | ${[1, [0.11], 1]} - ${numSeries()} | ${"rollingSum"} | ${[1, [0.23], 1, true]} - ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1 }]} - ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.33] }]} - ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} - ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} - ${numSeries()} | ${"rollingVar"} | ${[1]} - ${numSeries()} | ${"rollingVar"} | ${[1, [0.11]]} - ${numSeries()} | ${"rollingVar"} | ${[1, [0.11], 1]} - ${numSeries()} | ${"rollingVar"} | ${[1, [0.23], 1, true]} - ${fltSeries()} | ${"round"} | ${[1]} - ${numSeries()} | ${"sample"} | ${[]} - ${numSeries()} | ${"sample"} | ${[1, null, true]} - ${numSeries()} | ${"sample"} | ${[null, 1]} - ${numSeries()} | ${"sample"} | ${[{ n: 1 }]} - ${numSeries()} | ${"sample"} | ${[{ frac: 0.5 }]} - ${numSeries()} | ${"sample"} | ${[{ n: 1, withReplacement: true }]} - ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true }]} - ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true, seed: 1n }]} - ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true, seed: 1 }]} - ${numSeries()} | ${"sample"} | ${[{ n: 1, withReplacement: true, seed: 1 }]} - ${numSeries()} | ${"seriesEqual"} | ${[other()]} - ${numSeries()} | ${"seriesEqual"} | ${[other(), true]} - ${numSeries()} | ${"seriesEqual"} | ${[other(), false]} - ${numSeries()} | ${"set"} | ${[boolSeries(), 2]} - ${fltSeries()} | ${"setAtIdx"} | ${[[0, 1], 1]} - ${numSeries()} | ${"shift"} | ${[]} - ${numSeries()} | ${"shift"} | ${[1]} - ${numSeries()} | ${"shiftAndFill"} | ${[1, 2]} - ${numSeries()} | ${"shiftAndFill"} | ${[{ periods: 1, fillValue: 2 }]} - ${numSeries()} | ${"skew"} | ${[]} - ${numSeries()} | ${"skew"} | ${[true]} - ${numSeries()} | ${"skew"} | ${[false]} - ${numSeries()} | ${"skew"} | ${[{ bias: true }]} - ${numSeries()} | ${"skew"} | ${[{ bias: false }]} - ${numSeries()} | ${"slice"} | ${[1, 2]} - ${numSeries()} | ${"slice"} | ${[{ offset: 1, length: 2 }]} - ${numSeries()} | ${"sort"} | ${[]} - ${numSeries()} | ${"sort"} | ${[false]} - ${numSeries()} | ${"sort"} | ${[true]} - ${numSeries()} | ${"sort"} | ${[{ reverse: true }]} - ${numSeries()} | ${"sort"} | ${[{ reverse: false }]} - ${numSeries()} | ${"sum"} | ${[]} - ${numSeries()} | ${"tail"} | ${[]} - ${numSeries()} | ${"take"} | ${[[1, 2]]} - ${numSeries()} | ${"takeEvery"} | ${[1]} - ${numSeries()} | ${"toArray"} | ${[]} - ${numSeries()} | ${"unique"} | ${[]} - ${numSeries()} | ${"valueCounts"} | ${[]} - ${numSeries()} | ${"zipWith"} | ${[boolSeries(), other()]} + series | method | args + ${numSeries()} | ${"abs"} | ${[]} + ${numSeries()} | ${"as"} | ${[chance.string()]} + ${numSeries()} | ${"alias"} | ${[chance.string()]} + ${numSeries()} | ${"append"} | ${[other()]} + ${numSeries()} | ${"argMax"} | ${[]} + ${numSeries()} | ${"argMin"} | ${[]} + ${numSeries()} | ${"argSort"} | ${[]} + ${boolSeries()} | ${"argTrue"} | ${[]} + ${numSeries()} | ${"argUnique"} | ${[]} + ${numSeries()} | ${"cast"} | ${[pl.UInt32]} + ${numSeries()} | ${"chunkLengths"} | ${[]} + ${numSeries()} | ${"clone"} | ${[]} + ${numSeries()} | ${"cumMax"} | ${[]} + ${numSeries()} | ${"cumMin"} | ${[]} + ${numSeries()} | ${"cumProd"} | ${[]} + ${numSeries()} | ${"cumSum"} | ${[]} + ${numSeries()} | ${"describe"} | ${[]} + ${numSeries()} | ${"diff"} | ${[]} + ${numSeries()} | ${"diff"} | ${[{ n: 1, nullBehavior: "drop" }]} + ${numSeries()} | ${"diff"} | ${[{ nullBehavior: "drop" }]} + ${numSeries()} | ${"diff"} | ${[1, "drop"]} + ${numSeries()} | ${"dot"} | ${[other()]} + ${numSeries()} | ${"dropNulls"} | ${[]} + ${numSeries()} | ${"fillNull"} | ${["zero"]} + ${numSeries()} | ${"fillNull"} | ${[{ strategy: "zero" }]} + ${numSeries()} | ${"filter"} | ${[boolSeries()]} + ${fltSeries()} | ${"floor"} | ${[]} + ${numSeries()} | ${"hasValidity"} | ${[]} + ${numSeries()} | ${"hash"} | ${[]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10 }]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29 }]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29, k2: 3 }]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29, k3: 1, k2: 3 }]} + ${numSeries()} | ${"hash"} | ${[1]} + ${numSeries()} | ${"hash"} | ${[1, 2]} + ${numSeries()} | ${"hash"} | ${[1, 2, 3]} + ${numSeries()} | ${"hash"} | ${[1, 2, 3, 4]} + ${numSeries()} | ${"head"} | ${[]} + ${numSeries()} | ${"head"} | ${[1]} + ${numSeries()} | ${"inner"} | ${[]} + ${numSeries()} | ${"interpolate"} | ${[]} + ${numSeries()} | ${"isBoolean"} | ${[]} + ${numSeries()} | ${"isDateTime"} | ${[]} + ${numSeries()} | ${"isDuplicated"} | ${[]} + ${fltSeries()} | ${"isFinite"} | ${[]} + ${numSeries()} | ${"isFirstDistinct"} | ${[]} + ${numSeries()} | ${"isFloat"} | ${[]} + ${numSeries()} | ${"isIn"} | ${[other()]} + ${numSeries()} | ${"isIn"} | ${[[1, 2, 3]]} + ${fltSeries()} | ${"isInfinite"} | ${[]} + ${numSeries()} | ${"isNotNull"} | ${[]} + ${numSeries()} | ${"isNull"} | ${[]} + ${numSeries()} | ${"isNaN"} | ${[]} + ${numSeries()} | ${"isNotNaN"} | ${[]} + ${numSeries()} | ${"isNumeric"} | ${[]} + ${numSeries()} | ${"isUnique"} | ${[]} + ${numSeries()} | ${"isUtf8"} | ${[]} + ${numSeries()} | ${"kurtosis"} | ${[]} + ${numSeries()} | ${"kurtosis"} | ${[{ fisher: true, bias: true }]} + ${numSeries()} | ${"kurtosis"} | ${[{ bias: false }]} + ${numSeries()} | ${"kurtosis"} | ${[{ fisher: false }]} + ${numSeries()} | ${"kurtosis"} | ${[false, false]} + ${numSeries()} | ${"kurtosis"} | ${[false]} + ${numSeries()} | ${"len"} | ${[]} + ${numSeries()} | ${"limit"} | ${[]} + ${numSeries()} | ${"limit"} | ${[2]} + ${numSeries()} | ${"max"} | ${[]} + ${numSeries()} | ${"mean"} | ${[]} + ${numSeries()} | ${"median"} | ${[]} + ${numSeries()} | ${"min"} | ${[]} + ${numSeries()} | ${"mode"} | ${[]} + ${numSeries()} | ${"nChunks"} | ${[]} + ${numSeries()} | ${"nUnique"} | ${[]} + ${numSeries()} | ${"nullCount"} | ${[]} + ${numSeries()} | ${"peakMax"} | ${[]} + ${numSeries()} | ${"peakMin"} | ${[]} + ${numSeries()} | ${"quantile"} | ${[0.4]} + ${numSeries()} | ${"rank"} | ${[]} + ${numSeries()} | ${"rank"} | ${["average"]} + ${numSeries()} | ${"rechunk"} | ${[]} + ${numSeries()} | ${"rechunk"} | ${[true]} + ${numSeries()} | ${"rename"} | ${["new name"]} + ${numSeries()} | ${"rename"} | ${["new name", true]} + ${numSeries()} | ${"rename"} | ${[{ name: "new name" }]} + ${numSeries()} | ${"rename"} | ${[{ name: "new name", inPlace: true }]} + ${numSeries()} | ${"rename"} | ${[{ name: "new name" }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingMax"} | ${[1]} + ${numSeries()} | ${"rollingMax"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingMax"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingMax"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingMean"} | ${[1]} + ${numSeries()} | ${"rollingMean"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingMean"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingMean"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingMin"} | ${[1]} + ${numSeries()} | ${"rollingMin"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingMin"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingMin"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingSum"} | ${[1]} + ${numSeries()} | ${"rollingSum"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingSum"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingSum"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingVar"} | ${[1]} + ${numSeries()} | ${"rollingVar"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingVar"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingVar"} | ${[1, [0.23], 1, true]} + ${fltSeries()} | ${"round"} | ${[1]} + ${numSeries()} | ${"sample"} | ${[]} + ${numSeries()} | ${"sample"} | ${[1, null, true]} + ${numSeries()} | ${"sample"} | ${[null, 1]} + ${numSeries()} | ${"sample"} | ${[{ n: 1 }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.5 }]} + ${numSeries()} | ${"sample"} | ${[{ n: 1, withReplacement: true }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true, seed: 1n }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true, seed: 1 }]} + ${numSeries()} | ${"sample"} | ${[{ n: 1, withReplacement: true, seed: 1 }]} + ${numSeries()} | ${"seriesEqual"} | ${[other()]} + ${numSeries()} | ${"seriesEqual"} | ${[other(), true]} + ${numSeries()} | ${"seriesEqual"} | ${[other(), false]} + ${numSeries()} | ${"set"} | ${[boolSeries(), 2]} + ${fltSeries()} | ${"setAtIdx"} | ${[[0, 1], 1]} + ${numSeries()} | ${"shift"} | ${[]} + ${numSeries()} | ${"shift"} | ${[1]} + ${numSeries()} | ${"shiftAndFill"} | ${[1, 2]} + ${numSeries()} | ${"shiftAndFill"} | ${[{ periods: 1, fillValue: 2 }]} + ${numSeries()} | ${"skew"} | ${[]} + ${numSeries()} | ${"skew"} | ${[true]} + ${numSeries()} | ${"skew"} | ${[false]} + ${numSeries()} | ${"skew"} | ${[{ bias: true }]} + ${numSeries()} | ${"skew"} | ${[{ bias: false }]} + ${numSeries()} | ${"slice"} | ${[1, 2]} + ${numSeries()} | ${"slice"} | ${[{ offset: 1, length: 2 }]} + ${numSeries()} | ${"sort"} | ${[]} + ${numSeries()} | ${"sort"} | ${[false]} + ${numSeries()} | ${"sort"} | ${[true]} + ${numSeries()} | ${"sort"} | ${[{ reverse: true }]} + ${numSeries()} | ${"sort"} | ${[{ reverse: false }]} + ${numSeries()} | ${"sum"} | ${[]} + ${numSeries()} | ${"tail"} | ${[]} + ${numSeries()} | ${"take"} | ${[[1, 2]]} + ${numSeries()} | ${"takeEvery"} | ${[1]} + ${numSeries()} | ${"toArray"} | ${[]} + ${numSeries()} | ${"unique"} | ${[]} + ${numSeries()} | ${"valueCounts"} | ${[]} + ${numSeries()} | ${"zipWith"} | ${[boolSeries(), other()]} `("$# $method is callable", ({ series, method, args }) => { try { series[method](...args); diff --git a/package.json b/package.json index 4bc83a7f..d07f3567 100644 --- a/package.json +++ b/package.json @@ -55,17 +55,17 @@ "precommit": "yarn lint && yarn test" }, "devDependencies": { - "@biomejs/biome": "^1.3.1", - "@napi-rs/cli": "^2.16.3", + "@biomejs/biome": "^1.3.3", + "@napi-rs/cli": "^2.16.4", "@types/chance": "^1.1.5", - "@types/jest": "^29.5.6", - "@types/node": "^20.8.9", + "@types/jest": "^29.5.7", + "@types/node": "^20.8.10", "chance": "^1.1.11", "jest": "^29.7.0", "source-map-support": "^0.5.21", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", - "typedoc": "^0.25.2", + "typedoc": "^0.25.3", "typescript": "5.2.2" }, "packageManager": "yarn@3.6.2", diff --git a/polars/dataframe.ts b/polars/dataframe.ts index b10b401a..6d625bb5 100644 --- a/polars/dataframe.ts +++ b/polars/dataframe.ts @@ -1244,7 +1244,7 @@ export interface DataFrame * with the result of the `fill_value` expression. * ___ * @param opts - * @param opts.periods - Number of places to shift (may be negative). + * @param opts.n - Number of places to shift (may be negative). * @param opts.fillValue - fill null values with this value. * @example * ``` @@ -1253,7 +1253,7 @@ export interface DataFrame * ... "bar": [6, 7, 8], * ... "ham": ['a', 'b', 'c'] * ... }) - * > df.shiftAndFill({periods:1, fill_value:0}) + * > df.shiftAndFill({n:1, fill_value:0}) * shape: (3, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -1268,13 +1268,13 @@ export interface DataFrame * └─────┴─────┴─────┘ * ``` */ - shiftAndFill(periods: number, fillValue: number | string): DataFrame; + shiftAndFill(n: number, fillValue: number): DataFrame; shiftAndFill({ - periods, + n, fillValue, }: { - periods: number; - fillValue: number | string; + n: number; + fillValue: number; }): DataFrame; /** * Shrink memory usage of this DataFrame to fit the exact capacity needed to hold the data. @@ -1954,7 +1954,6 @@ export const _DataFrame = (_df: any): DataFrame => { every, period, offset, - truncate, includeBoundaries, closed, by, @@ -1965,7 +1964,6 @@ export const _DataFrame = (_df: any): DataFrame => { every, period, offset, - truncate, includeBoundaries, closed, by, @@ -2142,21 +2140,38 @@ export const _DataFrame = (_df: any): DataFrame => { sample(opts?, frac?, withReplacement = false, seed?) { // biome-ignore lint/style/noArguments: if (arguments.length === 0) { - return wrap("sampleN", 1, withReplacement, false, seed); + return wrap( + "sampleN", + Series("", [1]).inner(), + withReplacement, + false, + seed, + ); } if (opts?.n !== undefined || opts?.frac !== undefined) { return this.sample(opts.n, opts.frac, opts.withReplacement, seed); } if (typeof opts === "number") { - return wrap("sampleN", opts, withReplacement, false, seed); + return wrap( + "sampleN", + Series("", [opts]).inner(), + withReplacement, + false, + seed, + ); } if (typeof frac === "number") { - return wrap("sampleFrac", frac, withReplacement, false, seed); + return wrap( + "sampleFrac", + Series("", [frac]).inner(), + withReplacement, + false, + seed, + ); } else { throw new TypeError("must specify either 'frac' or 'n'"); } }, - select(...selection) { const hasExpr = selection.flat().some((s) => Expr.isExpr(s)); if (hasExpr) { @@ -2166,11 +2181,15 @@ export const _DataFrame = (_df: any): DataFrame => { } }, shift: (opt) => wrap("shift", opt?.periods ?? opt), - shiftAndFill(periods: any, fillValue?) { - return _DataFrame(_df) - .lazy() - .shiftAndFill(periods, fillValue) - .collectSync(); + shiftAndFill(n: any, fillValue?: number | undefined) { + if (typeof n === "number" && fillValue) { + return _DataFrame(_df).lazy().shiftAndFill(n, fillValue).collectSync(); + } else { + return _DataFrame(_df) + .lazy() + .shiftAndFill(n.n, n.fillValue) + .collectSync(); + } }, shrinkToFit(inPlace: any = false): any { if (inPlace) { diff --git a/polars/groupby.ts b/polars/groupby.ts index 9567a2cb..e12061d8 100644 --- a/polars/groupby.ts +++ b/polars/groupby.ts @@ -3,7 +3,7 @@ import * as utils from "./utils"; import util from "util"; import { Expr } from "./lazy/expr"; import { col, exclude } from "./lazy/functions"; -import { ColumnsOrExpr } from "./utils"; +import { ColumnsOrExpr, StartBy } from "./utils"; const inspect = Symbol.for("nodejs.util.inspect.custom"); const inspectOpts = { colors: true, depth: null }; @@ -301,10 +301,11 @@ export function DynamicGroupBy( every: string, period?: string, offset?: string, - truncate?: boolean, includeBoundaries?: boolean, closed?: string, by?: ColumnsOrExpr, + start_by?: StartBy, + check_sorted?: boolean, ): DynamicGroupBy { return { agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]) { @@ -315,10 +316,11 @@ export function DynamicGroupBy( every, period, offset, - truncate, includeBoundaries, closed, by, + start_by, + check_sorted, } as any) .agg(column as any, ...columns) .collectSync({ noOptimizations: true }); diff --git a/polars/io.ts b/polars/io.ts index c7c14395..967e79fb 100644 --- a/polars/io.ts +++ b/polars/io.ts @@ -475,6 +475,7 @@ interface ScanParquetOptions { rowCount?: RowCount; cache?: boolean; rechunk?: boolean; + hive_partitioning?: boolean; } /** diff --git a/polars/lazy/dataframe.ts b/polars/lazy/dataframe.ts index fc8bf4d3..dd325a3c 100644 --- a/polars/lazy/dataframe.ts +++ b/polars/lazy/dataframe.ts @@ -378,13 +378,10 @@ export interface LazyDataFrame extends Serialize, GroupByOps { /** * @see {@link DataFrame.shiftAndFill} */ - shiftAndFill( - periods: number, - fillValue: number | string | Expr, - ): LazyDataFrame; + shiftAndFill(n: number, fillValue: number): LazyDataFrame; shiftAndFill(opts: { - periods: number; - fillValue: number | string | Expr; + n: number; + fillValue: number; }): LazyDataFrame; /** * @see {@link DataFrame.slice} @@ -642,7 +639,6 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { every, period, offset, - truncate, includeBoundaries, closed, by, @@ -653,7 +649,6 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { offset = offset ?? `-${period}`; closed = closed ?? "right"; by = prepareGroupbyInputs(by); - truncate = truncate ?? true; includeBoundaries = includeBoundaries ?? false; start_by = start_by ?? "monday"; check_sorted = check_sorted ?? false; @@ -663,7 +658,6 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { every, period, offset, - truncate, includeBoundaries, closed, by, @@ -844,23 +838,17 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { shift(periods) { return _LazyDataFrame(_ldf.shift(periods)); }, - shiftAndFill(optOrPeriods, fillValue?) { - if (typeof optOrPeriods === "number") { - fillValue = exprToLitOrExpr(fillValue)._expr; - - return _LazyDataFrame(_ldf.shiftAndFill(optOrPeriods, fillValue)); + shiftAndFill(opts: any, fillValue?: number | undefined) { + if (typeof opts === "number") { + return _LazyDataFrame(_ldf.shiftAndFill(opts, fillValue)); } else { - fillValue = exprToLitOrExpr(optOrPeriods.fillValue)._expr; - const periods = optOrPeriods.periods; - - return _LazyDataFrame(_ldf.shiftAndFill(periods, fillValue)); + return _LazyDataFrame(_ldf.shiftAndFill(opts?.n, opts?.fillValue)); } }, slice(opt, len?) { if (opt?.offset !== undefined) { return _LazyDataFrame(_ldf.slice(opt.offset, opt.length)); } - return _LazyDataFrame(_ldf.slice(opt, len)); }, sort(arg, descending = false, maintain_order = false) { diff --git a/polars/lazy/expr/index.ts b/polars/lazy/expr/index.ts index 9649258f..0f5f78d8 100644 --- a/polars/lazy/expr/index.ts +++ b/polars/lazy/expr/index.ts @@ -35,7 +35,6 @@ export interface Expr Round, EwmOps, Serialize { - /** @ignore */ _expr: any; /** * Datetime namespace @@ -246,7 +245,7 @@ export interface Expr /** Create a boolean expression returning `true` where the expression values are finite. */ isFinite(): Expr; /** Get a mask of the first unique value. */ - isFirst(): Expr; + isFirstDistinct(): Expr; /** * Check if elements of this Series are in the right Series, or List values of the right Series. * @@ -349,6 +348,8 @@ export interface Expr list(): Expr; /** Returns a unit Series with the lowest value possible for the dtype of this expression. */ lowerBound(): Expr; + peakMax(): Expr; + peakMin(): Expr; /** Compute the max value of the arrays in the list */ max(): Expr; /** Compute the mean value of the arrays in the list */ @@ -487,11 +488,11 @@ export interface Expr * @param periods Number of places to shift (may be negative). * @param fillValue Fill null values with the result of this expression. */ - shiftAndFill(periods: number, fillValue: Expr): Expr; + shiftAndFill(periods: number, fillValue: number): Expr; shiftAndFill({ periods, fillValue, - }: { periods: number; fillValue: Expr }): Expr; + }: { periods: number; fillValue: number }): Expr; /** * Compute the sample skewness of a data set. * For normally distributed data, the skewness should be about zero. For @@ -575,7 +576,6 @@ export interface Expr where(predicate: Expr): Expr; } -/** @ignore */ export const _Expr = (_expr: any): Expr => { const unwrap = (method: string, ...args: any[]) => { return _expr[method as any](...args); @@ -590,7 +590,8 @@ export const _Expr = (_expr: any): Expr => { }; const rolling = - (method: string) => (opts, weights?, minPeriods?, center?): Expr => { + (method: string) => + (opts, weights?, minPeriods?, center?): Expr => { const windowSize = opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null); if (windowSize === null) { @@ -685,9 +686,16 @@ export const _Expr = (_expr: any): Expr => { }, clip(arg, max?) { if (typeof arg === "number") { - return _Expr(_expr.clip(arg, max)); + return _Expr( + _expr.clip(exprToLitOrExpr(arg)._expr, exprToLitOrExpr(max)._expr), + ); } else { - return _Expr(_expr.clip(arg.min, arg.max)); + return _Expr( + _expr.clip( + exprToLitOrExpr(arg.min)._expr, + exprToLitOrExpr(arg.max)._expr, + ), + ); } }, count() { @@ -929,8 +937,8 @@ export const _Expr = (_expr: any): Expr => { isInfinite() { return _Expr(_expr.isInfinite()); }, - isFirst() { - return _Expr(_expr.isFirst()); + isFirstDistinct() { + return _Expr(_expr.isFirstDistinct()); }, isNan() { return _Expr(_expr.isNan()); @@ -974,6 +982,12 @@ export const _Expr = (_expr: any): Expr => { lowerBound() { return _Expr(_expr.lowerBound()); }, + peakMax() { + return _Expr(_expr.peakMax()); + }, + peakMin() { + return _Expr(_expr.peakMin()); + }, max() { return _Expr(_expr.max()); }, @@ -1113,14 +1127,13 @@ export const _Expr = (_expr: any): Expr => { }, shiftAndFill(optOrPeriods, fillValue?) { if (typeof optOrPeriods === "number") { - fillValue = exprToLitOrExpr(fillValue).inner(); - return wrap("shiftAndFill", optOrPeriods, fillValue); } else { - fillValue = exprToLitOrExpr(optOrPeriods.fillValue).inner(); - const periods = optOrPeriods.periods; - - return wrap("shiftAndFill", periods, fillValue); + return wrap( + "shiftAndFill", + optOrPeriods.periods, + optOrPeriods.fillValue, + ); } }, skew(bias) { @@ -1245,7 +1258,6 @@ export const Expr: ExprConstructor = Object.assign(_Expr, { deserialize, }); -/** @ignore */ export const exprToLitOrExpr = (expr: any, stringToLit = true): Expr => { if (typeof expr === "string" && !stringToLit) { return _Expr(pli.col(expr)); diff --git a/polars/lazy/expr/list.ts b/polars/lazy/expr/list.ts index 8d73b7a6..126a702d 100644 --- a/polars/lazy/expr/list.ts +++ b/polars/lazy/expr/list.ts @@ -1,4 +1,4 @@ -import { Expr, _Expr } from "../expr"; +import { Expr, _Expr, exprToLitOrExpr } from "../expr"; import { ListFunctions } from "../../shared_traits"; import { Series } from "../../series"; import pli from "../../internals/polars_internal"; @@ -71,7 +71,7 @@ export const ExprListFunctions = (_expr: any): ExprList => { return this.get(0); }, join(separator = ",") { - return wrap("listJoin", separator); + return wrap("listJoin", exprToLitOrExpr(separator)._expr); }, last() { return this.get(-1); diff --git a/polars/lazy/expr/string.ts b/polars/lazy/expr/string.ts index e9773fbe..b4f07248 100644 --- a/polars/lazy/expr/string.ts +++ b/polars/lazy/expr/string.ts @@ -1,7 +1,7 @@ import { StringFunctions } from "../../shared_traits"; import { DataType } from "../../datatypes"; import { regexToString } from "../../utils"; -import { Expr, _Expr } from "../expr"; +import { Expr, _Expr, exprToLitOrExpr } from "../expr"; /** * namespace containing expr string functions @@ -379,8 +379,7 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => { split(by: string, options?) { const inclusive = typeof options === "boolean" ? options : options?.inclusive; - - return wrap("strSplit", by, inclusive); + return wrap("strSplit", exprToLitOrExpr(by)._expr, inclusive); }, strip() { return wrap("strStrip"); diff --git a/polars/series/index.ts b/polars/series/index.ts index cd1448ce..58914cef 100644 --- a/polars/series/index.ts +++ b/polars/series/index.ts @@ -419,7 +419,7 @@ export interface Series /** * Get a mask of the first unique value. */ - isFirst(): Series; + isFirstDistinct(): Series; /** * Check if this Series is a Float. */ @@ -822,8 +822,8 @@ export interface Series * @param periods - Number of places to shift (may be negative). * @param fillValue - Fill null & undefined values with the result of this expression. */ - shiftAndFill(periods: number, fillValue: any): Series; - shiftAndFill(args: { periods: number; fillValue: any }): Series; + shiftAndFill(periods: number, fillValue: number): Series; + shiftAndFill(args: { periods: number; fillValue: number }): Series; /** * __Shrink memory usage of this Series to fit the exact capacity needed to hold the data.__ @@ -1369,8 +1369,8 @@ export function _Series(_s: any): Series { return wrap("isFinite"); } }, - isFirst() { - return wrap("isFirst"); + isFirstDistinct() { + return wrap("isFirstDistinct"); }, isFloat() { const dtype = this.dtype; @@ -1500,10 +1500,10 @@ export function _Series(_s: any): Series { return _s.nUnique(); }, peakMax() { - return wrap("peakMax"); + return expr_op("peakMax"); }, peakMin() { - return wrap("peakMin"); + return expr_op("peakMin"); }, plus(other) { return dtypeWrap("Add", other); diff --git a/polars/shared_traits.ts b/polars/shared_traits.ts index 9f8d182b..584110fc 100644 --- a/polars/shared_traits.ts +++ b/polars/shared_traits.ts @@ -1181,7 +1181,6 @@ export interface GroupByOps { every: string; period?: string; offset?: string; - truncate?: boolean; includeBoundaries?: boolean; closed?: "left" | "right" | "both" | "none"; by?: ColumnsOrExpr; diff --git a/rust-toolchain b/rust-toolchain index 91c334b0..acd39859 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2023-07-27 \ No newline at end of file +nightly-2023-10-12 \ No newline at end of file diff --git a/src/dataframe.rs b/src/dataframe.rs index 69f4b9a1..a9e218fb 100644 --- a/src/dataframe.rs +++ b/src/dataframe.rs @@ -118,7 +118,7 @@ pub fn read_csv( .infer_schema(infer_schema_length) .has_header(options.has_header) .with_n_rows(n_rows) - .with_delimiter(options.sep.as_bytes()[0]) + .with_separator(options.sep.as_bytes()[0]) .with_skip_rows(skip_rows) .with_ignore_errors(options.ignore_errors) .with_rechunk(options.rechunk) @@ -141,7 +141,7 @@ pub fn read_csv( .infer_schema(infer_schema_length) .has_header(options.has_header) .with_n_rows(n_rows) - .with_delimiter(options.sep.as_bytes()[0]) + .with_separator(options.sep.as_bytes()[0]) .with_skip_rows(skip_rows) .with_ignore_errors(options.ignore_errors) .with_rechunk(options.rechunk) @@ -589,7 +589,7 @@ impl JsDataFrame { #[napi(catch_unwind)] pub fn get_columns(&self) -> Vec { - let cols = self.df.get_columns().clone(); + let cols = self.df.get_columns(); to_jsseries_collection(cols.to_vec()) } @@ -855,7 +855,7 @@ impl JsDataFrame { select: Option>, agg: String, ) -> napi::Result { - let gb = self.df.groupby(&by).map_err(JsPolarsErr::from)?; + let gb = self.df.group_by(&by).map_err(JsPolarsErr::from)?; let selection = match select.as_ref() { Some(s) => gb.select(s), None => gb, @@ -1083,7 +1083,7 @@ impl JsDataFrame { #[napi(catch_unwind)] pub fn sample_n( &self, - n: i64, + n: &JsSeries, with_replacement: bool, shuffle: bool, seed: Option, @@ -1091,7 +1091,7 @@ impl JsDataFrame { let df = self .df .sample_n( - n as usize, + &n.series, with_replacement, shuffle, seed.map(|s| s as u64), @@ -1103,14 +1103,14 @@ impl JsDataFrame { #[napi(catch_unwind)] pub fn sample_frac( &self, - frac: f64, + frac: &JsSeries, with_replacement: bool, shuffle: bool, seed: Option, ) -> napi::Result { let df = self .df - .sample_frac(frac, with_replacement, shuffle, seed.map(|s| s as u64)) + .sample_frac(&frac.series, with_replacement, shuffle, seed.map(|s| s as u64)) .map_err(JsPolarsErr::from)?; Ok(df.into()) } @@ -1333,8 +1333,8 @@ impl JsDataFrame { let f = BufWriter::new(f); CsvWriter::new(f) .has_header(has_header) - .with_delimiter(sep) - .with_quoting_char(quote) + .with_separator(sep) + .with_quote_char(quote) .finish(&mut self.df) .map_err(JsPolarsErr::from)?; } @@ -1344,8 +1344,8 @@ impl JsDataFrame { CsvWriter::new(writeable) .has_header(has_header) - .with_delimiter(sep) - .with_quoting_char(quote) + .with_separator(sep) + .with_quote_char(quote) .finish(&mut self.df) .map_err(JsPolarsErr::from)?; } diff --git a/src/functions.rs b/src/functions.rs index f958c6e2..eb791c43 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -6,14 +6,14 @@ use polars_core::prelude::DataFrame; #[napi(catch_unwind)] pub fn horizontal_concat(dfs: Vec<&JsDataFrame>) -> napi::Result { let dfs: Vec = dfs.iter().map(|df| df.df.clone()).collect(); - let df = pl_functions::hor_concat_df(&dfs).map_err(crate::error::JsPolarsErr::from)?; + let df = pl_functions::concat_df_horizontal(&dfs).map_err(crate::error::JsPolarsErr::from)?; Ok(df.into()) } #[napi(catch_unwind)] pub fn diagonal_concat(dfs: Vec<&JsDataFrame>) -> napi::Result { let dfs: Vec = dfs.iter().map(|df| df.df.clone()).collect(); - let df = pl_functions::diag_concat_df(&dfs).map_err(crate::error::JsPolarsErr::from)?; + let df = pl_functions::concat_df_diagonal(&dfs).map_err(crate::error::JsPolarsErr::from)?; Ok(df.into()) } diff --git a/src/lazy/dataframe.rs b/src/lazy/dataframe.rs index 9e3c2199..8875664b 100644 --- a/src/lazy/dataframe.rs +++ b/src/lazy/dataframe.rs @@ -4,8 +4,8 @@ use crate::prelude::*; use napi::{Env, Task}; use polars::io::RowCount; use polars::lazy::frame::{LazyCsvReader, LazyFrame, LazyGroupBy}; -use polars::prelude::{ClosedWindow, CsvEncoding, DataFrame, Field, JoinType, Schema}; -use polars_core::cloud::CloudOptions; +use polars::prelude::{ClosedWindow, CsvEncoding, DataFrame, Field, JoinType, Schema, col, lit}; +use polars_io::cloud::CloudOptions; use polars_io::parquet::ParallelStrategy; use std::collections::HashMap; @@ -210,9 +210,9 @@ impl JsLazyFrame { let ldf = self.ldf.clone(); let by = by.to_exprs(); let lazy_gb = if maintain_order { - ldf.groupby_stable(by) + ldf.group_by_stable(by) } else { - ldf.groupby(by) + ldf.group_by(by) }; JsLazyGroupBy { lgb: Some(lazy_gb) } @@ -230,7 +230,7 @@ impl JsLazyFrame { let closed_window = closed.0; let ldf = self.ldf.clone(); let by = by.to_exprs(); - let lazy_gb = ldf.groupby_rolling( + let lazy_gb = ldf.group_by_rolling( index_column.inner.clone(), by, RollingGroupOptions { @@ -253,7 +253,6 @@ impl JsLazyFrame { every: String, period: String, offset: String, - truncate: bool, include_boundaries: bool, closed: Wrap, by: Vec<&JsExpr>, @@ -263,14 +262,14 @@ impl JsLazyFrame { let closed_window = closed.0; let by = by.to_exprs(); let ldf = self.ldf.clone(); - let lazy_gb = ldf.groupby_dynamic( + let lazy_gb = ldf.group_by_dynamic( index_column.inner.clone(), by, DynamicGroupOptions { every: Duration::parse(&every), period: Duration::parse(&period), offset: Duration::parse(&offset), - truncate, + label: Label::DataPoint, include_boundaries, closed_window, start_by: start_by.0, @@ -377,9 +376,9 @@ impl JsLazyFrame { ldf.shift(periods).into() } #[napi(catch_unwind)] - pub fn shift_and_fill(&self, periods: i64, fill_value: &JsExpr) -> JsLazyFrame { + pub fn shift_and_fill(&self, periods: i64, fill_value: i64) -> JsLazyFrame { let ldf = self.ldf.clone(); - ldf.shift_and_fill(periods, fill_value.inner.clone()).into() + ldf.shift_and_fill(periods, fill_value).into() } #[napi(catch_unwind)] @@ -510,9 +509,9 @@ impl JsLazyFrame { } #[napi(catch_unwind)] - pub fn drop_columns(&self, cols: Vec) -> JsLazyFrame { + pub fn drop_columns(&self, colss: Vec) -> JsLazyFrame { let ldf = self.ldf.clone(); - ldf.drop_columns(cols).into() + ldf.drop_columns(colss).into() } #[napi(js_name = "clone", catch_unwind)] pub fn clone(&self) -> JsLazyFrame { @@ -531,8 +530,8 @@ impl JsLazyFrame { } #[napi(catch_unwind)] - pub fn unnest(&self, cols: Vec) -> JsLazyFrame { - self.ldf.clone().unnest(cols).into() + pub fn unnest(&self, colss: Vec) -> JsLazyFrame { + self.ldf.clone().unnest(colss).into() } } @@ -597,7 +596,7 @@ pub fn scan_csv(path: String, options: ScanCsvOptions) -> napi::Result, pub low_memory: Option, pub use_statistics: Option, + pub hive_partitioning: Option, } #[napi(catch_unwind)] @@ -640,6 +640,7 @@ pub fn scan_parquet(path: String, options: ScanParquetOptions) -> napi::Result napi::Result napi::Result { env.to_js_value(&self.inner) } - #[napi(catch_unwind)] pub fn serialize(&self, format: String) -> napi::Result { let buf = match format.as_ref() { @@ -367,10 +366,10 @@ impl JsExpr { } #[napi(catch_unwind)] - pub fn shift_and_fill(&self, periods: i64, fill_value: &JsExpr) -> JsExpr { + pub fn shift_and_fill(&self, periods: i64, fill_value: i64) -> JsExpr { self.clone() .inner - .shift_and_fill(periods, fill_value.inner.clone()) + .shift_and_fill(periods, fill_value) .into() } @@ -438,8 +437,8 @@ impl JsExpr { } #[napi(catch_unwind)] - pub fn is_first(&self) -> JsExpr { - self.clone().inner.is_first().into() + pub fn is_first_distinct(&self) -> JsExpr { + self.clone().inner.is_first_distinct().into() } #[napi(catch_unwind)] @@ -490,10 +489,9 @@ impl JsExpr { self.clone().inner.ceil().into() } #[napi(catch_unwind)] - pub fn clip(&self, min: Wrap, max: Wrap) -> JsExpr { - self.clone().inner.clip(min.0, max.0).into() + pub fn clip(&self, min: &JsExpr, max: &JsExpr) -> JsExpr { + self.clone().inner.clip(min.inner.clone(), max.inner.clone()).into() } - #[napi(catch_unwind)] pub fn abs(&self) -> JsExpr { self.clone().inner.abs().into() @@ -565,14 +563,12 @@ impl JsExpr { strict: bool, exact: bool, cache: bool, - use_earliest: Option, ) -> JsExpr { let options = StrptimeOptions { format, strict, exact, cache, - use_earliest: use_earliest, }; self.inner.clone().str().to_date(options).into() } @@ -587,19 +583,21 @@ impl JsExpr { strict: bool, exact: bool, cache: bool, - use_earliest: Option, + ambiguous: Option>, ) -> JsExpr { let options = StrptimeOptions { format, strict, exact, cache, - use_earliest: use_earliest, }; + let ambiguous = ambiguous + .map(|e| e.0) + .unwrap_or(dsl::lit(String::from("raise"))); self.inner .clone() .str() - .to_datetime(time_unit.map(|tu| tu.0), time_zone, options) + .to_datetime(time_unit.map(|tu| tu.0), time_zone, options, ambiguous) .into() } @@ -607,7 +605,7 @@ impl JsExpr { pub fn str_strip(&self) -> JsExpr { let function = |s: Series| { let ca = s.utf8()?; - Ok(Some(ca.apply(|s| Cow::Borrowed(s.trim())).into_series())) + Ok(Some(ca.apply(|s| Some(Cow::Borrowed(s?.trim()))).into_series())) }; self.clone() .inner @@ -621,7 +619,7 @@ impl JsExpr { let function = |s: Series| { let ca = s.utf8()?; Ok(Some( - ca.apply(|s| Cow::Borrowed(s.trim_end())).into_series(), + ca.apply(|s| Some(Cow::Borrowed(s?.trim_end()))).into_series(), )) }; self.clone() @@ -636,7 +634,7 @@ impl JsExpr { let function = |s: Series| { let ca = s.utf8()?; Ok(Some( - ca.apply(|s| Cow::Borrowed(s.trim_start())).into_series(), + ca.apply(|s| Some(Cow::Borrowed(s?.trim_start()))).into_series(), )) }; self.clone() @@ -663,6 +661,7 @@ impl JsExpr { .into() } + #[napi(catch_unwind)] pub fn str_pad_end(&self, length: i64, fill_char: String) -> JsExpr { let function = move |s: Series| { @@ -679,6 +678,7 @@ impl JsExpr { .with_fmt("str.pad_end") .into() } + #[napi(catch_unwind)] pub fn str_z_fill(&self, width: i64) -> JsExpr { let function = move |s: Series| { @@ -709,7 +709,7 @@ impl JsExpr { let function = move |s: Series| { let length = length.map(|l| l as u64); let ca = s.utf8()?; - Ok(Some(ca.str_slice(start, length)?.into_series())) + Ok(Some(ca.str_slice(start, length).into_series())) }; self.clone() .inner @@ -735,7 +735,7 @@ impl JsExpr { pub fn str_lengths(&self) -> JsExpr { let function = |s: Series| { let ca = s.utf8()?; - Ok(Some(ca.str_lengths().into_series())) + Ok(Some(ca.str_len_chars().into_series())) }; self.clone() .inner @@ -882,23 +882,23 @@ impl JsExpr { self.inner.clone().dt().strftime(&fmt).into() } #[napi(catch_unwind)] - pub fn str_split(&self, by: String) -> JsExpr { - self.inner.clone().str().split(&by).into() + pub fn str_split(&self, by: &JsExpr) -> JsExpr { + self.inner.clone().str().split(by.inner.clone()).into() } #[napi(catch_unwind)] - pub fn str_split_inclusive(&self, by: String) -> JsExpr { - self.inner.clone().str().split_inclusive(&by).into() + pub fn str_split_inclusive(&self, by: Wrap) -> JsExpr { + self.inner.clone().str().split_inclusive(by.0).into() } #[napi(catch_unwind)] - pub fn str_split_exact(&self, by: String, n: i64) -> JsExpr { - self.inner.clone().str().split_exact(&by, n as usize).into() + pub fn str_split_exact(&self, by: Wrap, n: i64) -> JsExpr { + self.inner.clone().str().split_exact(by.0, n as usize).into() } #[napi(catch_unwind)] - pub fn str_split_exact_inclusive(&self, by: String, n: i64) -> JsExpr { + pub fn str_split_exact_inclusive(&self, by: Wrap, n: i64) -> JsExpr { self.inner .clone() .str() - .split_exact_inclusive(&by, n as usize) + .split_exact_inclusive(by.0, n as usize) .into() } @@ -1076,6 +1076,14 @@ impl JsExpr { self.inner.clone().interpolate(method.0).into() } #[napi(catch_unwind)] + pub fn peak_min(&self) -> JsExpr { + self.inner.clone().peak_min().into() + } + #[napi(catch_unwind)] + pub fn peak_max(&self) -> JsExpr { + self.inner.clone().peak_max().into() + } + #[napi(catch_unwind)] pub fn rolling_sum(&self, options: JsRollingOptions) -> JsExpr { self.inner.clone().rolling_sum(options.into()).into() } @@ -1133,7 +1141,7 @@ impl JsExpr { pub fn rolling_skew(&self, window_size: i64, bias: bool) -> JsExpr { self.inner .clone() - .rolling_apply_float(window_size as usize, move |ca| { + .rolling_map_float(window_size as usize, move |ca| { ca.clone().into_series().skew(bias).unwrap() }) .into() @@ -1142,7 +1150,7 @@ impl JsExpr { pub fn lower_bound(&self) -> JsExpr { self.inner.clone().lower_bound().into() } - + #[napi(catch_unwind)] pub fn upper_bound(&self) -> JsExpr { self.inner.clone().upper_bound().into() @@ -1191,15 +1199,15 @@ impl JsExpr { } #[napi(catch_unwind)] pub fn list_lengths(&self) -> JsExpr { - self.inner.clone().list().lengths().into() + self.inner.clone().list().len().into() } #[napi(catch_unwind)] pub fn list_get(&self, index: &JsExpr) -> JsExpr { self.inner.clone().list().get(index.inner.clone()).into() } #[napi(catch_unwind)] - pub fn list_join(&self, separator: String) -> JsExpr { - self.inner.clone().list().join(&separator).into() + pub fn list_join(&self, separator: &JsExpr) -> JsExpr { + self.inner.clone().list().join(separator.inner.clone()).into() } #[napi(catch_unwind)] pub fn list_arg_min(&self) -> JsExpr { @@ -1216,8 +1224,8 @@ impl JsExpr { } #[napi(catch_unwind)] - pub fn list_shift(&self, periods: i64) -> JsExpr { - self.inner.clone().list().shift(periods).into() + pub fn list_shift(&self, periods: Wrap) -> JsExpr { + self.inner.clone().list().shift(periods.0).into() } #[napi(catch_unwind)] pub fn list_slice(&self, offset: &JsExpr, length: Option<&JsExpr>) -> JsExpr { @@ -1255,8 +1263,8 @@ impl JsExpr { self.inner.clone().diff(n, null_behavior.0).into() } #[napi(catch_unwind)] - pub fn pct_change(&self, n: i64) -> JsExpr { - self.inner.clone().pct_change(n).into() + pub fn pct_change(&self, n: Wrap) -> JsExpr { + self.inner.clone().pct_change(n.0).into() } #[napi(catch_unwind)] @@ -1302,23 +1310,22 @@ impl JsExpr { } #[napi(catch_unwind)] - pub fn shuffle(&self, seed: Wrap, fixed_seed: bool) -> JsExpr { - self.inner.clone().shuffle(Some(seed.0), fixed_seed).into() + pub fn shuffle(&self, seed: Wrap) -> JsExpr { + self.inner.clone().shuffle(Some(seed.0)).into() } #[napi(catch_unwind)] pub fn sample_frac( &self, - frac: f64, + frac: Wrap, with_replacement: bool, shuffle: bool, seed: Option, - fixed_seed: bool, ) -> JsExpr { let seed = seed.map(|s| s as u64); self.inner .clone() - .sample_frac(frac, with_replacement, shuffle, seed, fixed_seed) + .sample_frac(frac.0, with_replacement, shuffle, seed) .into() } #[napi(catch_unwind)] @@ -1621,12 +1628,8 @@ pub fn lit(value: Wrap) -> JsResult { } #[napi(catch_unwind)] -pub fn range(low: i64, high: i64, dtype: Wrap) -> JsExpr { - match dtype.0 { - DataType::Int32 => dsl::range(low as i32, high as i32).into(), - DataType::UInt32 => dsl::range(low as u32, high as u32).into(), - _ => dsl::range(low, high).into(), - } +pub fn range(low: Wrap, high: Wrap, dtype: Wrap) -> JsExpr { + int_range(low, high, 1, Some(dtype)).into() } #[napi(catch_unwind)] @@ -1645,7 +1648,7 @@ pub fn concat_str(s: Vec<&JsExpr>, sep: String) -> JsExpr { #[napi(catch_unwind)] pub fn as_struct(exprs: Vec<&JsExpr>) -> JsExpr { let exprs = exprs.to_exprs(); - polars::lazy::dsl::as_struct(&exprs).into() + polars::lazy::dsl::as_struct(exprs).into() } #[napi(catch_unwind)] diff --git a/src/lib.rs b/src/lib.rs index abb6bd2c..011a8f82 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,8 @@ pub fn version() -> &'static str { } #[napi] -pub fn toggle_string_cache(toggle: bool) { - polars::enable_string_cache(toggle) +pub fn toggle_string_cache() { + polars::enable_string_cache() } pub mod conversion; diff --git a/src/list_construction.rs b/src/list_construction.rs index b9b29b4e..f2bed746 100644 --- a/src/list_construction.rs +++ b/src/list_construction.rs @@ -2,6 +2,7 @@ use crate::prelude::*; use napi::{Either, JsTypedArrayValue}; use polars::chunked_array::ChunkedArray; +use napi::bindgen_prelude::Null; macro_rules! typed_to_chunked { ($arr:expr, $type:ty, $pl_type:ty) => {{ diff --git a/src/prelude.rs b/src/prelude.rs index c3e92676..bc939d52 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -2,5 +2,6 @@ pub use crate::conversion::*; pub use crate::datatypes::*; pub use crate::error::*; pub use napi::bindgen_prelude::*; +pub use napi::bindgen_prelude::Null; pub use napi::Result as JsResult; pub use polars::prelude::*; diff --git a/src/series.rs b/src/series.rs index 7bf376aa..9d293b8e 100644 --- a/src/series.rs +++ b/src/series.rs @@ -336,24 +336,24 @@ impl JsSeries { Ok(out.into()) } #[napi(catch_unwind)] - pub fn cumsum(&self, reverse: Option) -> JsSeries { + pub fn cumsum(&self, reverse: Option) -> napi::Result { let reverse = reverse.unwrap_or(false); - self.series.cumsum(reverse).into() + Ok(cumsum(&self.series, reverse).map_err(JsPolarsErr::from)?.into()) } #[napi(catch_unwind)] - pub fn cummax(&self, reverse: Option) -> JsSeries { + pub fn cummax(&self, reverse: Option) -> napi::Result { let reverse = reverse.unwrap_or(false); - self.series.cummax(reverse).into() + Ok(cummax(&self.series, reverse).map_err(JsPolarsErr::from)?.into()) } #[napi(catch_unwind)] - pub fn cummin(&self, reverse: Option) -> JsSeries { + pub fn cummin(&self, reverse: Option) -> napi::Result { let reverse = reverse.unwrap_or(false); - self.series.cummin(reverse).into() + Ok(cummin(&self.series, reverse).map_err(JsPolarsErr::from)?.into()) } #[napi(catch_unwind)] - pub fn cumprod(&self, reverse: Option) -> JsSeries { + pub fn cumprod(&self, reverse: Option) -> napi::Result { let reverse = reverse.unwrap_or(false); - self.series.cumprod(reverse).into() + Ok(cumprod(&self.series, reverse).map_err(JsPolarsErr::from)?.into()) } #[napi(catch_unwind)] pub fn chunk_lengths(&self) -> Vec { @@ -523,7 +523,6 @@ impl JsSeries { #[napi(catch_unwind)] pub fn take(&self, indices: Vec) -> napi::Result { let indices = UInt32Chunked::from_vec("", indices); - let take = self.series.take(&indices).map_err(JsPolarsErr::from)?; Ok(JsSeries::new(take)) } @@ -580,7 +579,7 @@ impl JsSeries { #[napi(catch_unwind)] pub fn is_unique(&self) -> napi::Result { - let ca = polars_ops::prelude::is_unique(&self.series).map_err(JsPolarsErr::from)?; + let ca = is_unique(&self.series).map_err(JsPolarsErr::from)?; Ok(ca.into_series().into()) } @@ -621,7 +620,7 @@ impl JsSeries { } #[napi(catch_unwind)] pub fn is_duplicated(&self) -> napi::Result { - let ca = polars_ops::prelude::is_duplicated(&self.series).map_err(JsPolarsErr::from)?; + let ca = is_duplicated(&self.series).map_err(JsPolarsErr::from)?; Ok(ca.into_series().into()) } #[napi(catch_unwind)] @@ -779,11 +778,11 @@ impl JsSeries { #[napi(catch_unwind)] pub fn is_in(&self, other: &JsSeries) -> napi::Result { - let out = self - .series - .is_in(&other.series) - .map_err(JsPolarsErr::from)?; - Ok(out.into_series().into()) + let series = is_in(&self.series, &other.series) + .map(|ca| ca.into_series()) + .map_err(JsPolarsErr::from)?; + + Ok(JsSeries::new(series)) } #[napi(catch_unwind)] @@ -824,7 +823,7 @@ impl JsSeries { #[napi(catch_unwind)] pub fn str_lengths(&self) -> napi::Result { let ca = self.series.utf8().map_err(JsPolarsErr::from)?; - let s = ca.str_lengths().into_series(); + let s = ca.str_len_chars().into_series(); Ok(JsSeries::new(s)) } @@ -913,7 +912,6 @@ impl JsSeries { let ca = self.series.utf8().map_err(JsPolarsErr::from)?; let s = ca .str_slice(start, length.map(|l| l as u64)) - .map_err(JsPolarsErr::from)? .into_series(); Ok(s.into()) } @@ -992,12 +990,10 @@ impl JsSeries { // let df = self.series.to_dummies().map_err(JsPolarsErr::from)?; // Ok(df.into()) } - #[napi(catch_unwind)] pub fn get_list(&self, index: i64) -> Option { if let Ok(ca) = &self.series.list() { - let s = ca.get(index as usize); - s.map(|s| s.into()) + Some(ca.get_as_series(index as usize)?.into()) } else { None } @@ -1060,15 +1056,6 @@ impl JsSeries { .map_err(JsPolarsErr::from)?; Ok((ms / 1000).into_series().into()) } - #[napi(catch_unwind)] - pub fn peak_max(&self) -> JsSeries { - self.series.peak_max().into_series().into() - } - #[napi(catch_unwind)] - pub fn peak_min(&self) -> JsSeries { - self.series.peak_min().into_series().into() - } - #[napi(catch_unwind)] pub fn n_unique(&self) -> napi::Result { let n = self.series.n_unique().map_err(JsPolarsErr::from)?; @@ -1076,8 +1063,8 @@ impl JsSeries { } #[napi(catch_unwind)] - pub fn is_first(&self) -> napi::Result { - let out = is_first(&self.series) + pub fn is_first_distinct(&self) -> napi::Result { + let out = is_first_distinct(&self.series) .map_err(JsPolarsErr::from)? .into_series(); Ok(out.into()) @@ -1123,7 +1110,7 @@ impl JsSeries { #[napi(catch_unwind)] pub fn mode(&self) -> napi::Result { - let s = self.series.mode().map_err(JsPolarsErr::from)?; + let s = mode::mode(&self.series).map_err(JsPolarsErr::from)?; Ok(s.into()) } @@ -1146,10 +1133,7 @@ impl JsSeries { } #[napi(catch_unwind)] pub fn diff(&self, n: i64, null_behavior: Wrap) -> napi::Result { - let s = self - .series - .diff(n, null_behavior.0) - .map_err(JsPolarsErr::from)?; + let s = diff(&self.series , n, null_behavior.0).map_err(JsPolarsErr::from)?; Ok(s.into()) } diff --git a/yarn.lock b/yarn.lock index d807e0a1..25f55774 100644 --- a/yarn.lock +++ b/yarn.lock @@ -408,16 +408,16 @@ __metadata: languageName: node linkType: hard -"@biomejs/biome@npm:^1.3.1": - version: 1.3.1 - resolution: "@biomejs/biome@npm:1.3.1" - dependencies: - "@biomejs/cli-darwin-arm64": 1.3.1 - "@biomejs/cli-darwin-x64": 1.3.1 - "@biomejs/cli-linux-arm64": 1.3.1 - "@biomejs/cli-linux-x64": 1.3.1 - "@biomejs/cli-win32-arm64": 1.3.1 - "@biomejs/cli-win32-x64": 1.3.1 +"@biomejs/biome@npm:^1.3.3": + version: 1.3.3 + resolution: "@biomejs/biome@npm:1.3.3" + dependencies: + "@biomejs/cli-darwin-arm64": 1.3.3 + "@biomejs/cli-darwin-x64": 1.3.3 + "@biomejs/cli-linux-arm64": 1.3.3 + "@biomejs/cli-linux-x64": 1.3.3 + "@biomejs/cli-win32-arm64": 1.3.3 + "@biomejs/cli-win32-x64": 1.3.3 dependenciesMeta: "@biomejs/cli-darwin-arm64": optional: true @@ -433,48 +433,48 @@ __metadata: optional: true bin: biome: bin/biome - checksum: d650ab977b3b4cb53105f528f89e4e92f92fb89ffe0ec18629c2061858540ac3f294b507231d6ef19314c22df818e06690629186e739312964b32c54151ee1b5 + checksum: fa417f938868bdb2246097c98d413272fe3e104d3ca2548dca90ccad9e3a2f65da805e078430b726041f99f8166903a14a808bdde35b36252d17cbe2a61757db languageName: node linkType: hard -"@biomejs/cli-darwin-arm64@npm:1.3.1": - version: 1.3.1 - resolution: "@biomejs/cli-darwin-arm64@npm:1.3.1" +"@biomejs/cli-darwin-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@biomejs/cli-darwin-arm64@npm:1.3.3" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-darwin-x64@npm:1.3.1": - version: 1.3.1 - resolution: "@biomejs/cli-darwin-x64@npm:1.3.1" +"@biomejs/cli-darwin-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@biomejs/cli-darwin-x64@npm:1.3.3" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@biomejs/cli-linux-arm64@npm:1.3.1": - version: 1.3.1 - resolution: "@biomejs/cli-linux-arm64@npm:1.3.1" +"@biomejs/cli-linux-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@biomejs/cli-linux-arm64@npm:1.3.3" conditions: os=linux & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-linux-x64@npm:1.3.1": - version: 1.3.1 - resolution: "@biomejs/cli-linux-x64@npm:1.3.1" +"@biomejs/cli-linux-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@biomejs/cli-linux-x64@npm:1.3.3" conditions: os=linux & cpu=x64 languageName: node linkType: hard -"@biomejs/cli-win32-arm64@npm:1.3.1": - version: 1.3.1 - resolution: "@biomejs/cli-win32-arm64@npm:1.3.1" +"@biomejs/cli-win32-arm64@npm:1.3.3": + version: 1.3.3 + resolution: "@biomejs/cli-win32-arm64@npm:1.3.3" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-win32-x64@npm:1.3.1": - version: 1.3.1 - resolution: "@biomejs/cli-win32-x64@npm:1.3.1" +"@biomejs/cli-win32-x64@npm:1.3.3": + version: 1.3.3 + resolution: "@biomejs/cli-win32-x64@npm:1.3.3" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -804,12 +804,12 @@ __metadata: languageName: node linkType: hard -"@napi-rs/cli@npm:^2.16.3": - version: 2.16.3 - resolution: "@napi-rs/cli@npm:2.16.3" +"@napi-rs/cli@npm:^2.16.4": + version: 2.16.4 + resolution: "@napi-rs/cli@npm:2.16.4" bin: napi: scripts/index.js - checksum: 11f78b09548bc5c22df56e4fab4a87b68c2d3f2a18a55cf11e775e6a4cb5739ec0e21a14e614db2cdc2b9773cb42536c6bd00c3f85d3b461f956594f8a89ddcb + checksum: cc4eea0719c649ee9f9704a20bcd6a55dd48f5622edecc1ff47611f09c7ad0e45c865c4c5ebc11fa1c5166dea996bee39c0c2dac9edd9c2be7b1cc74940bb296 languageName: node linkType: hard @@ -971,13 +971,13 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^29.5.6": - version: 29.5.6 - resolution: "@types/jest@npm:29.5.6" +"@types/jest@npm:^29.5.7": + version: 29.5.7 + resolution: "@types/jest@npm:29.5.7" dependencies: expect: ^29.0.0 pretty-format: ^29.0.0 - checksum: fa13a27bd1c8efd0381a419478769d0d6d3a8e93e1952d7ac3a16274e8440af6f73ed6f96ac1ff00761198badf2ee226b5ab5583a5d87a78d609ea78da5c5a24 + checksum: e28624ccb0ef1255a03fbbb4b5bc3e5cbcdc450d39e0739985ff679b124198f808c38c8c3e67859c6efc0e848196deeb8cfed028e12a821c511dfc1112a2d6e9 languageName: node linkType: hard @@ -988,12 +988,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:^20.8.9": - version: 20.8.9 - resolution: "@types/node@npm:20.8.9" +"@types/node@npm:^20.8.10": + version: 20.8.10 + resolution: "@types/node@npm:20.8.10" dependencies: undici-types: ~5.26.4 - checksum: 0c05f3502a9507ff27e91dd6fd574fa6f391b3fafedcfe8e0c8d33351fb22d02c0121f854e5b6b3ecb9a8a468407ddf6e7ac0029fb236d4c7e1361ffc758a01f + checksum: 7c61190e43e8074a1b571e52ff14c880bc67a0447f2fe5ed0e1a023eb8a23d5f815658edb98890f7578afe0f090433c4a635c7c87311762544e20dd78723e515 languageName: node linkType: hard @@ -3067,17 +3067,17 @@ __metadata: version: 0.0.0-use.local resolution: "nodejs-polars@workspace:." dependencies: - "@biomejs/biome": ^1.3.1 - "@napi-rs/cli": ^2.16.3 + "@biomejs/biome": ^1.3.3 + "@napi-rs/cli": ^2.16.4 "@types/chance": ^1.1.5 - "@types/jest": ^29.5.6 - "@types/node": ^20.8.9 + "@types/jest": ^29.5.7 + "@types/node": ^20.8.10 chance: ^1.1.11 jest: ^29.7.0 source-map-support: ^0.5.21 ts-jest: ^29.1.1 ts-node: ^10.9.1 - typedoc: ^0.25.2 + typedoc: ^0.25.3 typescript: 5.2.2 languageName: unknown linkType: soft @@ -3823,9 +3823,9 @@ __metadata: languageName: node linkType: hard -"typedoc@npm:^0.25.2": - version: 0.25.2 - resolution: "typedoc@npm:0.25.2" +"typedoc@npm:^0.25.3": + version: 0.25.3 + resolution: "typedoc@npm:0.25.3" dependencies: lunr: ^2.3.9 marked: ^4.3.0 @@ -3835,7 +3835,7 @@ __metadata: typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x bin: typedoc: bin/typedoc - checksum: 5b6e24bae7498bb542aaba495378ed5a3e13c76eb04a1ae95b506f76bda4d517847101fb05a7eab3f6b79357d1e2ac6f4747d39792395329b72e463f7effda65 + checksum: 060a8f798b32a0e70aa3b16e04d95b56fcfabf54f75fdff74fd9ddeed8860db3ba030d153f8b535b409a9d8825856252bc59f401619e5e3e2f71d3b9e0de606a languageName: node linkType: hard