From c0dfc89bc17d83ab0c3252b7bc9f86c5d6aedd9a Mon Sep 17 00:00:00 2001 From: Bidek56 Date: Thu, 26 Oct 2023 20:52:50 -0400 Subject: [PATCH] Upgrading biome and fixing linting errors --- .github/workflows/create-js-release.yaml | 8 +- __tests__/dataframe.test.ts | 16 ++-- __tests__/expr.test.ts | 4 +- __tests__/lazyframe.test.ts | 12 +-- biome.json | 2 +- package.json | 10 +-- polars/dataframe.ts | 25 +++--- polars/internals/construction.ts | 12 ++- polars/lazy/dataframe.ts | 4 +- polars/series/index.ts | 12 ++- polars/shared_traits.ts | 2 +- yarn.lock | 110 +++++++++++++---------- 12 files changed, 116 insertions(+), 101 deletions(-) diff --git a/.github/workflows/create-js-release.yaml b/.github/workflows/create-js-release.yaml index 0d4cca4a4..00270387b 100644 --- a/.github/workflows/create-js-release.yaml +++ b/.github/workflows/create-js-release.yaml @@ -83,10 +83,10 @@ jobs: architecture: x64 target: aarch64-linux-android build: | - export CLANG_VERSION=`ls ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang | sed 's/ *$//g'` - touch "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a" - chmod 777 "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a" - echo "INPUT(-lunwind)" > "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a" + export CLANG_VERSION=`ls ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib/clang | sed 's/ *$//g'` + touch "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a" + chmod 777 "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a" + echo "INPUT(-lunwind)" > "${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/lib/clang/${CLANG_VERSION}/lib/linux/aarch64/libgcc.a" yarn build --target aarch64-linux-android ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip polars/*.node diff --git a/__tests__/dataframe.test.ts b/__tests__/dataframe.test.ts index 59b732c7f..63c5e09ff 100644 --- a/__tests__/dataframe.test.ts +++ b/__tests__/dataframe.test.ts @@ -137,7 +137,7 @@ describe("dataframe", () => { }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder", () => { - Array.from({ length: 100 }).forEach(() => { + for (const x of Array.from({ length: 100 })) { const actual = pl .DataFrame({ foo: [0, 1, 2, 2, 2], @@ -152,11 +152,11 @@ describe("dataframe", () => { ham: ["0", "a", "b"], }); expect(actual).toFrameEqual(expected); - }); + } }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder:single subset", () => { - Array.from({ length: 100 }).forEach(() => { + for (const x of Array.from({ length: 100 })) { const actual = pl .DataFrame({ foo: [0, 1, 2, 2, 2], @@ -171,11 +171,11 @@ describe("dataframe", () => { ham: ["0", "a", "b"], }); expect(actual).toFrameEqual(expected); - }); + } }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder:multi subset", () => { - Array.from({ length: 100 }).forEach(() => { + for (const x of Array.from({ length: 100 })) { const actual = pl .DataFrame({ foo: [0, 1, 2, 2, 2], @@ -190,7 +190,7 @@ describe("dataframe", () => { ham: ["0", "a", "b", "c"], }); expect(actual).toFrameEqual(expected); - }); + } }); test("unnest", () => { const expected = pl.DataFrame({ @@ -427,9 +427,9 @@ describe("dataframe", () => { pl.Series("foo", [1, 2, 3]), pl.Series("ham", ["a", "b", "c"]), ]; - actual.forEach((a, idx) => { + for (const [idx, a] of actual.entries()) { expect(a).toSeriesEqual(expected[idx]); - }); + } }); test("groupBy", () => { const actual = pl diff --git a/__tests__/expr.test.ts b/__tests__/expr.test.ts index ab13483a4..4ab7e07ab 100644 --- a/__tests__/expr.test.ts +++ b/__tests__/expr.test.ts @@ -998,7 +998,9 @@ describe("expr.str", () => { .toFrame(); const actual = df.select( - col("a").str.extract(/candidate=(\w+)/, 1).as("candidate"), + col("a") + .str.extract(/candidate=(\w+)/, 1) + .as("candidate"), ); expect(actual).toFrameEqual(expected); expect(seriesActual).toFrameEqual(expected); diff --git a/__tests__/lazyframe.test.ts b/__tests__/lazyframe.test.ts index 1f5905032..c3a7c43a8 100644 --- a/__tests__/lazyframe.test.ts +++ b/__tests__/lazyframe.test.ts @@ -119,7 +119,7 @@ describe("lazyframe", () => { }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder", () => { - Array.from({ length: 100 }).forEach(() => { + for (const x of Array.from({ length: 100 })) { const actual = pl .DataFrame({ foo: [0, 1, 2, 2, 2], @@ -135,11 +135,11 @@ describe("lazyframe", () => { ham: ["0", "a", "b"], }); expect(actual).toFrameEqual(expected); - }); + } }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder:single subset", () => { - Array.from({ length: 100 }).forEach(() => { + for (const x of Array.from({ length: 100 })) { const actual = pl .DataFrame({ foo: [0, 1, 2, 2, 2], @@ -155,11 +155,11 @@ describe("lazyframe", () => { ham: ["0", "a", "b"], }); expect(actual).toFrameEqual(expected); - }); + } }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder:multi subset", () => { - Array.from({ length: 100 }).forEach(() => { + for (const x of Array.from({ length: 100 })) { const actual = pl .DataFrame({ foo: [0, 1, 2, 2, 2], @@ -175,7 +175,7 @@ describe("lazyframe", () => { ham: ["0", "a", "b", "c"], }); expect(actual).toFrameEqual(expected); - }); + } }); test("dropNulls", () => { const actual = pl diff --git a/biome.json b/biome.json index 3c7c33599..7abeca1bc 100644 --- a/biome.json +++ b/biome.json @@ -26,7 +26,7 @@ ] }, "formatter": { - "indentSize": 2, + "indentWidth": 2, "indentStyle": "space", "ignore": [ "polars/native-polars.js", diff --git a/package.json b/package.json index 9bf3f420b..0318815b4 100644 --- a/package.json +++ b/package.json @@ -55,17 +55,17 @@ "precommit": "yarn lint && yarn test" }, "devDependencies": { - "@biomejs/biome": "^1.1.2", + "@biomejs/biome": "^1.3.1", "@napi-rs/cli": "^2.16.3", - "@types/chance": "^1.1.4", - "@types/jest": "^29.5.4", - "@types/node": "^20.6.0", + "@types/chance": "^1.1.5", + "@types/jest": "^29.5.6", + "@types/node": "^20.8.9", "chance": "^1.1.11", "jest": "^29.7.0", "source-map-support": "^0.5.21", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", - "typedoc": "^0.25.1", + "typedoc": "^0.25.2", "typescript": "5.2.2" }, "packageManager": "yarn@3.6.2", diff --git a/polars/dataframe.ts b/polars/dataframe.ts index 3411fd33a..b10b401ab 100644 --- a/polars/dataframe.ts +++ b/polars/dataframe.ts @@ -1868,13 +1868,10 @@ export const _DataFrame = (_df: any): DataFrame => { if (!Array.isArray(names[0]) && names.length === 1) { return wrap("drop", names[0]); } - const df: any = this.clone(); - - names.flat(2).forEach((name) => { + for (const name of names.flat(2)) { df.inner().dropInPlace(name); - }); - + } return df; }, dropNulls(...subset) { @@ -2125,10 +2122,9 @@ export const _DataFrame = (_df: any): DataFrame => { }, rename(mapping) { const df = this.clone(); - Object.entries(mapping).forEach(([column, new_col]) => { + for (const [column, new_col] of Object.entries(mapping)) { (df as any).inner().rename(column, new_col); - }); - + } return df; }, replaceAtIdx(index, newColumn) { @@ -2255,20 +2251,19 @@ export const _DataFrame = (_df: any): DataFrame => { // Add table headers htmlTable += ""; - this.getColumns().forEach((field) => { + for (const field of this.getColumns()) { htmlTable += `${escapeHTML(field.name)}`; - }); + } htmlTable += ""; - // Add table data htmlTable += ""; - this.toRecords().forEach((row) => { + for (const row of this.toRecords()) { htmlTable += ""; - this.getColumns().forEach((field) => { + for (const field of this.getColumns()) { htmlTable += `${escapeHTML(String(row[field.name]))}`; - }); + } htmlTable += ""; - }); + } htmlTable += ""; return htmlTable; diff --git a/polars/internals/construction.ts b/polars/internals/construction.ts index caf157565..976f5e195 100644 --- a/polars/internals/construction.ts +++ b/polars/internals/construction.ts @@ -190,13 +190,12 @@ export function arrayToJsDataFrame(data: any[], options?): any { dataSeries = []; } else if (data[0]?._s) { dataSeries = []; - - data.forEach((series: any, idx) => { + for (const [idx, series] of data.entries()) { if (!series.name) { series.rename(`column_${idx}`, true); } dataSeries.push(series._s); - }); + } } else if (data[0].constructor.name === "Object") { const df = pli.fromRows(data, schema, inferSchemaLength); @@ -233,10 +232,9 @@ function handleColumnsArg(data: any[], columns?: string[]) { if (!data) { return columns.map((c) => (Series.from(c, []) as any)._s); } else if (data.length === columns.length) { - columns.forEach((name, i) => { - data[i].rename(name); - }); - + for (const [idx, name] of columns.entries()) { + data[idx].rename(name); + } return data; } } diff --git a/polars/lazy/dataframe.ts b/polars/lazy/dataframe.ts index 1e1aab538..fc8bf4d37 100644 --- a/polars/lazy/dataframe.ts +++ b/polars/lazy/dataframe.ts @@ -465,12 +465,12 @@ export interface LazyDataFrame extends Serialize, GroupByOps { const prepareGroupbyInputs = (by) => { if (Array.isArray(by)) { const newBy: any = []; - by.forEach((e) => { + for (let e of by) { if (typeof e === "string") { e = pli.col(e); } newBy.push(e); - }); + } return newBy; } else if (typeof by === "string") { diff --git a/polars/series/index.ts b/polars/series/index.ts index c3cc77678..cd1448ce9 100644 --- a/polars/series/index.ts +++ b/polars/series/index.ts @@ -774,7 +774,11 @@ export interface Series * false * ``` */ - seriesEqual(other: Series, nullEqual?: boolean, strict?: boolean): boolean; + seriesEqual( + other: Series, + nullEqual?: boolean, + strict?: boolean, + ): boolean; /** * __Set masked values__ * @param filter Boolean mask @@ -1788,13 +1792,13 @@ export interface SeriesConstructor extends Deserialize { * Creates an array from an array-like object. * @param arrayLike — An array-like object to convert to an array. */ - from(arrayLike: ArrayLike): Series; - from(name: string, arrayLike: ArrayLike): Series; + from(arrayLike: ArrayLike): Series; + from(name: string, arrayLike: ArrayLike): Series; /** * Returns a new Series from a set of elements. * @param items — A set of elements to include in the new Series object. */ - of(...items: T[]): Series; + of(...items: T3[]): Series; isSeries(arg: any): arg is Series; /** * @param binary used to serialize/deserialize series. This will only work with the output from series.toBinary(). diff --git a/polars/shared_traits.ts b/polars/shared_traits.ts index 192d87244..9f8d182bd 100644 --- a/polars/shared_traits.ts +++ b/polars/shared_traits.ts @@ -505,7 +505,7 @@ export interface Sample { export interface Bincode { (bincode: Uint8Array): T; - getState(T): Uint8Array; + getState(T2): Uint8Array; } /** diff --git a/yarn.lock b/yarn.lock index 7c2f27cac..d807e0a19 100644 --- a/yarn.lock +++ b/yarn.lock @@ -408,16 +408,16 @@ __metadata: languageName: node linkType: hard -"@biomejs/biome@npm:^1.1.2": - version: 1.2.2 - resolution: "@biomejs/biome@npm:1.2.2" - dependencies: - "@biomejs/cli-darwin-arm64": 1.2.2 - "@biomejs/cli-darwin-x64": 1.2.2 - "@biomejs/cli-linux-arm64": 1.2.2 - "@biomejs/cli-linux-x64": 1.2.2 - "@biomejs/cli-win32-arm64": 1.2.2 - "@biomejs/cli-win32-x64": 1.2.2 +"@biomejs/biome@npm:^1.3.1": + version: 1.3.1 + resolution: "@biomejs/biome@npm:1.3.1" + dependencies: + "@biomejs/cli-darwin-arm64": 1.3.1 + "@biomejs/cli-darwin-x64": 1.3.1 + "@biomejs/cli-linux-arm64": 1.3.1 + "@biomejs/cli-linux-x64": 1.3.1 + "@biomejs/cli-win32-arm64": 1.3.1 + "@biomejs/cli-win32-x64": 1.3.1 dependenciesMeta: "@biomejs/cli-darwin-arm64": optional: true @@ -433,48 +433,48 @@ __metadata: optional: true bin: biome: bin/biome - checksum: 36dfcc756c53e22a5f6b5819ebb261b02acaa4df2832ef00e231bf73d4707121d0acdefa81f12523beb09a7b363676ca8fe719873932794d2e92130c3a41908c + checksum: d650ab977b3b4cb53105f528f89e4e92f92fb89ffe0ec18629c2061858540ac3f294b507231d6ef19314c22df818e06690629186e739312964b32c54151ee1b5 languageName: node linkType: hard -"@biomejs/cli-darwin-arm64@npm:1.2.2": - version: 1.2.2 - resolution: "@biomejs/cli-darwin-arm64@npm:1.2.2" +"@biomejs/cli-darwin-arm64@npm:1.3.1": + version: 1.3.1 + resolution: "@biomejs/cli-darwin-arm64@npm:1.3.1" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-darwin-x64@npm:1.2.2": - version: 1.2.2 - resolution: "@biomejs/cli-darwin-x64@npm:1.2.2" +"@biomejs/cli-darwin-x64@npm:1.3.1": + version: 1.3.1 + resolution: "@biomejs/cli-darwin-x64@npm:1.3.1" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@biomejs/cli-linux-arm64@npm:1.2.2": - version: 1.2.2 - resolution: "@biomejs/cli-linux-arm64@npm:1.2.2" +"@biomejs/cli-linux-arm64@npm:1.3.1": + version: 1.3.1 + resolution: "@biomejs/cli-linux-arm64@npm:1.3.1" conditions: os=linux & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-linux-x64@npm:1.2.2": - version: 1.2.2 - resolution: "@biomejs/cli-linux-x64@npm:1.2.2" +"@biomejs/cli-linux-x64@npm:1.3.1": + version: 1.3.1 + resolution: "@biomejs/cli-linux-x64@npm:1.3.1" conditions: os=linux & cpu=x64 languageName: node linkType: hard -"@biomejs/cli-win32-arm64@npm:1.2.2": - version: 1.2.2 - resolution: "@biomejs/cli-win32-arm64@npm:1.2.2" +"@biomejs/cli-win32-arm64@npm:1.3.1": + version: 1.3.1 + resolution: "@biomejs/cli-win32-arm64@npm:1.3.1" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-win32-x64@npm:1.2.2": - version: 1.2.2 - resolution: "@biomejs/cli-win32-x64@npm:1.2.2" +"@biomejs/cli-win32-x64@npm:1.3.1": + version: 1.3.1 + resolution: "@biomejs/cli-win32-x64@npm:1.3.1" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -930,10 +930,10 @@ __metadata: languageName: node linkType: hard -"@types/chance@npm:^1.1.4": - version: 1.1.4 - resolution: "@types/chance@npm:1.1.4" - checksum: 0ce6a654e6702237800b01ae7889209a98752ed4792d810b5007c27c046972988ac6fcc36063bdc7ede37d3ab1d0fd0a7bb3e405d4566c80debd9e663a90bbb0 +"@types/chance@npm:^1.1.5": + version: 1.1.5 + resolution: "@types/chance@npm:1.1.5" + checksum: fd27552c7c38ebf60a721f7b5af77de9808df6b5f5bf6ee784c6c2ec62edb730ac76c502d736fbc5c59c77baaef8e70e83279e80d7adee4263d420f6e847a185 languageName: node linkType: hard @@ -971,23 +971,32 @@ __metadata: languageName: node linkType: hard -"@types/jest@npm:^29.5.4": - version: 29.5.5 - resolution: "@types/jest@npm:29.5.5" +"@types/jest@npm:^29.5.6": + version: 29.5.6 + resolution: "@types/jest@npm:29.5.6" dependencies: expect: ^29.0.0 pretty-format: ^29.0.0 - checksum: 56e55cde9949bcc0ee2fa34ce5b7c32c2bfb20e53424aa4ff3a210859eeaaa3fdf6f42f81a3f655238039cdaaaf108b054b7a8602f394e6c52b903659338d8c6 + checksum: fa13a27bd1c8efd0381a419478769d0d6d3a8e93e1952d7ac3a16274e8440af6f73ed6f96ac1ff00761198badf2ee226b5ab5583a5d87a78d609ea78da5c5a24 languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:^20.6.0": +"@types/node@npm:*": version: 20.6.2 resolution: "@types/node@npm:20.6.2" checksum: 96fe5303872640a173f3fd43e289a451776ed5b8f0090094447c6790b43f23fb607eea8268af0829cef4d132e5afa0bfa4cd871aa7412e9042a414a698e9e971 languageName: node linkType: hard +"@types/node@npm:^20.8.9": + version: 20.8.9 + resolution: "@types/node@npm:20.8.9" + dependencies: + undici-types: ~5.26.4 + checksum: 0c05f3502a9507ff27e91dd6fd574fa6f391b3fafedcfe8e0c8d33351fb22d02c0121f854e5b6b3ecb9a8a468407ddf6e7ac0029fb236d4c7e1361ffc758a01f + languageName: node + linkType: hard + "@types/stack-utils@npm:^2.0.0": version: 2.0.1 resolution: "@types/stack-utils@npm:2.0.1" @@ -3058,17 +3067,17 @@ __metadata: version: 0.0.0-use.local resolution: "nodejs-polars@workspace:." dependencies: - "@biomejs/biome": ^1.1.2 + "@biomejs/biome": ^1.3.1 "@napi-rs/cli": ^2.16.3 - "@types/chance": ^1.1.4 - "@types/jest": ^29.5.4 - "@types/node": ^20.6.0 + "@types/chance": ^1.1.5 + "@types/jest": ^29.5.6 + "@types/node": ^20.8.9 chance: ^1.1.11 jest: ^29.7.0 source-map-support: ^0.5.21 ts-jest: ^29.1.1 ts-node: ^10.9.1 - typedoc: ^0.25.1 + typedoc: ^0.25.2 typescript: 5.2.2 languageName: unknown linkType: soft @@ -3814,9 +3823,9 @@ __metadata: languageName: node linkType: hard -"typedoc@npm:^0.25.1": - version: 0.25.1 - resolution: "typedoc@npm:0.25.1" +"typedoc@npm:^0.25.2": + version: 0.25.2 + resolution: "typedoc@npm:0.25.2" dependencies: lunr: ^2.3.9 marked: ^4.3.0 @@ -3826,7 +3835,7 @@ __metadata: typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x bin: typedoc: bin/typedoc - checksum: 6c1c28cbf51b6ab1741429f58f540c5c12d6119ce30054866b879ef2a3a2120a6adbaf59919f7411d3bb51b9113fc926522c40934a3d8ef601785abdf0134eed + checksum: 5b6e24bae7498bb542aaba495378ed5a3e13c76eb04a1ae95b506f76bda4d517847101fb05a7eab3f6b79357d1e2ac6f4747d39792395329b72e463f7effda65 languageName: node linkType: hard @@ -3850,6 +3859,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~5.26.4": + version: 5.26.5 + resolution: "undici-types@npm:5.26.5" + checksum: 3192ef6f3fd5df652f2dc1cd782b49d6ff14dc98e5dced492aa8a8c65425227da5da6aafe22523c67f035a272c599bb89cfe803c1db6311e44bed3042fc25487 + languageName: node + linkType: hard + "unique-filename@npm:^3.0.0": version: 3.0.0 resolution: "unique-filename@npm:3.0.0"