Skip to content

Commit

Permalink
ci(nodejs-polars): add linting & test runner (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
universalmind303 committed Dec 22, 2021
1 parent b7d8bce commit ade3670
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 44 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/test-js.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test JS
on:
pull_request:
paths:
- 'nodejs-polars/**'
jobs:
test-js:
runs-on: ubuntu-latest
name: "${{ matrix.os }} node:${{ matrix.node }}"
defaults:
run:
working-directory: nodejs-polars
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
node: ["16", "17"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: yarn
cache-dependency-path: nodejs-polars/yarn.lock
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-12-02
override: true
components: rustfmt, clippy
- name: Install Node Dependencies
run: yarn install
- name: Build Binary
run: yarn build:debug
- name: Run Linting
run: yarn lint:ts
- name: Run Tests
run: yarn test
- name: Build JS
run: yarn build:ts
- name: Import polars
run: node -e "require('./bin/index.js')"
62 changes: 50 additions & 12 deletions nodejs-polars/__tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe("dataframe", () => {
"bar": [1, 2, 4],
"ham": ["a", "d", "c"],
});
expect(actual).toFrameEqual(expected);
expect(actual).toFrameEqualIgnoringOrder(expected);
});
test("dropDuplicates:subset", () => {
const actual = pl.DataFrame({
Expand All @@ -243,20 +243,58 @@ describe("dataframe", () => {
"bar": [1, 2, 2],
"ham": ["a", "b", "c"],
});
expect(actual).toFrameEqual(expected);
expect(actual).toFrameEqualIgnoringOrder(expected);
});
// run this test 100 times to make sure it is deterministic.
test("dropDuplicates:maintainOrder", () => {
const actual = pl.DataFrame({
"foo": [1, 2, 2, 2],
"bar": [1, 2, 2, 2],
"ham": ["a", "b", "c", "d"],
}).dropDuplicates({maintainOrder: true, subset: ["foo", "bar"]});
const expected = pl.DataFrame({
"foo": [1, 2],
"bar": [1, 2],
"ham": ["a", "b"],
Array.from({length:100}).forEach(() => {
const actual = pl.DataFrame({
"foo": [0, 1, 2, 2, 2],
"bar": [0, 1, 2, 2, 2],
"ham": ["0", "a", "b", "b", "b"],
}).dropDuplicates({maintainOrder: true});

const expected = pl.DataFrame({
"foo": [0, 1, 2],
"bar": [0, 1, 2],
"ham": ["0", "a", "b"],
});
expect(actual).toFrameEqual(expected);
});
});
// run this test 100 times to make sure it is deterministic.
test("dropDuplicates:maintainOrder:single subset", () => {
Array.from({length:100}).forEach(() => {
const actual = pl.DataFrame({
"foo": [0, 1, 2, 2, 2],
"bar": [0, 1, 2, 2, 2],
"ham": ["0", "a", "b", "c", "d"],
}).dropDuplicates({maintainOrder: true, subset: "foo"});

const expected = pl.DataFrame({
"foo": [0, 1, 2],
"bar": [0, 1, 2],
"ham": ["0", "a", "b"],
});
expect(actual).toFrameEqual(expected);
});
});
// run this test 100 times to make sure it is deterministic.
test("dropDuplicates:maintainOrder:multi subset", () => {
Array.from({length:100}).forEach(() => {
const actual = pl.DataFrame({
"foo": [0, 1, 2, 2, 2],
"bar": [0, 1, 2, 2, 2],
"ham": ["0", "a", "b", "c", "c"],
}).dropDuplicates({maintainOrder: true, subset: ["foo", "ham"]});

const expected = pl.DataFrame({
"foo": [0, 1, 2, 2],
"bar": [0, 1, 2, 2],
"ham": ["0", "a", "b", "c"],
});
expect(actual).toFrameEqual(expected);
});
expect(actual).toFrameEqual(expected);
});
test("dropNulls", () => {
const actual = pl.DataFrame({
Expand Down
64 changes: 51 additions & 13 deletions nodejs-polars/__tests__/lazyframe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,59 @@ describe("lazyframe", () => {
});
expect(actual).toFrameEqualIgnoringOrder(expected);
});

// run this test 100 times to make sure it is deterministic.
test("dropDuplicates:maintainOrder", () => {
const actual = pl.DataFrame({
"foo": [1, 2, 2, 2],
"bar": [1, 2, 2, 2],
"ham": ["a", "b", "c", "d"],
}).lazy()
.dropDuplicates({maintainOrder: true, subset: ["foo", "bar"]})
.collectSync();
const expected = pl.DataFrame({
"foo": [1, 2],
"bar": [1, 2],
"ham": ["a", "b"],
Array.from({length:100}).forEach(() => {
const actual = pl.DataFrame({
"foo": [0, 1, 2, 2, 2],
"bar": [0, 1, 2, 2, 2],
"ham": ["0", "a", "b", "b", "b"],
}).lazy()
.dropDuplicates({maintainOrder: true})
.collectSync();
const expected = pl.DataFrame({
"foo": [0, 1, 2],
"bar": [0, 1, 2],
"ham": ["0", "a", "b"],
});
expect(actual).toFrameEqual(expected);
});
});
// run this test 100 times to make sure it is deterministic.
test("dropDuplicates:maintainOrder:single subset", () => {
Array.from({length:100}).forEach(() => {
const actual = pl.DataFrame({
"foo": [0, 1, 2, 2, 2],
"bar": [0, 1, 2, 2, 2],
"ham": ["0", "a", "b", "c", "d"],
}).lazy()
.dropDuplicates({maintainOrder: true, subset: "foo"})
.collectSync();
const expected = pl.DataFrame({
"foo": [0, 1, 2],
"bar": [0, 1, 2],
"ham": ["0", "a", "b"],
});
expect(actual).toFrameEqual(expected);
});
});
// run this test 100 times to make sure it is deterministic.
test("dropDuplicates:maintainOrder:multi subset", () => {
Array.from({length:100}).forEach(() => {
const actual = pl.DataFrame({
"foo": [0, 1, 2, 2, 2],
"bar": [0, 1, 2, 2, 2],
"ham": ["0", "a", "b", "c", "c"],
}).lazy()
.dropDuplicates({maintainOrder: true, subset: ["foo", "ham"]})
.collectSync();
const expected = pl.DataFrame({
"foo": [0, 1, 2, 2],
"bar": [0, 1, 2, 2],
"ham": ["0", "a", "b", "c"],
});
expect(actual).toFrameEqual(expected);
});
expect(actual).toFrameEqual(expected);
});
test("dropNulls", () => {
const actual = pl.DataFrame({
Expand Down
4 changes: 1 addition & 3 deletions nodejs-polars/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
"artifacts": "napi artifacts",
"bench": "node -r @swc-node/register benchmark/bench.ts",
"build": "napi build --platform --release polars",
"build:debug": "napi build --platform polars",
"build:all": "tsc -p tsconfig.build.json && napi build --platform --release polars",
"build:all:slim": "tsc -p tsconfig.build.json && RUSTFLAGS='-C codegen-units=16' napi build --platform --release polars",
"build:debug": "napi build --platform",
"build:ts": "tsc -p tsconfig.build.json",
"format:rs": "cargo fmt",
"format:source": "prettier --config ./package.json --write './**/*.{js,ts}'",
Expand Down
13 changes: 6 additions & 7 deletions nodejs-polars/polars/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,15 +1284,14 @@ export const dfWrapper = (_df: JsDataFrame): DataFrame => {
return wrap("drop_nulls");
}
},
dropDuplicates(opts: any=true, subset?) {
if(opts?.maintainOrder !== undefined) {
return this.dropDuplicates(opts.maintainOrder, opts.subset);
}
if(subset) {
subset = [subset].flat(2);
dropDuplicates(opts: any=false, subset?) {
const maintainOrder = opts?.maintainOrder ?? opts;
subset = opts?.subset ?? subset;
if(typeof subset! === "string") {
subset = [subset];
}

return wrap("drop_duplicates", {maintainOrder: opts.maintainOrder, subset});
return wrap("drop_duplicates", {maintainOrder, subset});
},
explode(...columns) {
return dfWrapper(_df).lazy()
Expand Down
4 changes: 2 additions & 2 deletions nodejs-polars/polars/internals/polars_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import {loadBinding} from "@node-rs/helper";
import {join} from "path";

// eslint-disable-next-line no-undef
const up1 = join(__dirname, "../");
const bindings = loadBinding(up1, "nodejs-polars", "nodejs-polars");
const up2 = join(__dirname, "../", "../");
const bindings = loadBinding(up2, "nodejs-polars", "nodejs-polars");
export default bindings;
14 changes: 7 additions & 7 deletions nodejs-polars/polars/lazy/dataframe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ export const LazyDataFrame = (ldf: JsLazyFrame): LazyDataFrame => {
collectSync: () => dfWrapper(unwrap("collectSync")),
collect: () => unwrap("collect").then(dfWrapper),
drop: (...cols) => wrap("dropColumns", {cols: cols.flat(2)}),
dropDuplicates(opts: any=true, subset?){
if(opts?.maintainOrder !== undefined) {
return this.dropDuplicates(opts.maintainOrder, opts.subset);
}
if(subset) {
subset = [subset].flat(2);
dropDuplicates(opts: any=false, subset?) {
const maintainOrder = opts?.maintainOrder ?? opts;
subset = opts?.subset ?? subset;
if(typeof subset! === "string") {
subset = [subset];
}

return wrap("dropDuplicates", {maintainOrder: opts.maintainOrder, subset});
return wrap("dropDuplicates", {maintainOrder, subset});

},
dropNulls(...subset) {
if(subset.length) {
Expand Down

0 comments on commit ade3670

Please sign in to comment.