Skip to content

Commit

Permalink
Updating dependencies (#73)
Browse files Browse the repository at this point in the history
* 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 <dchrostowski@medallia.com>
  • Loading branch information
Bidek56 and Darek committed Jun 16, 2023
1 parent 98153fd commit 703f574
Show file tree
Hide file tree
Showing 38 changed files with 1,636 additions and 1,590 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
21 changes: 13 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ repository = "https://github.com/pola-rs/nodejs-polars"
crate-type = ["cdylib", "lib"]

[dependencies]
ahash = "0.7"
bincode = "1.3"
napi = {version = "2.10.9", default-features = false, features = ["napi8", "serde-json", "experimental"]}
napi-derive = {version = "2.9.4", default-features = false}
polars-core = {git = "https://github.com/pola-rs/polars.git", rev = "43598c3e21a2b6c1246a565005045ef553e4f688", default-features = false}
thiserror = "1.0.20"

ahash = "0.8.3"
bincode = "1.3.3"
napi = {version = "2.13.1", 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 = "af2948a430846dae784d062a3c6f223e685af9ac", default-features = false}
polars-ops = {git = "https://github.com/pola-rs/polars.git", rev = "af2948a430846dae784d062a3c6f223e685af9ac", default-features = false}
polars-io = {git = "https://github.com/pola-rs/polars.git", rev = "af2948a430846dae784d062a3c6f223e685af9ac", default-features = false}
thiserror = "1.0.40"
smartstring = { version = "1" }
serde_json = {version = "1"}

[dependencies.polars]
features = [
"binary_encoding",
"rolling_window",
"json",
"dynamic_groupby",
Expand All @@ -41,6 +44,7 @@ features = [
"rows",
"private",
"round_series",
"is_unique",
"is_in",
"is_first",
"asof_join",
Expand Down Expand Up @@ -88,9 +92,10 @@ features = [
"avro",
"list_eval",
"arg_where",
"timezones",
]
git = "https://github.com/pola-rs/polars.git"
rev = "43598c3e21a2b6c1246a565005045ef553e4f688"
rev = "af2948a430846dae784d062a3c6f223e685af9ac"

[build-dependencies]
napi-build = "2.0.1"
Expand Down
11 changes: 7 additions & 4 deletions __tests__/complex_types.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import pl from "@polars";

describe("complex types", () => {
test.skip("nested arrays round trip", () => {
const arr = [[["foo"]], [], null];
test("nested arrays round trip", () => {
const arr = [["foo"], [], null];
const s = pl.Series("", arr);
const actual = s.toArray();
expect(actual).toEqual(arr);
});
test.skip("struct arrays round trip", () => {
const arr = [{ foo: "a", bar: 1 }, null, null];
test("struct arrays round trip", () => {
const arr = [
{ foo: "a", bar: 1 },
{ foo: "b", bar: 2 },
];
const s = pl.Series("", arr);
const actual = s.toArray();
expect(actual).toEqual(arr);
Expand Down
104 changes: 77 additions & 27 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("dataframe", () => {
const actual = expected.clone();
expect(actual).toFrameEqual(expected);
});
test.skip("describe", () => {
test("describe", () => {
const actual = pl
.DataFrame({
a: [1, 2, 3],
Expand All @@ -56,8 +56,8 @@ describe("dataframe", () => {
const expected = pl.DataFrame({
describe: ["mean", "std", "min", "max", "median"],
a: [2, 1, 1, 3, 2],
b: [null, null, null, null, null],
c: [null, null, 0, 1, null],
b: [null, null, "a", "c", null],
c: [0.6666666666666666, 0.5773502588272095, 0, 1, 1],
});

expect(actual).toFrameEqual(expected);
Expand Down Expand Up @@ -192,13 +192,22 @@ describe("dataframe", () => {
expect(actual).toFrameEqual(expected);
});
});
test("unnest", () => {
const expected = pl.DataFrame({
int: [1, 2],
str: ["a", "b"],
bool: [true, null],
list: [[1, 2], [3]],
});
const actual = expected.toStruct("my_struct").toFrame().unnest("my_struct");
expect(actual).toFrameEqual(expected);
});
test("DF with nulls", () => {
const actual = pl
.DataFrame([
{ foo: 1, bar: 6.0, ham: "a" },
{ foo: null,bar: 0.5, ham: "b" },
{ foo: 3, bar: 7.0, ham: "c" },
]);
const actual = pl.DataFrame([
{ foo: 1, bar: 6.0, ham: "a" },
{ foo: null, bar: 0.5, ham: "b" },
{ foo: 3, bar: 7.0, ham: "c" },
]);
const expected = pl.DataFrame({
foo: [1, null, 3],
bar: [6.0, 0.5, 7.0],
Expand Down Expand Up @@ -284,7 +293,35 @@ describe("dataframe", () => {
});
expect(actual).toFrameEqual(expected);
});
// test.todo("filter");
test("filter", () => {
const df = pl.DataFrame({
foo: [1, 2, 3],
bar: [6, 7, 8],
ham: ["a", "b", "c"],
});
// Filter on one condition
let actual = df.filter(pl.col("foo").lt(3));
let expected = pl.DataFrame({
foo: [1, 2],
bar: [6, 7],
ham: ["a", "b"],
});
expect(actual).toFrameEqual(expected);

// Filter on multiple conditions
actual = df.filter(
pl
.col("foo")
.lt(3)
.and(pl.col("ham").eq(pl.lit("a"))),
);
expected = pl.DataFrame({
foo: [1],
bar: [6],
ham: ["a"],
});
expect(actual).toFrameEqual(expected);
});
test("findIdxByName", () => {
const actual = pl
.DataFrame({
Expand All @@ -296,12 +333,12 @@ describe("dataframe", () => {
const expected = 2;
expect(actual).toEqual(expected);
});
// test("fold:single column", () => {
// const expected = pl.Series([1, 2, 3]);
// const df = pl.DataFrame([expected]);
// const actual = df.fold((a, b) => a.concat(b));
// expect(actual).toSeriesEqual(expected);
// });
test("fold:single column", () => {
const expected = pl.Series([1, 2, 3]);
const df = pl.DataFrame([expected]);
const actual = df.fold((a, b) => a.concat(b));
expect(actual).toSeriesEqual(expected);
});
// test("fold", () => {
// const s1 = pl.Series([1, 2, 3]);
// const s2 = pl.Series([4, 5, 6]);
Expand Down Expand Up @@ -611,10 +648,23 @@ describe("dataframe", () => {
ham: ["a", "b", "c"],
})
.median();

expect(actual.row(0)).toEqual([2, 7, null]);
});
test.todo("melt");
test("melt", () => {
const df = pl.DataFrame({
id: [1],
asset_key_1: ["123"],
asset_key_2: ["456"],
asset_key_3: ["abc"],
});
const actual = df.melt("id", ["asset_key_1", "asset_key_2", "asset_key_3"]);
const expected = pl.DataFrame({
id: [1, 1, 1],
variable: ["asset_key_1", "asset_key_2", "asset_key_3"],
value: ["123", "456", "abc"],
});
expect(actual).toFrameEqual(expected);
});
test("min:axis:0", () => {
const actual = pl
.DataFrame({
Expand Down Expand Up @@ -765,7 +815,7 @@ describe("dataframe", () => {
expect(fn).toThrow(TypeError);
});
test("select:strings", () => {
const columns = ["ham", "foo"]
const columns = ["ham", "foo"];
const actual = pl
.DataFrame({
foo: [1, 2, 3, 1],
Expand Down Expand Up @@ -986,7 +1036,7 @@ describe("dataframe", () => {
const expected = [9, 8];
expect(actual).toEqual(expected);
});
test.skip("transpose", () => {
test("transpose", () => {
const expected = pl.DataFrame({
column_0: [1, 1],
column_1: [2, 2],
Expand All @@ -999,9 +1049,9 @@ describe("dataframe", () => {
const actual = df.transpose();
expect(actual).toFrameEqual(expected);
});
test.skip("transpose:includeHeader", () => {
test("transpose:includeHeader", () => {
const expected = pl.DataFrame({
column: ["a", "b"],
"": ["a", "b"],
column_0: [1, 1],
column_1: [2, 2],
column_2: [3, 3],
Expand All @@ -1013,7 +1063,7 @@ describe("dataframe", () => {
const actual = df.transpose({ includeHeader: true });
expect(actual).toFrameEqual(expected);
});
test.skip("transpose:columnNames", () => {
test("transpose:columnNames", () => {
const expected = pl.DataFrame({
a: [1, 1],
b: [2, 2],
Expand All @@ -1026,7 +1076,7 @@ describe("dataframe", () => {
const actual = df.transpose({ includeHeader: false, columnNames: "abc" });
expect(actual).toFrameEqual(expected);
});
test.skip("transpose:columnNames:generator", () => {
test("transpose:columnNames:generator", () => {
const expected = pl.DataFrame({
col_0: [1, 1],
col_1: [2, 2],
Expand All @@ -1036,7 +1086,7 @@ describe("dataframe", () => {
const baseName = "col_";
let count = 0;
while (true) {
let name = `${baseName}${count}`;
const name = `${baseName}${count}`;
yield name;
count++;
}
Expand Down Expand Up @@ -1553,7 +1603,7 @@ describe("io", () => {
callback(null);
},
});
df.writeJSON(writeStream, { format: "lines" });
df.writeJSON(writeStream, { format: "json" });
const newDF = pl.readJSON(body).select("foo", "bar");
expect(newDF).toFrameEqual(df);
done();
Expand All @@ -1563,7 +1613,7 @@ describe("io", () => {
pl.Series("foo", [1, 2, 3], pl.UInt32),
pl.Series("bar", ["a", "b", "c"]),
]);
df.writeJSON("./test.json", { format: "lines" });
df.writeJSON("./test.json", { format: "json" });
const newDF = pl.readJSON("./test.json").select("foo", "bar");
expect(newDF).toFrameEqual(df);
fs.rmSync("./test.json");
Expand Down
56 changes: 29 additions & 27 deletions __tests__/examples/foods.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
{"category":"vegetables","calories":45,"fats_g":0.5,"sugars_g":2}
{"category":"seafood","calories":150,"fats_g":5.0,"sugars_g":0}
{"category":"meat","calories":100,"fats_g":5.0,"sugars_g":0}
{"category":"fruit","calories":60,"fats_g":0.0,"sugars_g":11}
{"category":"seafood","calories":140,"fats_g":5.0,"sugars_g":1}
{"category":"meat","calories":120,"fats_g":10.0,"sugars_g":1}
{"category":"vegetables","calories":20,"fats_g":0.0,"sugars_g":2}
{"category":"fruit","calories":30,"fats_g":0.0,"sugars_g":5}
{"category":"seafood","calories":130,"fats_g":5.0,"sugars_g":0}
{"category":"fruit","calories":50,"fats_g":4.5,"sugars_g":0}
{"category":"meat","calories":110,"fats_g":7.0,"sugars_g":0}
{"category":"vegetables","calories":25,"fats_g":0.0,"sugars_g":2}
{"category":"fruit","calories":30,"fats_g":0.0,"sugars_g":3}
{"category":"vegetables","calories":22,"fats_g":0.0,"sugars_g":3}
{"category":"vegetables","calories":25,"fats_g":0.0,"sugars_g":4}
{"category":"seafood","calories":100,"fats_g":5.0,"sugars_g":0}
{"category":"seafood","calories":200,"fats_g":10.0,"sugars_g":0}
{"category":"seafood","calories":200,"fats_g":7.0,"sugars_g":2}
{"category":"fruit","calories":60,"fats_g":0.0,"sugars_g":11}
{"category":"meat","calories":110,"fats_g":7.0,"sugars_g":0}
{"category":"vegetables","calories":25,"fats_g":0.0,"sugars_g":3}
{"category":"seafood","calories":200,"fats_g":7.0,"sugars_g":2}
{"category":"seafood","calories":130,"fats_g":1.5,"sugars_g":0}
{"category":"fruit","calories":130,"fats_g":0.0,"sugars_g":25}
{"category":"meat","calories":100,"fats_g":7.0,"sugars_g":0}
{"category":"vegetables","calories":30,"fats_g":0.0,"sugars_g":5}
{"category":"fruit","calories":50,"fats_g":0.0,"sugars_g":11}
[
{ "category": "vegetables", "calories": 45, "fats_g": 0.5, "sugars_g": 2 },
{ "category": "seafood", "calories": 150, "fats_g": 5.0, "sugars_g": 0 },
{ "category": "meat", "calories": 100, "fats_g": 5.0, "sugars_g": 0 },
{ "category": "fruit", "calories": 60, "fats_g": 0.0, "sugars_g": 11 },
{ "category": "seafood", "calories": 140, "fats_g": 5.0, "sugars_g": 1 },
{ "category": "meat", "calories": 120, "fats_g": 10.0, "sugars_g": 1 },
{ "category": "vegetables", "calories": 20, "fats_g": 0.0, "sugars_g": 2 },
{ "category": "fruit", "calories": 30, "fats_g": 0.0, "sugars_g": 5 },
{ "category": "seafood", "calories": 130, "fats_g": 5.0, "sugars_g": 0 },
{ "category": "fruit", "calories": 50, "fats_g": 4.5, "sugars_g": 0 },
{ "category": "meat", "calories": 110, "fats_g": 7.0, "sugars_g": 0 },
{ "category": "vegetables", "calories": 25, "fats_g": 0.0, "sugars_g": 2 },
{ "category": "fruit", "calories": 30, "fats_g": 0.0, "sugars_g": 3 },
{ "category": "vegetables", "calories": 22, "fats_g": 0.0, "sugars_g": 3 },
{ "category": "vegetables", "calories": 25, "fats_g": 0.0, "sugars_g": 4 },
{ "category": "seafood", "calories": 100, "fats_g": 5.0, "sugars_g": 0 },
{ "category": "seafood", "calories": 200, "fats_g": 10.0, "sugars_g": 0 },
{ "category": "seafood", "calories": 200, "fats_g": 7.0, "sugars_g": 2 },
{ "category": "fruit", "calories": 60, "fats_g": 0.0, "sugars_g": 11 },
{ "category": "meat", "calories": 110, "fats_g": 7.0, "sugars_g": 0 },
{ "category": "vegetables", "calories": 25, "fats_g": 0.0, "sugars_g": 3 },
{ "category": "seafood", "calories": 200, "fats_g": 7.0, "sugars_g": 2 },
{ "category": "seafood", "calories": 130, "fats_g": 1.5, "sugars_g": 0 },
{ "category": "fruit", "calories": 130, "fats_g": 0.0, "sugars_g": 25 },
{ "category": "meat", "calories": 100, "fats_g": 7.0, "sugars_g": 0 },
{ "category": "vegetables", "calories": 30, "fats_g": 0.0, "sugars_g": 5 },
{ "category": "fruit", "calories": 50, "fats_g": 0.0, "sugars_g": 11 }
]
1 change: 1 addition & 0 deletions __tests__/examples/single_foods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "category": "vegetables", "calories": 45, "fats_g": "0.5", "sugars_g": 2 }
Loading

0 comments on commit 703f574

Please sign in to comment.