Skip to content

Commit

Permalink
Upgrading to rs 0.41.3 (#238)
Browse files Browse the repository at this point in the history
Upgrading to rs-0.41.3
  • Loading branch information
Bidek56 authored Jul 9, 2024
1 parent 5e20abc commit 67285ed
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-05-14
toolchain: nightly-2024-06-23
components: rustfmt, clippy
- name: Install ghp-import
uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-05-14
toolchain: nightly-2024-06-23
components: rustfmt, clippy
- name: Check yarn version
run: yarn --version
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-05-14
toolchain: nightly-2024-06-23
components: rustfmt, clippy
- name: Bun version
uses: oven-sh/setup-bun@v1
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ crate-type = ["cdylib", "lib"]
[dependencies]
ahash = "0.8.11"
bincode = "1.3.3"
napi = { version = "2.16.6", default-features = false, features = [
napi = { version = "2.16.8", default-features = false, features = [
"napi8",
"serde-json",
] }
napi-derive = { version = "2.16.5", default-features = false }
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "7bc70141f4dad7863a2026849522551abb274f00", default-features = false }
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "7bc70141f4dad7863a2026849522551abb274f00", default-features = false }
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "7bc70141f4dad7863a2026849522551abb274f00", default-features = false }
napi-derive = { version = "2.16.8", default-features = false }
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "91a423fea2dc067837db65c3608e3cbc1112a6fc", default-features = false }
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "91a423fea2dc067837db65c3608e3cbc1112a6fc", default-features = false }
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "91a423fea2dc067837db65c3608e3cbc1112a6fc", default-features = false }
thiserror = "1"
smartstring = { version = "1" }
serde_json = { version = "1" }
either = "1.11.0"
either = "1.13.0"

