Skip to content

Commit 703f574

Browse files
Bidek56Darek
and
Darek
authored
Updating dependencies (pola-rs#73)
* First attempt in upgrading to Polars 0.28 * WIP compile time * Fixing tests * Fixing tests * Fixing tests * Fixing tests * Fixing tests * Fixing tests * Fixing timezone tests * Upgrading packages * Removing unsed script * Fixing linting errors * Removing feature decorators * Adding melt test * Fixing linting errors * Adding more tests * Fixing complex tests Adding struct series tests * Changing min node version to 16+ Removing unsed and commented code --------- Co-authored-by: Darek <[email protected]>
1 parent 98153fd commit 703f574

38 files changed

+1636
-1590
lines changed

.yarn/install-state.gz

-21.2 KB
Binary file not shown.

Cargo.toml

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ repository = "https://github.com/pola-rs/nodejs-polars"
1313
crate-type = ["cdylib", "lib"]
1414

1515
[dependencies]
16-
ahash = "0.7"
17-
bincode = "1.3"
18-
napi = {version = "2.10.9", default-features = false, features = ["napi8", "serde-json", "experimental"]}
19-
napi-derive = {version = "2.9.4", default-features = false}
20-
polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "43598c3e21a2b6c1246a565005045ef553e4f688", default-features = false}
21-
thiserror = "1.0.20"
22-
16+
ahash = "0.8.3"
17+
bincode = "1.3.3"
18+
napi = {version = "2.13.1", default-features = false, features = ["napi8", "serde-json", "experimental"]}
19+
napi-derive = {version = "2.13.0", default-features = false}
20+
polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "af2948a430846dae784d062a3c6f223e685af9ac", default-features = false}
21+
polars-ops = {git = "https://github.com/pola-rs/polars.git", rev = "af2948a430846dae784d062a3c6f223e685af9ac", default-features = false}
22+
polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "af2948a430846dae784d062a3c6f223e685af9ac", default-features = false}
23+
thiserror = "1.0.40"
24+
smartstring = { version = "1" }
2325
serde_json = {version = "1"}
2426

