Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rs 0.31.1 upgrade #85

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: actions-rs/toolchain@v1
with:
toolchain: nightly-2022-11-24
toolchain: nightly-2023-06-23
override: true
components: rustfmt, clippy
- name: Install ghp-import
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2022-11-24
toolchain: nightly-2023-06-23
override: true
components: rustfmt, clippy
- run: yarn --version
Expand Down
16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ ahash = "0.8.3"
bincode = "1.3.3"
napi = {version = "2.13.2", 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 = "ee2366b68f35c4b69dfe34cbf1eae107d4ebe97b", default-features = false}
polars-ops = {git = "https://github.com/pola-rs/polars.git", rev = "ee2366b68f35c4b69dfe34cbf1eae107d4ebe97b", default-features = false}
polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "ee2366b68f35c4b69dfe34cbf1eae107d4ebe97b", default-features = false}
polars-plan = {git = "https://github.com/pola-rs/polars.git", rev = "ee2366b68f35c4b69dfe34cbf1eae107d4ebe97b", default-features = false}
polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "672922491bac1f144747d39b864106d90010fd1e", default-features = false}
polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "672922491bac1f144747d39b864106d90010fd1e", default-features = false}
polars-lazy = {git = "https://github.com/pola-rs/polars.git", rev = "672922491bac1f144747d39b864106d90010fd1e", default-features = false}
polars-ops = {git = "https://github.com/pola-rs/polars.git", rev = "672922491bac1f144747d39b864106d90010fd1e", default-features = false}
thiserror = "1.0.40"
smartstring = { version = "1" }
serde_json = {version = "1"}
Expand All @@ -42,7 +42,6 @@ features = [
"performant",
"dtype-full",
"rows",
"private",
"round_series",
"is_unique",
"is_in",
Expand All @@ -67,7 +66,6 @@ features = [
"diff",
"pct_change",
"moment",
"arange",
"true_div",
"dtype-categorical",
"string_justify",
Expand Down Expand Up @@ -95,7 +93,7 @@ features = [
"timezones",
]
git = "https://github.com/pola-rs/polars.git"
rev = "ee2366b68f35c4b69dfe34cbf1eae107d4ebe97b"
rev = "672922491bac1f144747d39b864106d90010fd1e"

[build-dependencies]
napi-build = "2.0.1"
Expand All @@ -104,4 +102,8 @@ napi-build = "2.0.1"
codegen-units = 1
lto = "fat"

[features]
default = ["range"]
range = ["polars-lazy/range"]

[workspace]
17 changes: 10 additions & 7 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ describe("dataframe", () => {
foo: [1, 2, 3, 1],
bar: [6, 7, 8, 1],
})
.sort({ by: "bar", reverse: true });
.sort({ by: "bar", descending: true });
const expected = pl.DataFrame({
foo: [3, 2, 1, 1],
bar: [8, 7, 6, 1],
Expand Down Expand Up @@ -1414,7 +1414,7 @@ describe("join", () => {
bar: [6, 7, 8],
ham: ["a", "b", "c"],
apple: ["x", "y", null],
fooright: [1, 10, null],
foo_right: [1, 10, null],
});
expect(actual).toFrameEqual(expected);
});
Expand All @@ -1438,7 +1438,7 @@ describe("join", () => {
bar: [6, 7, 8, null],
ham: ["a", "b", "c", "d"],
apple: ["x", null, null, "y"],
fooright: [1, null, null, 10],
foo_right: [1, null, null, 10],
});
expect(actual).toFrameEqual(expected);
});
Expand All @@ -1456,14 +1456,14 @@ describe("join", () => {
const actual = df.join(otherDF, {
on: "ham",
how: "left",
suffix: "_other",
suffix: "_right",
});
const expected = pl.DataFrame({
foo: [1, 2, 3],
bar: [6, 7, 8],
ham: ["a", "b", "c"],
apple: ["x", "y", null],
foo_other: [1, 10, null],
foo_right: [1, 10, null],
});
expect(actual).toFrameEqual(expected);
});
Expand Down Expand Up @@ -2209,7 +2209,9 @@ describe("additional", () => {
label: ["a", "a", "b", "b"],
value: [1, 2, 3, 4],
});
const dfs = df.partitionBy(["label"], true).map((df) => df.toObject());
const dfs = df
.partitionBy(["label"], true, true)
.map((df) => df.toObject());
const expected = [
{
label: ["a", "a"],
Expand All @@ -2228,7 +2230,8 @@ describe("additional", () => {
label: ["a", "a", "b", "b"],
value: [1, 2, 3, 4],
});
const dfs = df.partitionBy(["label"], true, (df) => df.toObject());
const dfs = df.partitionBy(["label"], true, true, (df) => df.toObject());

const expected = [
{
label: ["a", "a"],
Expand Down
4 changes: 2 additions & 2 deletions __tests__/expr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ describe("expr.str", () => {

const datetimeSeries = df
.getColumn("timestamp")
.str.strptime(pl.Datetime("ms"), "%FT%T%.3f%:z")
.str.strptime(pl.Datetime("ms"), "%FT%T%.3f")
.rename("datetime");
const dateSeries = df
.getColumn("timestamp")
Expand All @@ -1116,7 +1116,7 @@ describe("expr.str", () => {

const actual = df.select(
col("timestamp")
.str.strptime(pl.Datetime("ms"), "%FT%T%.3f%:z")
.str.strptime(pl.Datetime("ms"), "%FT%T%.3f")
.as("datetime"),
col("timestamp").str.strptime(pl.Date, "%FT%T%.3f%:z").as("date"),
);
Expand Down
12 changes: 6 additions & 6 deletions __tests__/lazy_functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,31 @@ describe("lazy functions", () => {
expect(actual).toFrameEqual(expected);
});
});
test("arange:positional", () => {
test("intRange:positional", () => {
const df = pl.DataFrame({
foo: [1, 1, 1],
});
const expected = pl.DataFrame({ foo: [1, 1] });
const actual = df.filter(pl.col("foo").gtEq(pl.arange(0, 3)));
const actual = df.filter(pl.col("foo").gtEq(pl.intRange(0, 3)));
expect(actual).toFrameEqual(expected);
});
test("arange:named", () => {
test("intRange:named", () => {
const df = pl.DataFrame({
foo: [1, 1, 1],
});
const expected = pl.DataFrame({ foo: [1, 1] });
const actual = df.filter(
pl.col("foo").gtEq(pl.arange({ low: 0, high: 3 })),
pl.col("foo").gtEq(pl.intRange({ low: 0, high: 3 })),
);
expect(actual).toFrameEqual(expected);
});
test("arange:eager", () => {
test("intRange:eager", () => {
const df = pl.DataFrame({
foo: [1, 1, 1],
});
const expected = pl.DataFrame({ foo: [1, 1] });
const actual = df.filter(
pl.col("foo").gtEq(pl.arange({ low: 0, high: 3, eager: true })),
pl.col("foo").gtEq(pl.intRange({ low: 0, high: 3, eager: true })),
);
expect(actual).toFrameEqual(expected);
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lazyframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ describe("lazyframe", () => {
bar: [6, 7, 8, 1],
})
.lazy()
.sort({ by: "bar", reverse: true })
.sort({ by: "bar", descending: true })
.collectSync();
const expected = pl.DataFrame({
foo: [3, 2, 1, 1],
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
"precommit": "yarn lint && yarn test"
},
"devDependencies": {
"@napi-rs/cli": "^2.16.1",
"@napi-rs/cli": "^2.16.2",
"@types/chance": "^1.1.3",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.2",
"chance": "^1.1.11",
"jest": "^29.5.0",
"jest": "^29.6.1",
"rome": "^12.1.3",
"source-map-support": "^0.5.21",
"ts-jest": "^29.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typedoc": "^0.24.8",
"typescript": "5.1.3"
"typescript": "5.1.6"
},
"packageManager": "yarn@3.3.1",
"packageManager": "yarn@3.6.1",
"workspaces": [
"benches"
]
Expand Down
38 changes: 28 additions & 10 deletions polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,15 @@ export interface DataFrame
* ```
*/
nullCount(): DataFrame;
partitionBy(cols: string | string[], stable?: boolean): DataFrame[];
partitionBy(
cols: string | string[],
stable?: boolean,
includeKey?: boolean,
): DataFrame[];
partitionBy<T>(
cols: string | string[],
stable: boolean,
includeKey: boolean,
mapFn: (df: DataFrame) => T,
): T[];
/**
Expand Down Expand Up @@ -1310,8 +1315,20 @@ export interface DataFrame
* @param by - By which columns to sort. Only accepts string.
* @param reverse - Reverse/descending sort.
*/
sort(by: ColumnsOrExpr, reverse?: boolean): DataFrame;
sort({ by, reverse }: { by: ColumnsOrExpr; reverse?: boolean }): DataFrame;
sort(
by: ColumnsOrExpr,
descending?: boolean,
maintain_order?: boolean,
): DataFrame;
sort({
by,
descending,
maintain_order,
}: {
by: ColumnsOrExpr;
descending?: boolean;
maintain_order?: boolean;
}): DataFrame;
/**
* Aggregate the columns of this DataFrame to their standard deviation value.
* ___
Expand Down Expand Up @@ -1985,10 +2002,11 @@ export const _DataFrame = (_df: any): DataFrame => {
nullCount() {
return wrap("nullCount");
},
partitionBy(by, strict = false, mapFn = (df) => df) {
partitionBy(by, strict = false, includeKey?: boolean, mapFn = (df) => df) {
by = Array.isArray(by) ? by : [by];

return _df.partitionBy(by, strict).map((d) => mapFn(_DataFrame(d)));
return _df
.partitionBy(by, strict, includeKey)
.map((d) => mapFn(_DataFrame(d)));
},
pivot(values, options?) {
let {
Expand Down Expand Up @@ -2105,18 +2123,18 @@ export const _DataFrame = (_df: any): DataFrame => {

return wrap("slice", opts.offset, opts.length);
},
sort(arg, reverse = false) {
sort(arg, descending = false, maintain_order = false) {
if (arg?.by !== undefined) {
return this.sort(arg.by, arg.reverse);
return this.sort(arg.by, arg.descending);
}
if (Array.isArray(arg) || Expr.isExpr(arg)) {
return _DataFrame(_df)
.lazy()
.sort(arg, reverse)
.sort(arg, descending, maintain_order)
.collectSync({ noOptimization: true, stringCache: false });
}

return wrap("sort", arg, reverse, true, false);
return wrap("sort", arg, descending, maintain_order, true, false);
},
std() {
return wrap("std");
Expand Down
2 changes: 1 addition & 1 deletion polars/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export namespace pl {
export import col = lazy.col;
export import cols = lazy.cols;
export import lit = lazy.lit;
export import arange = lazy.arange;
export import intRange = lazy.intRange;
export import argSortBy = lazy.argSortBy;
export import avg = lazy.avg;
export import concatList = lazy.concatList;
Expand Down
19 changes: 12 additions & 7 deletions polars/lazy/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,15 @@ export interface LazyDataFrame extends Serialize, GroupByOps<LazyGroupBy> {
/**
* @see {@link DataFrame.sort}
*/
sort(by: ColumnsOrExpr, reverse?: ValueOrArray<boolean>): LazyDataFrame;
sort(
by: ColumnsOrExpr,
descending?: ValueOrArray<boolean>,
maintain_order?: boolean,
): LazyDataFrame;
sort(opts: {
by: ColumnsOrExpr;
reverse?: ValueOrArray<boolean>;
descending?: ValueOrArray<boolean>;
maintain_order?: boolean;
}): LazyDataFrame;
/**
* @see {@link DataFrame.std}
Expand Down Expand Up @@ -858,17 +863,17 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => {

return _LazyDataFrame(_ldf.slice(opt, len));
},
sort(arg, reverse = false) {
sort(arg, descending = false, maintain_order = false) {
if (arg?.by !== undefined) {
return this.sort(arg.by, arg.reverse);
return this.sort(arg.by, arg.descending, arg.maintain_order);
}
if (typeof arg === "string") {
return wrap("sort", arg, reverse, true, false);
return wrap("sort", arg, descending, maintain_order, true, false);
} else {
reverse = [reverse].flat(3) as any;
descending = [descending].flat(3) as any;
const by = selectionToExprList(arg, false);

return wrap("sortByExprs", by, reverse, true);
return wrap("sortByExprs", by, descending, maintain_order, true);
}
},
std() {
Expand Down
Loading