Skip to content

Commit bf78f49

Browse files
bump polars version (#177)
* bump polars version * lint
1 parent ce3b2df commit bf78f49

17 files changed

+178
-148
lines changed

Cargo.toml

+14-12
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ crate-type = ["cdylib", "lib"]
1515
[dependencies]
1616
ahash = "0.8.7"
1717
bincode = "1.3.3"
18-
napi = {version = "2.14.2", default-features = false, features = ["napi8", "serde-json"]}
19-
napi-derive = {version = "2.14.6", default-features = false}
20-
polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5", default-features = false}
21-
polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5", default-features = false}
22-
polars-lazy = {git = "https://github.com/pola-rs/polars.git", rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5", default-features = false}
18+
napi = { version = "2.14.2", default-features = false, features = [
19+
"napi8",
20+
"serde-json",
21+
] }
22+
napi-derive = { version = "2.14.6", default-features = false }
23+
polars-core = { git = "https://github.com/pola-rs/polars.git", rev = "3cf4897e679b056d17a235d48867035265d43cdc", default-features = false }
24+
polars-io = { git = "https://github.com/pola-rs/polars.git", rev = "3cf4897e679b056d17a235d48867035265d43cdc", default-features = false }
25+
polars-lazy = { git = "https://github.com/pola-rs/polars.git", rev = "3cf4897e679b056d17a235d48867035265d43cdc", default-features = false }
2326
thiserror = "1"
24-
smartstring = {version = "1"}
25-
serde_json = {version = "1"}
27+
smartstring = { version = "1" }
28+
serde_json = { version = "1" }
2629
either = "1.9"
2730

2831
[dependencies.polars]
@@ -54,7 +57,6 @@ features = [
5457
"reinterpret",
5558
"mode",
5659
"extract_jsonpath",
57-
"lazy_regex",
5860
"cum_agg",
5961
"rolling_window",
6062
"repeat_by",
@@ -66,7 +68,6 @@ features = [
6668
"pct_change",
6769
"moment",
6870
"diagonal_concat",
69-
"horizontal_concat",
7071
"abs",
7172
"dot_diagram",
7273
"dataframe_arithmetic",
@@ -89,10 +90,11 @@ features = [
8990
"timezones",
9091
"peaks",
9192
"string_pad",
92-
"cov"
93+
"cov",
94+
"group_by_list",
9395
]
9496
git = "https://github.com/pola-rs/polars.git"
95-
rev = "fa59ffc1685043b44476dcb2a3f3804460ead5c5"
97+
rev = "3cf4897e679b056d17a235d48867035265d43cdc"
9698

9799
[build-dependencies]
98100
napi-build = "2.1.0"
@@ -103,4 +105,4 @@ lto = "fat"
103105

104106
[features]
105107
default = ["range"]
106-
range = ["polars-lazy/range"]
108+
range = ["polars-lazy/range"]

__tests__/dataframe.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1582,13 +1582,13 @@ describe("io", () => {
15821582
{
15831583
name: "foo",
15841584
datatype: "Float64",
1585-
bit_settings: "SORTED_ASC",
1585+
bit_settings: "",
15861586
values: [1.0],
15871587
},
15881588
{
15891589
name: "bar",
15901590
datatype: "String",
1591-
bit_settings: "SORTED_ASC",
1591+
bit_settings: "",
15921592
values: ["a"],
15931593
},
15941594
],

__tests__/expr.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ describe("expr", () => {
104104
});
105105
test.each`
106106
args | cumCount
107-
${undefined} | ${[0, 1, 2]}
108-
${true} | ${[2, 1, 0]}
109-
${{ reverse: true }} | ${[2, 1, 0]}
107+
${undefined} | ${[1, 2, 3]}
108+
${true} | ${[3, 2, 1]}
109+
${{ reverse: true }} | ${[3, 2, 1]}
110110
`("$# cumCount", ({ args, cumCount }) => {
111111
const df = pl.DataFrame({ a: [1, 2, 3] });
112112
const expected = pl.DataFrame({ a: cumCount });
@@ -331,8 +331,8 @@ describe("expr", () => {
331331
});
332332
test.each`
333333
args | hashValue
334-
${[0]} | ${6340063056640878722n}
335-
${[{ k0: 1n, k1: 1 }]} | ${9788354747012366704n}
334+
${[0]} | ${7355865757046787768n}
335+
${[{ k0: 1n, k1: 1 }]} | ${2179653058507248884n}
336336
`("$# hash", ({ args, hashValue }) => {
337337
const df = pl.DataFrame({ a: [1] });
338338
const expected = pl.DataFrame({ hash: [hashValue] });

__tests__/series.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ describe("series", () => {
472472
${"getIndex"} | ${pl.Series(["a", "b", "c"]).getIndex(0)} | ${"a"}
473473
${"hasValidity"} | ${pl.Series([1, null, 2]).hasValidity()} | ${true}
474474
${"hasValidity"} | ${pl.Series([1, 1, 2]).hasValidity()} | ${false}
475-
${"hash"} | ${pl.Series([1]).hash()} | ${pl.Series([6340063056640878722n])}
475+
${"hash"} | ${pl.Series([1]).hash()} | ${pl.Series([7355865757046787768n])}
476476
${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head()} | ${pl.Series([1, 2, 3, 4, 5])}
477477
${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head(2)} | ${pl.Series([1, 2])}
478478
${"interpolate"} | ${pl.Series([1, 2, null, null, 5]).interpolate()} | ${pl.Series([1, 2, 3, 4, 5])}
@@ -520,8 +520,8 @@ describe("series", () => {
520520
${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(-3, 3)} | ${pl.Series([3, 3, 0])}
521521
${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(1, 3)} | ${pl.Series([2, 3, 3])}
522522
${"sort"} | ${pl.Series([4, 2, 5, 1, 2, 3, 3, 0]).sort()} | ${pl.Series([0, 1, 2, 2, 3, 3, 4, 5])}
523-
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ reverse: true })} | ${pl.Series([5, 4, 2, 0])}
524-
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ reverse: false })} | ${pl.Series([0, 2, 4, 5])}
523+
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ descending: true })} | ${pl.Series([5, 4, 2, 0])}
524+
${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ descending: false })} | ${pl.Series([0, 2, 4, 5])}
525525
${"sum"} | ${pl.Series([1, 2, 2, 1]).sum()} | ${6}
526526
${"tail"} | ${pl.Series([1, 2, 2, 1]).tail(2)} | ${pl.Series([2, 1])}
527527
${"gatherEvery"} | ${pl.Series([1, 3, 2, 9, 1]).gatherEvery(2)} | ${pl.Series([1, 2, 1])}
@@ -535,7 +535,7 @@ describe("series", () => {
535535
.gather([2])} | ${pl.Series([[6, 7, 8]])}
536536
${"toArray"} | ${pl.Series([1, 2, 3]).toArray()} | ${[1, 2, 3]}
537537
${"unique"} | ${pl.Series([1, 2, 3, 3]).unique().sort()} | ${pl.Series([1, 2, 3])}
538-
${"cumCount"} | ${pl.Series([1, 2, 3, 3]).cumCount()} | ${pl.Series([0, 1, 2, 3])}
538+
${"cumCount"} | ${pl.Series([1, 2, 3, 3]).cumCount()} | ${pl.Series([1, 2, 3, 4])}
539539
${"shiftAndFill"} | ${pl.Series("foo", [1, 2, 3]).shiftAndFill(1, 99)} | ${pl.Series("foo", [99, 1, 2])}
540540
${"bitand"} | ${pl
541541
.Series("bit", [1, 2, 3], pl.Int32)

polars/lazy/expr/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ export type { ExprStruct as StructNamespace } from "./struct";
99

1010
import { DataType } from "../../datatypes";
1111
import pli from "../../internals/polars_internal";
12-
import { ExprOrString, selectionToExprList, INSPECT_SYMBOL } from "../../utils";
12+
import {
13+
ExprOrString,
14+
selectionToExprList,
15+
INSPECT_SYMBOL,
16+
regexToString,
17+
} from "../../utils";
1318
import { Series } from "../../series";
1419
import {
1520
Arithmetic,
@@ -23,6 +28,7 @@ import {
2328
EwmOps,
2429
} from "../../shared_traits";
2530
import { InterpolationMethod, FillNullStrategy, RankMethod } from "../../types";
31+
import { isRegExp } from "util/types";
2632
/**
2733
* Expressions that can be used in various contexts.
2834
*/
@@ -1246,6 +1252,9 @@ export const Expr: ExprConstructor = Object.assign(_Expr, {
12461252
});
12471253

12481254
export const exprToLitOrExpr = (expr: any, stringToLit = true): Expr => {
1255+
if (isRegExp(expr)) {
1256+
return _Expr(pli.lit(regexToString(expr)));
1257+
}
12491258
if (typeof expr === "string" && !stringToLit) {
12501259
return _Expr(pli.col(expr));
12511260
}

polars/lazy/expr/list.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,19 @@ export const ExprListFunctions = (_expr: any): ExprList => {
6868
first() {
6969
return this.get(0);
7070
},
71-
join(separator = ",") {
72-
return wrap("listJoin", exprToLitOrExpr(separator)._expr);
71+
join(options?) {
72+
if (typeof options === "string") {
73+
options = { separator: options };
74+
}
75+
options = options ?? {};
76+
let separator = options?.separator ?? ",";
77+
const ignoreNulls = options?.ignoreNulls ?? false;
78+
79+
if (!Expr.isExpr(separator)) {
80+
separator = pli.lit(separator);
81+
}
82+
83+
return wrap("listJoin", separator, ignoreNulls);
7384
},
7485
last() {
7586
return this.get(-1);

polars/lazy/expr/string.ts

+19-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { StringFunctions } from "../../shared_traits";
22
import { DataType } from "../../datatypes";
33
import { regexToString } from "../../utils";
44
import { Expr, _Expr, exprToLitOrExpr } from "../expr";
5+
import { lit } from "../functions";
56

67
/**
78
* namespace containing expr string functions
@@ -106,7 +107,7 @@ export interface StringNamespace extends StringFunctions<Expr> {
106107
* └─────────┘
107108
* ```
108109
*/
109-
extract(pat: string | RegExp, groupIndex: number): Expr;
110+
extract(pat: any, groupIndex: number): Expr;
110111
/**
111112
* Parse string values as JSON.
112113
* Throw errors if encounter invalid JSON strings.
@@ -267,7 +268,7 @@ export interface StringNamespace extends StringFunctions<Expr> {
267268
* └──────────┘
268269
* ```
269270
*/
270-
zFill(length: number): Expr;
271+
zFill(length: number | Expr): Expr;
271272
/**
272273
* Add a trailing fillChar to a string until string length is reached.
273274
* If string is longer or equal to given length no modifications will be done
@@ -306,7 +307,7 @@ export interface StringNamespace extends StringFunctions<Expr> {
306307
* @param start - Start of the slice (negative indexing may be used).
307308
* @param length - Optional length of the slice.
308309
*/
309-
slice(start: number, length?: number): Expr;
310+
slice(start: number | Expr, length?: number | Expr): Expr;
310311
/**
311312
* Split a string into substrings using the specified separator and return them as a Series.
312313
* @param separator — A string that identifies character or characters to use in separating the string.
@@ -364,8 +365,8 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => {
364365
throw new RangeError("supported encodings are 'hex' and 'base64'");
365366
}
366367
},
367-
extract(pat: string | RegExp, groupIndex: number) {
368-
return wrap("strExtract", regexToString(pat), groupIndex);
368+
extract(pat: any, groupIndex: number) {
369+
return wrap("strExtract", exprToLitOrExpr(pat, true)._expr, groupIndex);
369370
},
370371
jsonExtract(dtype?: DataType, inferSchemaLength?: number) {
371372
return wrap("strJsonDecode", dtype, inferSchemaLength);
@@ -394,13 +395,23 @@ export const ExprStringFunctions = (_expr: any): StringNamespace => {
394395
padStart(length: number, fillChar: string) {
395396
return wrap("strPadStart", length, fillChar);
396397
},
397-
zFill(length: number) {
398-
return wrap("strZFill", length);
398+
zFill(length: number | Expr) {
399+
if (!Expr.isExpr(length)) {
400+
length = lit(length)._expr;
401+
}
402+
return wrap("zfill", length);
399403
},
400404
padEnd(length: number, fillChar: string) {
401405
return wrap("strPadEnd", length, fillChar);
402406
},
403-
slice(start: number, length?: number) {
407+
slice(start, length?) {
408+
if (!Expr.isExpr(start)) {
409+
start = lit(start)._expr;
410+
}
411+
if (!Expr.isExpr(length)) {
412+
length = lit(length)._expr;
413+
}
414+
404415
return wrap("strSlice", start, length);
405416
},
406417
split(by: string, options?) {

polars/lazy/functions.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,23 @@ export function concatList(...exprs): Expr {
305305
}
306306

307307
/** Concat Utf8 Series in linear time. Non utf8 columns are cast to utf8. */
308-
export function concatString(opts: { exprs: ExprOrString[]; sep: string });
309-
export function concatString(exprs: ExprOrString[], sep?: string);
310-
export function concatString(opts, sep = ",") {
308+
export function concatString(opts: {
309+
exprs: ExprOrString[];
310+
sep: string;
311+
ignoreNulls?: boolean;
312+
});
313+
export function concatString(
314+
exprs: ExprOrString[],
315+
sep?: string,
316+
ignoreNulls?: boolean,
317+
);
318+
export function concatString(opts, sep = ",", ignoreNulls = true) {
311319
if (opts?.exprs) {
312-
return concatString(opts.exprs, opts.sep);
320+
return concatString(opts.exprs, opts.sep, opts.ignoreNulls);
313321
}
314322
const items = selectionToExprList(opts as any, false);
315323

316-
return (Expr as any)(pli.concatStr(items, sep));
324+
return (Expr as any)(pli.concatStr(items, sep, ignoreNulls));
317325
}
318326

319327
/** Count the number of values in this column. */

polars/series/index.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ export interface Series
865865
slice(start: number, length?: number): Series;
866866
/**
867867
* __Sort this Series.__
868-
* @param reverse - Reverse sort
868+
* @param descending - Sort in descending order.
869+
* @param nullsLast - Place nulls at the end.
869870
* @example
870871
* ```
871872
* s = pl.Series("a", [1, 3, 4, 2])
@@ -878,7 +879,7 @@ export interface Series
878879
* 3
879880
* 4
880881
* ]
881-
* s.sort(true)
882+
* s.sort({descending: true})
882883
* shape: (4,)
883884
* Series: 'a' [i64]
884885
* [
@@ -890,8 +891,7 @@ export interface Series
890891
* ```
891892
*/
892893
sort(): Series;
893-
sort(reverse?: boolean): Series;
894-
sort(options: { reverse: boolean }): Series;
894+
sort(options: { descending?: boolean; nullsLast?: boolean }): Series;
895895
/**
896896
* Reduce this Series to the sum value.
897897
* @example
@@ -1684,12 +1684,10 @@ export function _Series(_s: any): Series {
16841684

16851685
return wrap("slice", offset.offset, offset.length);
16861686
},
1687-
sort(reverse?) {
1688-
if (typeof reverse === "boolean") {
1689-
return wrap("sort", reverse);
1690-
}
1687+
sort(options?) {
1688+
options = { descending: false, nullsLast: false, ...(options ?? {}) };
16911689

1692-
return wrap("sort", reverse?.reverse ?? false);
1690+
return wrap("sort", options.descending, options.nullsLast);
16931691
},
16941692
sub(field) {
16951693
return dtypeWrap("Sub", field);

polars/series/list.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Series, _Series } from ".";
2+
import { exprToLitOrExpr } from "..";
23
import { col } from "../lazy/functions";
34
import { ListFunctions } from "../shared_traits";
45

@@ -49,8 +50,8 @@ export const SeriesListFunctions = (_s): ListFunctions<Series> => {
4950
tail(n = 5) {
5051
return this.slice(-n, n);
5152
},
52-
join(separator = ",") {
53-
return wrap("join", separator);
53+
join(options?) {
54+
return wrap("join", options);
5455
},
5556
last() {
5657
return wrap("get", -1);

0 commit comments

Comments
 (0)