2527
[dependencies.polars]
2628
features = [
29+
"binary_encoding",
2730
"rolling_window",
2831
"json",
2932
"dynamic_groupby",
@@ -41,6 +44,7 @@ features = [
4144
"rows",
4245
"private",
4346
"round_series",
47+
"is_unique",
4448
"is_in",
4549
"is_first",
4650
"asof_join",
@@ -88,9 +92,10 @@ features = [
8892
"avro",
8993
"list_eval",
9094
"arg_where",
95+
"timezones",
9196
]
9297
git = "https://github.com/pola-rs/polars.git"
93-
rev = "43598c3e21a2b6c1246a565005045ef553e4f688"
98+
rev = "af2948a430846dae784d062a3c6f223e685af9ac"
9499

95100
[build-dependencies]
96101
napi-build = "2.0.1"

__tests__/complex_types.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import pl from "@polars";
22

33
describe("complex types", () => {
4-
test.skip("nested arrays round trip", () => {
5-
const arr = [[["foo"]], [], null];
4+
test("nested arrays round trip", () => {
5+
const arr = [["foo"], [], null];
66
const s = pl.Series("", arr);
77
const actual = s.toArray();
88
expect(actual).toEqual(arr);
99
});
10-
test.skip("struct arrays round trip", () => {
11-
const arr = [{ foo: "a", bar: 1 }, null, null];
10+
test("struct arrays round trip", () => {
11+
const arr = [
12+
{ foo: "a", bar: 1 },
13+
{ foo: "b", bar: 2 },
14+
];
1215
const s = pl.Series("", arr);
1316
const actual = s.toArray();
1417
expect(actual).toEqual(arr);

__tests__/dataframe.test.ts

+77-27
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("dataframe", () => {
4545
const actual = expected.clone();
4646
expect(actual).toFrameEqual(expected);
4747
});
48-
test.skip("describe", () => {
48+
test("describe", () => {
4949
const actual = pl
5050
.DataFrame({
5151
a: [1, 2, 3],
@@ -56,8 +56,8 @@ describe("dataframe", () => {
5656
const expected = pl.DataFrame({
5757
describe: ["mean", "std", "min", "max", "median"],
5858
a: [2, 1, 1, 3, 2],
59-
b: [null, null, null, null, null],
60-
c: [null, null, 0, 1, null],
59+
b: [null, null, "a", "c", null],
60+
c: [0.6666666666666666, 0.5773502588272095, 0, 1, 1],
6161
});
6262

6363
expect(actual).toFrameEqual(expected);
@@ -192,13 +192,22 @@ describe("dataframe", () => {
192192
expect(actual).toFrameEqual(expected);
193193
});
194194
});
195+
test("unnest", () => {
196+
const expected = pl.DataFrame({
197+
int: [1, 2],
198+
str: ["a", "b"],
199+
bool: [true, null],
200+
list: [[1, 2], [3]],
201+
});
202+
const actual = expected.toStruct("my_struct").toFrame().unnest("my_struct");
203+
expect(actual).toFrameEqual(expected);
204+
});
195205
test("DF with nulls", () => {
196-
const actual = pl
197-
.DataFrame([
198-
{ foo: 1, bar: 6.0, ham: "a" },
199-
{ foo: null,bar: 0.5, ham: "b" },
200-
{ foo: 3, bar: 7.0, ham: "c" },
201-
]);
206+
const actual = pl.DataFrame([
207+
{ foo: 1, bar: 6.0, ham: "a" },
208+
{ foo: null, bar: 0.5, ham: "b" },
209+
{ foo: 3, bar: 7.0, ham: "c" },
210+
]);
202211
const expected = pl.DataFrame({
203212
foo: [1, null, 3],
204213
bar: [6.0, 0.5, 7.0],
@@ -284,7 +293,35 @@ describe("dataframe", () => {
284293
});
285294
expect(actual).toFrameEqual(expected);
286295
});
287-
// test.todo("filter");
296+
test("filter", () => {
297+
const df = pl.DataFrame({
298+
foo: [1, 2, 3],
299+
bar: [6, 7, 8],
300+
ham: ["a", "b", "c"],
301+
});
302+
// Filter on one condition
303+
let actual = df.filter(pl.col("foo").lt(3));
304+
let expected = pl.DataFrame({
305+
foo: [1, 2],
306+
bar: [6, 7],
307+
ham: ["a", "b"],
308+
});
309+
expect(actual).toFrameEqual(expected);
310+
311+
// Filter on multiple conditions
312+
actual = df.filter(
313+
pl
314+
.col("foo")
315+
.lt(3)
316+
.and(pl.col("ham").eq(pl.lit("a"))),
317+
);
318+
expected = pl.DataFrame({
319+
foo: [1],
320+
bar: [6],
321+
ham: ["a"],
322+
});
323+
expect(actual).toFrameEqual(expected);
324+
});
288325
test("findIdxByName", () => {
289326
const actual = pl
290327
.DataFrame({
@@ -296,12 +333,12 @@ describe("dataframe", () => {
296333
const expected = 2;
297334
expect(actual).toEqual(expected);
298335
});
299-
// test("fold:single column", () => {
300-
// const expected = pl.Series([1, 2, 3]);
301-
// const df = pl.DataFrame([expected]);
302-
// const actual = df.fold((a, b) => a.concat(b));
303-
// expect(actual).toSeriesEqual(expected);
304-
// });
336+
test("fold:single column", () => {
337+
const expected = pl.Series([1, 2, 3]);
338+
const df = pl.DataFrame([expected]);
339+
const actual = df.fold((a, b) => a.concat(b));
340+
expect(actual).toSeriesEqual(expected);
341+
});
305342
// test("fold", () => {
306343
// const s1 = pl.Series([1, 2, 3]);
307344
// const s2 = pl.Series([4, 5, 6]);
@@ -611,10 +648,23 @@ describe("dataframe", () => {
611648
ham: ["a", "b", "c"],
612649
})
613650
.median();
614-
615651
expect(actual.row(0)).toEqual([2, 7, null]);
616652
});
617-
test.todo("melt");
653+
test("melt", () => {
654+
const df = pl.DataFrame({
655+
id: [1],
656+
asset_key_1: ["123"],
657+
asset_key_2: ["456"],
658+
asset_key_3: ["abc"],
659+
});
660+
const actual = df.melt("id", ["asset_key_1", "asset_key_2", "asset_key_3"]);
661+
const expected = pl.DataFrame({
662+
id: [1, 1, 1],
663+
variable: ["asset_key_1", "asset_key_2", "asset_key_3"],
664+
value: ["123", "456", "abc"],
665+
});
666+
expect(actual).toFrameEqual(expected);
667+
});
618668
test("min:axis:0", () => {
619669
const actual = pl
620670
.DataFrame({
@@ -765,7 +815,7 @@ describe("dataframe", () => {
765815
expect(fn).toThrow(TypeError);
766816
});
767817
test("select:strings", () => {
768-
const columns = ["ham", "foo"]
818+
const columns = ["ham", "foo"];
769819
const actual = pl
770820
.DataFrame({
771821
foo: [1, 2, 3, 1],
@@ -986,7 +1036,7 @@ describe("dataframe", () => {
9861036
const expected = [9, 8];
9871037
expect(actual).toEqual(expected);
9881038
});
989-
test.skip("transpose", () => {
1039+
test("transpose", () => {
9901040
const expected = pl.DataFrame({
9911041
column_0: [1, 1],
9921042
column_1: [2, 2],
@@ -999,9 +1049,9 @@ describe("dataframe", () => {
9991049
const actual = df.transpose();
10001050
expect(actual).toFrameEqual(expected);
10011051
});
1002-
test.skip("transpose:includeHeader", () => {
1052+
test("transpose:includeHeader", () => {
10031053
const expected = pl.DataFrame({
1004-
column: ["a", "b"],
1054+
"": ["a", "b"],
10051055
column_0: [1, 1],
10061056
column_1: [2, 2],
10071057
column_2: [3, 3],
@@ -1013,7 +1063,7 @@ describe("dataframe", () => {
10131063
const actual = df.transpose({ includeHeader: true });
10141064
expect(actual).toFrameEqual(expected);
10151065
});
1016-
test.skip("transpose:columnNames", () => {
1066+
test("transpose:columnNames", () => {
10171067
const expected = pl.DataFrame({
10181068
a: [1, 1],
10191069
b: [2, 2],
@@ -1026,7 +1076,7 @@ describe("dataframe", () => {
10261076
const actual = df.transpose({ includeHeader: false, columnNames: "abc" });
10271077
expect(actual).toFrameEqual(expected);
10281078
});
1029-
test.skip("transpose:columnNames:generator", () => {
1079+
test("transpose:columnNames:generator", () => {
10301080
const expected = pl.DataFrame({
10311081
col_0: [1, 1],
10321082
col_1: [2, 2],
@@ -1036,7 +1086,7 @@ describe("dataframe", () => {
10361086
const baseName = "col_";
10371087
let count = 0;
10381088
while (true) {
1039-
let name = `${baseName}${count}`;
1089+
const name = `${baseName}${count}`;
10401090
yield name;
10411091
count++;
10421092
}
@@ -1553,7 +1603,7 @@ describe("io", () => {
15531603
callback(null);
15541604
},
15551605
});
1556-
df.writeJSON(writeStream, { format: "lines" });
1606+
df.writeJSON(writeStream, { format: "json" });
15571607
const newDF = pl.readJSON(body).select("foo", "bar");
15581608
expect(newDF).toFrameEqual(df);
15591609
done();
@@ -1563,7 +1613,7 @@ describe("io", () => {
15631613
pl.Series("foo", [1, 2, 3], pl.UInt32),
15641614
pl.Series("bar", ["a", "b", "c"]),
15651615
]);
1566-
df.writeJSON("./test.json", { format: "lines" });
1616+
df.writeJSON("./test.json", { format: "json" });
15671617
const newDF = pl.readJSON("./test.json").select("foo", "bar");
15681618
expect(newDF).toFrameEqual(df);
15691619
fs.rmSync("./test.json");

__tests__/examples/foods.json

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
{"category":"vegetables","calories":45,"fats_g":0.5,"sugars_g":2}
2-
{"category":"seafood","calories":150,"fats_g":5.0,"sugars_g":0}
3-
{"category":"meat","calories":100,"fats_g":5.0,"sugars_g":0}
4-
{"category":"fruit","calories":60,"fats_g":0.0,"sugars_g":11}
5-
{"category":"seafood","calories":140,"fats_g":5.0,"sugars_g":1}
6-
{"category":"meat","calories":120,"fats_g":10.0,"sugars_g":1}
7-
{"category":"vegetables","calories":20,"fats_g":0.0,"sugars_g":2}
8-
{"category":"fruit","calories":30,"fats_g":0.0,"sugars_g":5}
9-
{"category":"seafood","calories":130,"fats_g":5.0,"sugars_g":0}
10-
{"category":"fruit","calories":50,"fats_g":4.5,"sugars_g":0}
11-
{"category":"meat","calories":110,"fats_g":7.0,"sugars_g":0}
12-
{"category":"vegetables","calories":25,"fats_g":0.0,"sugars_g":2}
13-
{"category":"fruit","calories":30,"fats_g":0.0,"sugars_g":3}
14-
{"category":"vegetables","calories":22,"fats_g":0.0,"sugars_g":3}
15-
{"category":"vegetables","calories":25,"fats_g":0.0,"sugars_g":4}
16-
{"category":"seafood","calories":100,"fats_g":5.0,"sugars_g":0}
17-
{"category":"seafood","calories":200,"fats_g":10.0,"sugars_g":0}
18-
{"category":"seafood","calories":200,"fats_g":7.0,"sugars_g":2}
19-
{"category":"fruit","calories":60,"fats_g":0.0,"sugars_g":11}
20-
{"category":"meat","calories":110,"fats_g":7.0,"sugars_g":0}
21-
{"category":"vegetables","calories":25,"fats_g":0.0,"sugars_g":3}
22-
{"category":"seafood","calories":200,"fats_g":7.0,"sugars_g":2}
23-
{"category":"seafood","calories":130,"fats_g":1.5,"sugars_g":0}
24-
{"category":"fruit","calories":130,"fats_g":0.0,"sugars_g":25}
25-
{"category":"meat","calories":100,"fats_g":7.0,"sugars_g":0}
26-
{"category":"vegetables","calories":30,"fats_g":0.0,"sugars_g":5}
27-
{"category":"fruit","calories":50,"fats_g":0.0,"sugars_g":11}
1+
[
2+
{ "category": "vegetables", "calories": 45, "fats_g": 0.5, "sugars_g": 2 },
3+
{ "category": "seafood", "calories": 150, "fats_g": 5.0, "sugars_g": 0 },
4+
{ "category": "meat", "calories": 100, "fats_g": 5.0, "sugars_g": 0 },
5+
{ "category": "fruit", "calories": 60, "fats_g": 0.0, "sugars_g": 11 },
6+
{ "category": "seafood", "calories": 140, "fats_g": 5.0, "sugars_g": 1 },
7+
{ "category": "meat", "calories": 120, "fats_g": 10.0, "sugars_g": 1 },
8+
{ "category": "vegetables", "calories": 20, "fats_g": 0.0, "sugars_g": 2 },
9+
{ "category": "fruit", "calories": 30, "fats_g": 0.0, "sugars_g": 5 },
10+
{ "category": "seafood", "calories": 130, "fats_g": 5.0, "sugars_g": 0 },
11+
{ "category": "fruit", "calories": 50, "fats_g": 4.5, "sugars_g": 0 },
12+
{ "category": "meat", "calories": 110, "fats_g": 7.0, "sugars_g": 0 },
13+
{ "category": "vegetables", "calories": 25, "fats_g": 0.0, "sugars_g": 2 },
14+
{ "category": "fruit", "calories": 30, "fats_g": 0.0, "sugars_g": 3 },
15+
{ "category": "vegetables", "calories": 22, "fats_g": 0.0, "sugars_g": 3 },
16+
{ "category": "vegetables", "calories": 25, "fats_g": 0.0, "sugars_g": 4 },
17+
{ "category": "seafood", "calories": 100, "fats_g": 5.0, "sugars_g": 0 },
18+
{ "category": "seafood", "calories": 200, "fats_g": 10.0, "sugars_g": 0 },
19+
{ "category": "seafood", "calories": 200, "fats_g": 7.0, "sugars_g": 2 },
20+
{ "category": "fruit", "calories": 60, "fats_g": 0.0, "sugars_g": 11 },
21+
{ "category": "meat", "calories": 110, "fats_g": 7.0, "sugars_g": 0 },
22+
{ "category": "vegetables", "calories": 25, "fats_g": 0.0, "sugars_g": 3 },
23+
{ "category": "seafood", "calories": 200, "fats_g": 7.0, "sugars_g": 2 },
24+
{ "category": "seafood", "calories": 130, "fats_g": 1.5, "sugars_g": 0 },
25+
{ "category": "fruit", "calories": 130, "fats_g": 0.0, "sugars_g": 25 },
26+
{ "category": "meat", "calories": 100, "fats_g": 7.0, "sugars_g": 0 },
27+
{ "category": "vegetables", "calories": 30, "fats_g": 0.0, "sugars_g": 5 },
28+
{ "category": "fruit", "calories": 50, "fats_g": 0.0, "sugars_g": 11 }
29+
]

__tests__/examples/single_foods.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "category": "vegetables", "calories": 45, "fats_g": "0.5", "sugars_g": 2 }

0 commit comments

Comments
 (0)