[dependencies.polars]
features = [
Expand Down Expand Up @@ -161,7 +161,7 @@ features = [
"azure"
]
git = "https://github.com/pola-rs/polars.git"
rev = "7bc70141f4dad7863a2026849522551abb274f00"
rev = "91a423fea2dc067837db65c3608e3cbc1112a6fc"

[build-dependencies]
napi-build = "2.1.3"
Expand Down
19 changes: 9 additions & 10 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ describe("dataframe", () => {

let actual = df.pivot("b", {
index: "a",
columns: "a",
on: "a",
aggregateFunc: "first",
sortColumns: true,
});
Expand All @@ -1340,18 +1340,18 @@ describe("dataframe", () => {
});
actual = df.pivot(["a", "e"], {
index: "b",
columns: ["c"],
on: ["b"],
aggregateFunc: "first",
separator: "|",
maintainOrder: true,
});

expected = pl.DataFrame({
b: ["a", "b"],
"a|c|s": ["beep", null],
"a|c|f": [null, "bop"],
"e|c|s": ["x", null],
"e|c|f": [null, "y"],
"a|a": ["beep", null],
"a|b": [null, "bop"],
"e|a": ["x", null],
"e|b": [null, "y"],
});
expect(actual).toFrameEqual(expected, true);
});
Expand Down Expand Up @@ -1529,7 +1529,7 @@ describe("join", () => {
});
expect(actual).toFrameEqual(expected);
});
test("how:outer", () => {
test("how:full", () => {
const df = pl.DataFrame({
foo: [1, 2, 3],
bar: [6.0, 7.0, 8.0],
Expand All @@ -1542,7 +1542,7 @@ describe("join", () => {
});
const actual = df.join(otherDF, {
on: "ham",
how: "outer",
how: "full",
});
const expected = pl.DataFrame({
foo: [1, 2, 3, null],
Expand Down Expand Up @@ -2523,7 +2523,7 @@ describe("additional", () => {
.sort("date");

let actual = df
.upsample("date", "1mo", "0ns", "groups", true)
.upsample("date", "1mo", "groups", true)
.select(pl.col("*").forwardFill());

let expected = pl
Expand All @@ -2548,7 +2548,6 @@ describe("additional", () => {
.upsample({
timeColumn: "date",
every: "1mo",
offset: "0ns",
by: "groups",
maintainOrder: true,
})
Expand Down
13 changes: 8 additions & 5 deletions __tests__/expr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ describe("expr", () => {
const actual = df.select(col("a").tail(3).as("tail3"));
expect(actual).toFrameEqual(expected);
});
test.skip("take", () => {
test("take", () => {
const df = pl.DataFrame({ a: [1, 2, 2, 3, 3, 8, null, 1] });
const expected = pl.DataFrame({
"take:array": [1, 2, 3, 8],
Expand Down Expand Up @@ -1187,7 +1187,10 @@ describe("expr.str", () => {
});
expect(actual).toFrameEqual(expected);
actual = df.withColumns(
pl.col("a").replace([2, 3], [100, 200], -1, pl.Float64).alias("replaced"),
pl
.col("a")
.replaceStrict([2, 3], [100, 200], -1, pl.Float64)
.alias("replaced"),
);
expected = pl.DataFrame({
a: [1, 2, 2, 3],
Expand All @@ -1196,7 +1199,7 @@ describe("expr.str", () => {
});
expect(actual).toFrameEqual(expected);
actual = df.withColumns(
pl.col("b").replace("a", "c", "e", pl.Utf8).alias("replaced"),
pl.col("b").replaceStrict("a", "c", "e", pl.Utf8).alias("replaced"),
);
expected = pl.DataFrame({
a: [1, 2, 2, 3],
Expand All @@ -1207,7 +1210,7 @@ describe("expr.str", () => {
actual = df.withColumns(
pl
.col("b")
.replace(["a", "b"], ["c", "d"], "e", pl.Utf8)
.replaceStrict(["a", "b"], ["c", "d"], "e", pl.Utf8)
.alias("replaced"),
);
expected = pl.DataFrame({
Expand All @@ -1220,7 +1223,7 @@ describe("expr.str", () => {
actual = df.withColumns(
pl
.col("a")
.replace({ old: mapping, default_: -1, returnDtype: pl.Int64 })
.replaceStrict({ old: mapping, default_: -1, returnDtype: pl.Int64 })
.alias("replaced"),
);
expected = pl.DataFrame({
Expand Down
4 changes: 2 additions & 2 deletions __tests__/lazyframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ describe("lazyframe", () => {
});
expect(actual).toFrameEqualIgnoringOrder(expected);
});
test("how:outer", () => {
test("how:full", () => {
const df = pl.DataFrame({
foo: [1, 2, 3],
bar: [6.0, 7.0, 8.0],
Expand All @@ -597,7 +597,7 @@ describe("lazyframe", () => {
.lazy()
.join(otherDF, {
on: "ham",
how: "outer",
how: "full",
})
.collectSync();
const expected = pl.DataFrame({
Expand Down
2 changes: 1 addition & 1 deletion __tests__/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe("series", () => {
expect(actual).toFrameEqual(expected);
});
it("series:valueCounts", () => {
const actual = pl.Series("a", [1, 2, 2, 3]).valueCounts();
const actual = pl.Series("a", [1, 2, 2, 3]).valueCounts(true);
const expected = pl.DataFrame({
a: [2, 1, 3],
count: [2, 1, 1],
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"build:ts": " rm -rf bin; tsc -p tsconfig.build.json",
"cp:bin": "cp ./polars/*.node bin/",
"format:rs": "cargo fmt",
"lint:ts:fix": "biome check --apply-unsafe {polars,__tests__} && biome format --write {polars,__tests__}",
"lint:ts:fix": "biome check --apply-unsafe {polars,__tests__} && biome format --write {polars,__tests__}",
"lint:ts": "biome check {polars,__tests__} && biome format {polars,__tests__}",
"lint": "yarn lint:ts && yarn format:rs",
"prepublishOnly": "napi prepublish -t npm",
Expand All @@ -55,17 +55,17 @@
},
"devDependencies": {
"@biomejs/biome": "=1.7.3",
"@napi-rs/cli": "^2.18.3",
"@napi-rs/cli": "^2.18.4",
"@types/chance": "^1.1.6",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@types/node": "^20.14.9",
"chance": "^1.1.11",
"jest": "^29.7.0",
"source-map-support": "^0.5.21",
"ts-jest": "^29.1.3",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typescript": "5.4.5"
"typedoc": "^0.26.3",
"typescript": "5.5.3"
},
"packageManager": "[email protected]",
"workspaces": [
Expand Down
42 changes: 23 additions & 19 deletions polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -913,12 +913,21 @@ export interface DataFrame
* ```
*/
median(): DataFrame;
/**
* Unpivot a DataFrame from wide to long format.
* @deprecated *since 0.13.0* use {@link unpivot}
*/
melt(idVars: ColumnSelection, valueVars: ColumnSelection): DataFrame;
/**
* Unpivot DataFrame to long format.
* ___
*
* @param idVars - Columns to use as identifier variables.
* @param valueVars - Values to use as value variables.
* @param variableName - Name to give to the `variable` column. Defaults to "variable"
* @param valueName - Name to give to the `value` column. Defaults to "value"
* @param streamable - Allow this node to run in the streaming engine.
If this runs in streaming, the output of the unpivot operation will not have a stable ordering.
* @example
* ```
* > const df1 = pl.DataFrame({
Expand All @@ -927,7 +936,7 @@ export interface DataFrame
* ... 'asset_key_2': ['456'],
* ... 'asset_key_3': ['abc'],
* ... });
* > df1.melt('id', ['asset_key_1', 'asset_key_2', 'asset_key_3']);
* > df1.unpivot('id', ['asset_key_1', 'asset_key_2', 'asset_key_3']);
* shape: (3, 3)
* ┌─────┬─────────────┬───────┐
* │ id ┆ variable ┆ value │
Expand All @@ -942,7 +951,7 @@ export interface DataFrame
* └─────┴─────────────┴───────┘
* ```
*/
melt(idVars: ColumnSelection, valueVars: ColumnSelection): DataFrame;
unpivot(idVars: ColumnSelection, valueVars: ColumnSelection): DataFrame;
/**
* Aggregate the columns of this DataFrame to their minimum value.
* ___
Expand Down Expand Up @@ -1051,7 +1060,7 @@ export interface DataFrame
values: string | string[],
options: {
index: string | string[];
columns: string | string[];
on: string | string[];
aggregateFunc?:
| "sum"
| "max"
Expand All @@ -1070,7 +1079,7 @@ export interface DataFrame
pivot(options: {
values: string | string[];
index: string | string[];
columns: string | string[];
on: string | string[];
aggregateFunc?:
| "sum"
| "max"
Expand Down Expand Up @@ -1750,7 +1759,6 @@ export interface DataFrame
@param timeColumn Time column will be used to determine a date range.
Note that this column has to be sorted for the output to make sense.
@param every Interval will start 'every' duration.
@param offset Change the start of the date range by this offset.
@param by First group by these columns and then upsample for every group.
@param maintainOrder Keep the ordering predictable. This is slower.
Expand All @@ -1776,7 +1784,7 @@ export interface DataFrame
.withColumn(pl.col("date").cast(pl.Date).alias("date"))
.sort("date");
>>> df.upsample({timeColumn: "date", every: "1mo", offset: "0ns", by: "groups", maintainOrder: true})
>>> df.upsample({timeColumn: "date", every: "1mo", by: "groups", maintainOrder: true})
.select(pl.col("*").forwardFill());
shape: (7, 3)
┌────────────┬────────┬────────┐
Expand All @@ -1796,14 +1804,12 @@ shape: (7, 3)
upsample(
timeColumn: string,
every: string,
offset?: string,
by?: string | string[],
maintainOrder?: boolean,
): DataFrame;
upsample(opts: {
timeColumn: string;
every: string;
offset?: string;
by?: string | string[];
maintainOrder?: boolean;
}): DataFrame;
Expand Down Expand Up @@ -2070,14 +2076,13 @@ export const _DataFrame = (_df: any): DataFrame => {
by,
);
},
upsample(opts, every?, offset?, by?, maintainOrder?) {
upsample(opts, every?, by?, maintainOrder?) {
let timeColumn;
if (typeof opts === "string") {
timeColumn = opts;
} else {
timeColumn = opts.timeColumn;
by = opts.by;
offset = opts.offset;
every = opts.every;
maintainOrder = opts.maintainOrder ?? false;
}
Expand All @@ -2088,11 +2093,7 @@ export const _DataFrame = (_df: any): DataFrame => {
by = by ?? [];
}

offset = offset ?? "0ns";

return _DataFrame(
_df.upsample(by, timeColumn, every, offset, maintainOrder),
);
return _DataFrame(_df.upsample(by, timeColumn, every, maintainOrder));
},
hashRows(obj: any = 0n, k1 = 1n, k2 = 2n, k3 = 3n) {
if (typeof obj === "number" || typeof obj === "bigint") {
Expand Down Expand Up @@ -2174,7 +2175,10 @@ export const _DataFrame = (_df: any): DataFrame => {
return this.lazy().median().collectSync();
},
melt(ids, values) {
return wrap("melt", columnOrColumns(ids), columnOrColumns(values));
return wrap("unpivot", columnOrColumns(ids), columnOrColumns(values));
},
unpivot(ids, values) {
return wrap("unpivot", columnOrColumns(ids), columnOrColumns(values));
},
min(axis = 0) {
if (axis === 1) {
Expand All @@ -2198,7 +2202,7 @@ export const _DataFrame = (_df: any): DataFrame => {
let {
values: values_,
index,
columns,
on,
maintainOrder = true,
sortColumns = false,
aggregateFunc = "first",
Expand All @@ -2207,7 +2211,7 @@ export const _DataFrame = (_df: any): DataFrame => {
values = values_ ?? values;
values = typeof values === "string" ? [values] : values;
index = typeof index === "string" ? [index] : index;
columns = typeof columns === "string" ? [columns] : columns;
on = typeof on === "string" ? [on] : on;

let fn: Expr;
if (Expr.isExpr(aggregateFunc)) {
Expand All @@ -2234,7 +2238,7 @@ export const _DataFrame = (_df: any): DataFrame => {
_df.pivotExpr(
values,
index,
columns,
on,
fn,
maintainOrder,
sortColumns,
Expand Down
Loading

0 comments on commit 67285ed

Please sign in to comment.