diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 4726b079a..000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "ignorePatterns": [ - "**/*.js" - ], - "env": { - "browser": true, - "es2021": true, - "jest/globals": true - }, - "globals": { - "Buffer": "readonly", - "process": "writable" - }, - "extends": [ - "eslint:recommended" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2020, - "sourceType": "module" - }, - "plugins": [ - "@typescript-eslint", - "jest" - ], - "rules": { - "arrow-spacing": "error", - "eol-last": "error", - "no-inner-declarations": "off", - "func-call-spacing": "off", - "no-duplicate-imports": "off", - "comma-spacing": "off", - "quotes": [ - "error", - "double", - { - "allowTemplateLiterals": true, - "avoidEscape": true - } - ], - "no-redeclare": "off", - "no-trailing-spaces": "error", - "semi": [ - "error", - "always" - ], - "indent": [ - "error", - 2, - { - "MemberExpression": 1 - } - ], - "no-dupe-class-members": "off", - "no-unused-vars": "off", - "newline-per-chained-call": [ - "error", - { - "ignoreChainWithDepth": 2 - } - ], - "no-multiple-empty-lines": [ - "error", - { - "max": 2, - "maxEOF": 0 - } - ], - "padding-line-between-statements": [ - "error", - { - "blankLine": "always", - "prev": "*", - "next": "return" - } - ], - "@typescript-eslint/func-call-spacing": "error", - "@typescript-eslint/no-duplicate-imports": "error", - "@typescript-eslint/comma-spacing": "error", - "@typescript-eslint/type-annotation-spacing": "error" - } -} \ No newline at end of file diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz new file mode 100644 index 000000000..05b9da4a3 Binary files /dev/null and b/.yarn/install-state.gz differ diff --git a/@types/jest.d.ts b/@types/jest.d.ts index 28058d8c2..e66c70e3a 100644 --- a/@types/jest.d.ts +++ b/@types/jest.d.ts @@ -1,5 +1,5 @@ import {DataFrame} from "@polars/dataframe"; -import {Series} from "@polars/series/series"; +import {Series} from "@polars/series"; declare global { namespace jest { @@ -12,11 +12,11 @@ declare global { * * @example * ``` - * >>> df = pl.Dataframe([pl.Series("int32": [1,2], pl.Int32)]) - * >>> other = pl.Dataframe([pl.Series("int32": [1,2], pl.UInt32)]) + * > df = pl.Dataframe([pl.Series("int32": [1,2], pl.Int32)]) + * > other = pl.Dataframe([pl.Series("int32": [1,2], pl.UInt32)]) * - * >>> expect(df).toFrameEqual(other) // passes - * >>> expect(df).toFrameStrictEqual(other) // fails + * > expect(df).toFrameEqual(other) // passes + * > expect(df).toFrameStrictEqual(other) // fails * ``` */ toFrameStrictEqual(b: DataFrame): R; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..1251bfc5c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,71 @@ +# Contributing to nodejs-polars + +First of all, thank you for considering contributing to nodejs-polars! + +The following is a set of guidelines for contributing to nodejs-polars. These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request. + +## How Can I Contribute? + +### Reporting Bugs + +- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/pola-rs/nodejs-polars/issues). + +- If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring. + +- If possible, use the relevant bug report templates to create the issue. + +### Suggesting Enhancements + +- Open a new GitHub issue in the [Issues](https://github.com/pola-rs/nodejs-polars/issues) with a **clear title** and **description**. + +- If possible, use the relevant enhancement request templates to create the issue. + + +### Pull Requests + +- Fill in the required template +- Use a descriptive title. *(This will end up in the changelog)* +- In the pull request description, link to the issue you were working on. +- Add any relevant information to the description that you think may help the maintainers review your code. +- Make sure your branch is [rebased](https://docs.github.com/en/get-started/using-git/about-git-rebase) against the latest version of the `main` branch. +- Make sure all GitHub Actions checks pass. + + + +## Development +### Vscode +If using VScode, it is recommended to install the following extensions +- rust-analyzer +- rome +--- + +- Fork the repository, then clone it from your fork +``` +git clone https://github.com//nodejs-polars.git +``` + +- Install dependencies +``` +yarn install +``` + +- Build the binary +``` +yarn build:debug +``` + +- Run the tests +``` +yarn jest +``` + +- Make your changes +- Test your changes +- +You can run the `precommit` command to make sure all of your tests pass & code is formatted correctly. +``` +yarn precommit +``` + +- Update the documentation if necessary +- Create a new pull request diff --git a/README.md b/README.md index b35968e88..337e2a191 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,14 @@ const pl = require('nodejs-polars'); ### Series ```js ->>> const fooSeries = pl.Series("foo", [1, 2, 3]) ->>> fooSeries.sum() +> const fooSeries = pl.Series("foo", [1, 2, 3]) +> fooSeries.sum() 6 // a lot operations support both positional and named arguments // you can see the full specs in the docs or the type definitions ->>> fooSeries.sort(true) ->>> fooSeries.sort({reverse: true}) +> fooSeries.sort(true) +> fooSeries.sort({reverse: true}) shape: (3,) Series: 'foo' [f64] [ @@ -36,14 +36,14 @@ Series: 'foo' [f64] 2 1 ] ->>> fooSeries.toArray() +> fooSeries.toArray() [1, 2, 3] // Series are 'Iterables' so you can use javascript iterable syntax on them ->>> [...fooSeries] +> [...fooSeries] [1, 2, 3] ->>> fooSeries[0] +> fooSeries[0] 1 ``` @@ -51,7 +51,7 @@ Series: 'foo' [f64] ### DataFrame ```js ->>> const df = pl.DataFrame( +>const df = pl.DataFrame( ... { ... A: [1, 2, 3, 4, 5], ... fruits: ["banana", "banana", "apple", "apple", "banana"], @@ -59,9 +59,7 @@ Series: 'foo' [f64] ... cars: ["beetle", "audi", "beetle", "beetle", "beetle"], ... } ... ) ->>> df -... .sort("fruits") -... .select( +> df.sort("fruits").select( ... "fruits", ... "cars", ... pl.lit("fruits").alias("literal_string_fruits"), @@ -90,7 +88,7 @@ shape: (5, 8) ``` ```js ->>> df["cars"] // or df.getColumn("cars") +> df["cars"] // or df.getColumn("cars") shape: (5,) Series: 'cars' [str] [ diff --git a/__tests__/complex_types.test.ts b/__tests__/complex_types.test.ts index 87797c6b1..58f52c951 100644 --- a/__tests__/complex_types.test.ts +++ b/__tests__/complex_types.test.ts @@ -1,8 +1,6 @@ import pl from "@polars"; - describe("complex types", () => { - test.skip("nested arrays round trip", () => { const arr = [[["foo"]], [], null]; const s = pl.Series("", arr); @@ -10,10 +8,9 @@ describe("complex types", () => { expect(actual).toEqual(arr); }); test.skip("struct arrays round trip", () => { - const arr = [{foo: "a", bar: 1}, null, null]; + const arr = [{ foo: "a", bar: 1 }, null, null]; const s = pl.Series("", arr); const actual = s.toArray(); expect(actual).toEqual(arr); }); - }); diff --git a/__tests__/dataframe.test.ts b/__tests__/dataframe.test.ts index d0d44f71c..3796050a5 100644 --- a/__tests__/dataframe.test.ts +++ b/__tests__/dataframe.test.ts @@ -1,6 +1,6 @@ /* eslint-disable newline-per-chained-call */ import pl from "@polars"; -import {Stream} from "stream"; +import { Stream } from "stream"; import fs from "fs"; describe("dataframe", () => { const df = pl.DataFrame([ @@ -10,248 +10,275 @@ describe("dataframe", () => { test("dtypes", () => { const expected = [pl.Float64, pl.Utf8]; - const actual = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}).dtypes; + const actual = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }).dtypes; expect(actual).toEqual(expected); }); test("height", () => { const expected = 3; - const actual = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}).height; + const actual = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }).height; expect(actual).toEqual(expected); }); test("width", () => { const expected = 2; - const actual = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}).width; + const actual = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }).width; expect(actual).toEqual(expected); }); test("shape", () => { - const expected = {height: 3, width: 2}; - const actual = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}).shape; + const expected = { height: 3, width: 2 }; + const actual = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }).shape; expect(actual).toEqual(expected); }); test("get columns", () => { const expected = ["a", "b"]; - const actual = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}).columns; + const actual = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }).columns; expect(actual).toEqual(expected); }); test("set columns", () => { const expected = ["d", "e"]; - const df = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}); + const df = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }); df.columns = expected; expect(df.columns).toEqual(expected); }); test("clone", () => { - const expected = pl.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}); + const expected = pl.DataFrame({ a: [1, 2, 3], b: ["a", "b", "c"] }); const actual = expected.clone(); expect(actual).toFrameEqual(expected); }); test.skip("describe", () => { - const actual = pl.DataFrame({ - "a": [1, 2, 3], - "b": ["a", "b", "c"], - "c": [true, true, false] - }).describe(); + const actual = pl + .DataFrame({ + a: [1, 2, 3], + b: ["a", "b", "c"], + c: [true, true, false], + }) + .describe(); 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] + describe: ["mean", "std", "min", "max", "median"], + a: [2, 1, 1, 3, 2], + b: [null, null, null, null, null], + c: [null, null, 0, 1, null], }); expect(actual).toFrameEqual(expected); }); test("drop", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], - "apple": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + apple: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const actual = df.drop("apple"); expect(actual).toFrameEqual(expected); }); test("drop: array", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], - "apple": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + apple: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], }); const actual = df.drop(["apple", "ham"]); expect(actual).toFrameEqual(expected); }); test("drop: ...rest", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], - "apple": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + apple: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], }); const actual = df.drop("apple", "ham"); expect(actual).toFrameEqual(expected); }); test("unique", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 2, 3], - "bar": [1, 2, 2, 4], - "ham": ["a", "d", "d", "c"], - }).unique(); + const actual = pl + .DataFrame({ + foo: [1, 2, 2, 3], + bar: [1, 2, 2, 4], + ham: ["a", "d", "d", "c"], + }) + .unique(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [1, 2, 4], - "ham": ["a", "d", "c"], + foo: [1, 2, 3], + bar: [1, 2, 4], + ham: ["a", "d", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("unique:subset", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 2, 2], - "bar": [1, 2, 2, 2], - "ham": ["a", "b", "c", "c"], - }).unique({subset: ["foo", "ham"]}); + const actual = pl + .DataFrame({ + foo: [1, 2, 2, 2], + bar: [1, 2, 2, 2], + ham: ["a", "b", "c", "c"], + }) + .unique({ subset: ["foo", "ham"] }); const expected = pl.DataFrame({ - "foo": [1, 2, 2], - "bar": [1, 2, 2], - "ham": ["a", "b", "c"], + foo: [1, 2, 2], + bar: [1, 2, 2], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder", () => { - 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"], - }).unique({maintainOrder: true}); + 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"], + }) + .unique({ maintainOrder: true }); const expected = pl.DataFrame({ - "foo": [0, 1, 2], - "bar": [0, 1, 2], - "ham": ["0", "a", "b"], + 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("unique: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"], - }).unique({maintainOrder: true, subset: "foo"}); + 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"], + }) + .unique({ maintainOrder: true, subset: "foo" }); const expected = pl.DataFrame({ - "foo": [0, 1, 2], - "bar": [0, 1, 2], - "ham": ["0", "a", "b"], + 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("unique: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"], - }).unique({maintainOrder: true, subset: ["foo", "ham"]}); + 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"], + }) + .unique({ maintainOrder: true, subset: ["foo", "ham"] }); const expected = pl.DataFrame({ - "foo": [0, 1, 2, 2], - "bar": [0, 1, 2, 2], - "ham": ["0", "a", "b", "c"], + foo: [0, 1, 2, 2], + bar: [0, 1, 2, 2], + ham: ["0", "a", "b", "c"], }); expect(actual).toFrameEqual(expected); }); }); test("dropNulls", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).dropNulls(); + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .dropNulls(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqual(expected); }); test("dropNulls subset", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).dropNulls("foo"); + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .dropNulls("foo"); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqual(expected); }); test("explode", () => { - const actual = pl.DataFrame({ - "letters": ["c", "a"], - "nrs": [[1, 2], [1, 3]] - }).explode("nrs"); + const actual = pl + .DataFrame({ + letters: ["c", "a"], + nrs: [ + [1, 2], + [1, 3], + ], + }) + .explode("nrs"); const expected = pl.DataFrame({ - "letters": ["c", "c", "a", "a"], - "nrs": [1, 2, 1, 3] + letters: ["c", "c", "a", "a"], + nrs: [1, 2, 1, 3], }); expect(actual).toFrameEqual(expected); }); test("fillNull:zero", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).fillNull("zero"); + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .fillNull("zero"); const expected = pl.DataFrame({ - "foo": [1, 0, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], + foo: [1, 0, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], }); expect(actual).toFrameEqual(expected); }); test("fillNull:one", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).fillNull("one"); + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .fillNull("one"); const expected = pl.DataFrame({ - "foo": [1, 1, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], + foo: [1, 1, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], }); expect(actual).toFrameEqual(expected); }); // test.todo("filter"); test("findIdxByName", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).findIdxByName("ham"); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .findIdxByName("ham"); const expected = 2; expect(actual).toEqual(expected); }); @@ -280,174 +307,191 @@ describe("dataframe", () => { // expect(actual).toSeriesEqual(expected); // }); test("frameEqual:true", () => { - const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], + const df = pl.DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], }); - const other = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], + const other = pl.DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], }); const actual = df.frameEqual(other); expect(actual).toStrictEqual(true); }); test("frameEqual:false", () => { - const df = pl.DataFrame({ - "foo": [3, 2, 22], - "baz": [0, 7, 8], + const df = pl.DataFrame({ + foo: [3, 2, 22], + baz: [0, 7, 8], }); - const other = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], + const other = pl.DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], }); const actual = df.frameEqual(other); expect(actual).toStrictEqual(false); }); test("frameEqual:nullEq:false", () => { - const df = pl.DataFrame({ - "foo": [1, 2, null], - "bar": [6, 7, 8], + const df = pl.DataFrame({ + foo: [1, 2, null], + bar: [6, 7, 8], }); - const other = pl.DataFrame({ - "foo": [1, 2, null], - "bar": [6, 7, 8], + const other = pl.DataFrame({ + foo: [1, 2, null], + bar: [6, 7, 8], }); const actual = df.frameEqual(other, false); expect(actual).toStrictEqual(false); }); test("frameEqual:nullEq:true", () => { - const df = pl.DataFrame({ - "foo": [1, 2, null], - "bar": [6, 7, 8], + const df = pl.DataFrame({ + foo: [1, 2, null], + bar: [6, 7, 8], }); - const other = pl.DataFrame({ - "foo": [1, 2, null], - "bar": [6, 7, 8], + const other = pl.DataFrame({ + foo: [1, 2, null], + bar: [6, 7, 8], }); const actual = df.frameEqual(other, true); expect(actual).toStrictEqual(true); }); test("getColumn", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).getColumn("ham"); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .getColumn("ham"); const expected = pl.Series("ham", ["a", "b", "c"]); expect(actual).toSeriesEqual(expected); }); test("getColumns", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).getColumns(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .getColumns(); const expected = [ pl.Series("foo", [1, 2, 3]), - pl.Series("ham", ["a", "b", "c"]) + pl.Series("ham", ["a", "b", "c"]), ]; actual.forEach((a, idx) => { expect(a).toSeriesEqual(expected[idx]); }); - }); test("groupBy", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).groupBy("foo"); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .groupBy("foo"); expect(actual.toString()).toEqual("GroupBy"); }); test("hashRows", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).hashRows(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .hashRows(); expect(actual.dtype).toEqual(pl.UInt64); }); + test.each([[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]])( + "hashRows:positional", + (...args: any[]) => { + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .hashRows(...args); + expect(actual.dtype).toEqual(pl.UInt64); + }, + ); test.each([ - [1], - [1, 2], - [1, 2, 3], - [1, 2, 3, 4], - ])("hashRows:positional", (...args: any[]) => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).hashRows(...args); - expect(actual.dtype).toEqual(pl.UInt64); - }); - test.each([ - [{k0: 1}], - [{k0: 1, k1: 2}], - [{k0: 1, k1: 2, k2:3}], - [{k0: 1, k1: 2, k2:3, k3:4}], + [{ k0: 1 }], + [{ k0: 1, k1: 2 }], + [{ k0: 1, k1: 2, k2: 3 }], + [{ k0: 1, k1: 2, k2: 3, k3: 4 }], ])("hashRows:named", (opts) => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).hashRows(opts); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .hashRows(opts); expect(actual.dtype).toEqual(pl.UInt64); }); test("head", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).head(1); - const expected = pl.DataFrame({ - "foo": [1], - "ham": ["a"] - }).head(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .head(1); + const expected = pl + .DataFrame({ + foo: [1], + ham: ["a"], + }) + .head(1); expect(actual).toFrameEqual(expected); }); test("hstack:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).hstack([pl.Series("apple", [10, 20, 30])]); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .hstack([pl.Series("apple", [10, 20, 30])]); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], - "apple": [10, 20, 30] + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + apple: [10, 20, 30], }); expect(actual).toFrameEqual(expected); }); test("hstack:df", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).hstack(pl.DataFrame([pl.Series("apple", [10, 20, 30])])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .hstack(pl.DataFrame([pl.Series("apple", [10, 20, 30])])); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], - "apple": [10, 20, 30] + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + apple: [10, 20, 30], }); expect(actual).toFrameEqual(expected); }); test("hstack:df", () => { const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], }); actual.insertAtIdx(0, pl.Series("apple", [10, 20, 30])); const expected = pl.DataFrame({ - "apple": [10, 20, 30], - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], + apple: [10, 20, 30], + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqual(expected); }); test("interpolate", () => { const df = pl.DataFrame({ - a: [1, null, 3] + a: [1, null, 3], }); const expected = pl.DataFrame({ - a: [1, 2, 3] + a: [1, 2, 3], }); const actual = df.interpolate(); expect(actual).toFrameEqual(expected); @@ -455,7 +499,7 @@ describe("dataframe", () => { test("isDuplicated", () => { const df = pl.DataFrame({ a: [1, 2, 2], - b: [1, 2, 2] + b: [1, 2, 2], }); const expected = pl.Series([false, true, true]); const actual = df.isDuplicated(); @@ -468,7 +512,7 @@ describe("dataframe", () => { test("isUnique", () => { const df = pl.DataFrame({ a: [1, 2, 2], - b: [1, 2, 2] + b: [1, 2, 2], }); const expected = pl.Series([true, false, false]); const actual = df.isUnique(); @@ -476,130 +520,155 @@ describe("dataframe", () => { }); test("lazy", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] - }).lazy().collectSync(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + }) + .lazy() + .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqual(expected); }); test("limit", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).limit(1); - const expected = pl.DataFrame({ - "foo": [1], - "ham": ["a"] + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .limit(1); + const expected = pl.DataFrame({ + foo: [1], + ham: ["a"], }); expect(actual).toFrameEqual(expected); }); test("max:axis:0", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).max(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .max(); expect(actual.row(0)).toEqual([3, 8, "c"]); }); test("max:axis:1", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).max(1); - const expected = pl.Series("foo", [6, 2, 9]); + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .max(1); + const expected = pl.Series("foo", [6, 2, 9]); expect(actual).toSeriesEqual(expected); }); test("mean:axis:0", () => { - const actual = pl.DataFrame({ - "foo": [4, 4, 4], - "bar": [1, 1, 10], - "ham": ["a", "b", "a"] - }).mean(); + const actual = pl + .DataFrame({ + foo: [4, 4, 4], + bar: [1, 1, 10], + ham: ["a", "b", "a"], + }) + .mean(); expect(actual.row(0)).toEqual([4, 4, null]); }); test("mean:axis:1", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 6], - "bar": [6, 2, 8], - }).mean(1, "ignore"); - const expected = pl.Series("foo", [3.5, 2, 7]); + const actual = pl + .DataFrame({ + foo: [1, null, 6], + bar: [6, 2, 8], + }) + .mean(1, "ignore"); + const expected = pl.Series("foo", [3.5, 2, 7]); expect(actual).toSeriesEqual(expected); }); test("median", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).median(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .median(); expect(actual.row(0)).toEqual([2, 7, null]); }); test.todo("melt"); test("min:axis:0", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).min(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .min(); expect(actual.row(0)).toEqual([1, 6, "a"]); }); test("min:axis:1", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).min(1); - const expected = pl.Series("foo", [1, 2, 8]); + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .min(1); + const expected = pl.Series("foo", [1, 2, 8]); expect(actual).toSeriesEqual(expected); }); test("nChunks", () => { const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], + foo: [1, 2, 9], + bar: [6, 2, 8], }); expect(actual.nChunks()).toEqual(1); }); test("nullCount", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, null], - "bar": [6, 2, 8], - "apple": [6, 2, 8], - "pizza": [null, null, 8], - }).nullCount(); + const actual = pl + .DataFrame({ + foo: [1, 2, null], + bar: [6, 2, 8], + apple: [6, 2, 8], + pizza: [null, null, 8], + }) + .nullCount(); expect(actual.row(0)).toEqual([1, 0, 0, 2]); }); test.todo("pipe"); test("quantile", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).quantile(0.5); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .quantile(0.5); expect(actual.row(0)).toEqual([2, 7, null]); }); test("rename", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).rename({ - "foo": "foo_new", - "bar": "bar_new", - "ham": "ham_new" - }); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .rename({ + foo: "foo_new", + bar: "bar_new", + ham: "ham_new", + }); expect(actual.columns).toEqual(["foo_new", "bar_new", "ham_new"]); }); test("replaceAtIdx", () => { const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], }); const s = pl.Series("new_foo", [0.12, 2.0, 9.99]); actual.replaceAtIdx(0, s); @@ -607,71 +676,88 @@ describe("dataframe", () => { expect(actual.findIdxByName("new_foo")).toEqual(0); }); test("row", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).row(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .row(1); expect(actual).toEqual([2, 7, "b"]); }); test("rows", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).rows(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .rows(); expect(actual).toEqual([ [1, 6, "a"], [2, 7, "b"], - [3, 8, "c"] + [3, 8, "c"], ]); }); test("sample:n", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).sample(2); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .sample(2); expect(actual.height).toStrictEqual(2); }); test("sample:default", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).sample(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .sample(); expect(actual.height).toStrictEqual(1); }); test("sample:frac", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).sample({frac: 0.5}); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .sample({ frac: 0.5 }); expect(actual.height).toStrictEqual(2); }); test("sample:frac", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).sample({frac: 0.75}); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .sample({ frac: 0.75 }); expect(actual.height).toStrictEqual(3); }); test("sample:invalid", () => { - const fn = () => pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).sample({} as any); + const fn = () => + pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .sample({} as any); expect(fn).toThrow(TypeError); }); test("select:strings", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).select("ham", "foo"); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .select("ham", "foo"); const foo = pl.Series("foo", [1, 2, 3, 1]); const ham = pl.Series("ham", ["a", "b", "c", null]); expect(actual.width).toStrictEqual(2); @@ -679,11 +765,13 @@ describe("dataframe", () => { expect(actual.getColumn("ham")).toSeriesEqual(ham); }); test("select:expr", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).select(pl.col("foo"), "ham"); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .select(pl.col("foo"), "ham"); const foo = pl.Series("foo", [1, 2, 3, 1]); const ham = pl.Series("ham", ["a", "b", "c", null]); expect(actual.width).toStrictEqual(2); @@ -691,140 +779,159 @@ describe("dataframe", () => { expect(actual.getColumn("ham")).toSeriesEqual(ham); }); test("shift:pos", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).shift(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .shift(1); const expected = pl.DataFrame({ - "foo": [null, 1, 2, 3], - "bar": [null, 6, 7, 8], + foo: [null, 1, 2, 3], + bar: [null, 6, 7, 8], }); expect(actual).toFrameEqual(expected); }); test("shift:neg", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).shift(-1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .shift(-1); const expected = pl.DataFrame({ - "foo": [2, 3, 1, null], - "bar": [7, 8, 1, null], + foo: [2, 3, 1, null], + bar: [7, 8, 1, null], }); expect(actual).toFrameEqual(expected); }); test("shiftAndFill:positional", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).shiftAndFill(-1, 99); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .shiftAndFill(-1, 99); const expected = pl.DataFrame({ - "foo": [2, 3, 1, 99], - "bar": [7, 8, 1, 99], + foo: [2, 3, 1, 99], + bar: [7, 8, 1, 99], }); expect(actual).toFrameEqual(expected); }); test("shiftAndFill:named", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).shiftAndFill({periods: -1, fillValue: 99}); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .shiftAndFill({ periods: -1, fillValue: 99 }); const expected = pl.DataFrame({ - "foo": [2, 3, 1, 99], - "bar": [7, 8, 1, 99], + foo: [2, 3, 1, 99], + bar: [7, 8, 1, 99], }); expect(actual).toFrameEqual(expected); }); test("shrinkToFit:inPlace", () => { const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], }); actual.shrinkToFit(true); const expected = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], }); expect(actual).toFrameEqual(expected); }); test("shrinkToFit", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).shrinkToFit(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .shrinkToFit(); const expected = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], }); expect(actual).toFrameEqual(expected); }); test("slice:positional", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).slice(0, 2); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .slice(0, 2); const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": [6, 7], + foo: [1, 2], + bar: [6, 7], }); expect(actual).toFrameEqual(expected); }); test("slice:named", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).slice({offset: 0, length: 2}); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .slice({ offset: 0, length: 2 }); const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": [6, 7], + foo: [1, 2], + bar: [6, 7], }); expect(actual).toFrameEqual(expected); }); test("sort:positional", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).sort("bar"); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .sort("bar"); const expected = pl.DataFrame({ - "foo": [1, 1, 2, 3], - "bar": [1, 6, 7, 8], + foo: [1, 1, 2, 3], + bar: [1, 6, 7, 8], }); expect(actual).toFrameEqual(expected); }); test("sort:named", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).sort({by: "bar", reverse: true}); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .sort({ by: "bar", reverse: true }); const expected = pl.DataFrame({ - "foo": [3, 2, 1, 1], - "bar": [8, 7, 6, 1], + foo: [3, 2, 1, 1], + bar: [8, 7, 6, 1], }); expect(actual).toFrameEqual(expected); }); test("sort:multi-args", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, -1], - "bar": [6, 7, 8, 2], - "baz": ["a", "b", "d", "A"], - }).sort({ - by: [ - pl.col("baz"), - pl.col("bar") - ] - }); + const actual = pl + .DataFrame({ + foo: [1, 2, 3, -1], + bar: [6, 7, 8, 2], + baz: ["a", "b", "d", "A"], + }) + .sort({ + by: [pl.col("baz"), pl.col("bar")], + }); const expected = pl.DataFrame({ - "foo": [-1, 1, 2, 3], - "bar": [2, 6, 7, 8], - "baz": ["A", "a", "b", "d"], + foo: [-1, 1, 2, 3], + bar: [2, 6, 7, 8], + baz: ["A", "a", "b", "d"], }); expect(actual).toFrameEqual(expected); }); test("std", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).std(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .std(); const expected = pl.DataFrame([ pl.Series("foo", [1]), pl.Series("bar", [1]), @@ -833,79 +940,87 @@ describe("dataframe", () => { expect(actual).toFrameEqual(expected); }); test("sum:axis:0", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).sum(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .sum(); expect(actual.row(0)).toEqual([6, 21, null]); }); test("sum:axis:1", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).sum(1).rename("sum"); - const expected = pl.Series("sum", [7, 4, 17]); + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .sum(1) + .rename("sum"); + const expected = pl.Series("sum", [7, 4, 17]); expect(actual).toSeriesEqual(expected); }); test("tail", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).tail(1).row(0); - const expected = [9, 8]; + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .tail(1) + .row(0); + const expected = [9, 8]; expect(actual).toEqual(expected); }); test.skip("transpose", () => { const expected = pl.DataFrame({ - "column_0": [1, 1], - "column_1": [2, 2], - "column_2": [3, 3] + column_0: [1, 1], + column_1: [2, 2], + column_2: [3, 3], }); const df = pl.DataFrame({ a: [1, 2, 3], - b: [1, 2, 3] + b: [1, 2, 3], }); const actual = df.transpose(); expect(actual).toFrameEqual(expected); }); test.skip("transpose:includeHeader", () => { const expected = pl.DataFrame({ - "column": ["a", "b"], - "column_0": [1, 1], - "column_1": [2, 2], - "column_2": [3, 3] + column: ["a", "b"], + column_0: [1, 1], + column_1: [2, 2], + column_2: [3, 3], }); const df = pl.DataFrame({ a: [1, 2, 3], - b: [1, 2, 3] + b: [1, 2, 3], }); - const actual = df.transpose({includeHeader:true}); + const actual = df.transpose({ includeHeader: true }); expect(actual).toFrameEqual(expected); }); test.skip("transpose:columnNames", () => { const expected = pl.DataFrame({ - "a": [1, 1], - "b": [2, 2], - "c": [3, 3] + a: [1, 1], + b: [2, 2], + c: [3, 3], }); const df = pl.DataFrame({ a: [1, 2, 3], - b: [1, 2, 3] + b: [1, 2, 3], }); - const actual = df.transpose({includeHeader:false, columnNames: "abc"}); + const actual = df.transpose({ includeHeader: false, columnNames: "abc" }); expect(actual).toFrameEqual(expected); }); test.skip("transpose:columnNames:generator", () => { const expected = pl.DataFrame({ - "col_0": [1, 1], - "col_1": [2, 2], - "col_2": [3, 3] + col_0: [1, 1], + col_1: [2, 2], + col_2: [3, 3], }); - function *namesGenerator() { + function* namesGenerator() { const baseName = "col_"; let count = 0; - while(true) { + while (true) { let name = `${baseName}${count}`; yield name; count++; @@ -913,17 +1028,22 @@ describe("dataframe", () => { } const df = pl.DataFrame({ a: [1, 2, 3], - b: [1, 2, 3] + b: [1, 2, 3], + }); + const actual = df.transpose({ + includeHeader: false, + columnNames: namesGenerator(), }); - const actual = df.transpose({includeHeader:false, columnNames: namesGenerator()}); expect(actual).toFrameEqual(expected); }); test("var", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).var(); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .var(); const expected = pl.DataFrame([ pl.Series("foo", [1]), pl.Series("bar", [1]), @@ -933,14 +1053,14 @@ describe("dataframe", () => { }); test("vstack", () => { const df1 = pl.DataFrame({ - "foo": [1, 2], - "bar": [6, 7], - "ham": ["a", "b"] + foo: [1, 2], + bar: [6, 7], + ham: ["a", "b"], }); const df2 = pl.DataFrame({ - "foo": [3, 4], - "bar": [8, 9], - "ham": ["c", "d"] + foo: [3, 4], + bar: [8, 9], + ham: ["c", "d"], }); const actual = df1.vstack(df2); @@ -955,7 +1075,7 @@ describe("dataframe", () => { const actual = df .clone() .withColumn(pl.Series("col_a", ["a", "a", "a"], pl.Utf8)); - const expected = pl.DataFrame([ + const expected = pl.DataFrame([ pl.Series("foo", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), pl.Series("col_a", ["a", "a", "a"], pl.Utf8), @@ -963,11 +1083,9 @@ describe("dataframe", () => { expect(actual).toFrameEqual(expected); }); test("withColumn:expr", () => { - const actual = df - .clone() - .withColumn(pl.lit("a").alias("col_a")); + const actual = df.clone().withColumn(pl.lit("a").alias("col_a")); - const expected = pl.DataFrame([ + const expected = pl.DataFrame([ pl.Series("foo", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), pl.Series("col_a", ["a", "a", "a"], pl.Utf8), @@ -979,9 +1097,9 @@ describe("dataframe", () => { .clone() .withColumns( pl.Series("col_a", ["a", "a", "a"], pl.Utf8), - pl.Series("col_b", ["b", "b", "b"], pl.Utf8) + pl.Series("col_b", ["b", "b", "b"], pl.Utf8), ); - const expected = pl.DataFrame([ + const expected = pl.DataFrame([ pl.Series("foo", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), pl.Series("col_a", ["a", "a", "a"], pl.Utf8), @@ -992,11 +1110,8 @@ describe("dataframe", () => { test("withColumns:expr", () => { const actual = df .clone() - .withColumns( - pl.lit("a").alias("col_a"), - pl.lit("b").alias("col_b") - ); - const expected = pl.DataFrame([ + .withColumns(pl.lit("a").alias("col_a"), pl.lit("b").alias("col_b")); + const expected = pl.DataFrame([ pl.Series("foo", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), pl.Series("col_a", ["a", "a", "a"], pl.Utf8), @@ -1005,11 +1120,9 @@ describe("dataframe", () => { expect(actual).toFrameEqual(expected); }); test("withColumnRenamed:positional", () => { - const actual = df - .clone() - .withColumnRenamed("foo", "apple"); + const actual = df.clone().withColumnRenamed("foo", "apple"); - const expected = pl.DataFrame([ + const expected = pl.DataFrame([ pl.Series("apple", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), ]); @@ -1018,20 +1131,18 @@ describe("dataframe", () => { test("withColumnRenamed:named", () => { const actual = df .clone() - .withColumnRenamed({existing: "foo", replacement: "apple"}); + .withColumnRenamed({ existing: "foo", replacement: "apple" }); - const expected = pl.DataFrame([ + const expected = pl.DataFrame([ pl.Series("apple", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), ]); expect(actual).toFrameEqual(expected); }); test("withRowCount", () => { - const actual = df - .clone() - .withRowCount(); + const actual = df.clone().withRowCount(); - const expected = pl.DataFrame([ + const expected = pl.DataFrame([ pl.Series("row_nr", [0, 1, 2], pl.UInt32), pl.Series("foo", [1, 2, 9], pl.Int16), pl.Series("bar", [6, 2, 8], pl.Int16), @@ -1040,20 +1151,31 @@ describe("dataframe", () => { }); test("pivot", () => { const df = pl.DataFrame({ - "a": pl.Series([1, 2, 3]).cast(pl.Int32), - "b": pl.Series([[1, 1], [2, 2], [3, 3]]).cast(pl.List(pl.Int32)) - }); - - const expected = pl.DataFrame( - { - "a": pl.Series([1, 2, 3]).cast(pl.Int32), + a: pl.Series([1, 2, 3]).cast(pl.Int32), + b: pl + .Series([ + [1, 1], + [2, 2], + [3, 3], + ]) + .cast(pl.List(pl.Int32)), + }); + + const expected = pl + .DataFrame({ + a: pl.Series([1, 2, 3]).cast(pl.Int32), "1": pl.Series([[1, 1], null, null]).cast(pl.List(pl.Int32)), "2": pl.Series([null, [2, 2], null]).cast(pl.List(pl.Int32)), "3": pl.Series([null, null, [3, 3]]).cast(pl.List(pl.Int32)), - } - ).select("a", "1", "2", "3"); + }) + .select("a", "1", "2", "3"); - const actual = df.pivot("b", {index:"a", columns:"a", aggregateFunc:"first", sortColumns:true}); + const actual = df.pivot("b", { + index: "a", + columns: "a", + aggregateFunc: "first", + sortColumns: true, + }); expect(actual).toFrameEqual(expected, true); }); @@ -1061,141 +1183,137 @@ describe("dataframe", () => { describe("join", () => { test("on", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"] + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], }); - const actual = df.join(otherDF, {on: "ham"}); + const actual = df.join(otherDF, { on: "ham" }); const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": [6.0, 7.0], - "ham": ["a", "b"], - "apple": ["x", "y"], + foo: [1, 2], + bar: [6.0, 7.0], + ham: ["a", "b"], + apple: ["x", "y"], }); expect(actual).toFrameEqual(expected); }); test("on:multiple-columns", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo": [1, 10, 11], - + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo: [1, 10, 11], }); - const actual = df.join(otherDF, {on: ["ham", "foo"]}); + const actual = df.join(otherDF, { on: ["ham", "foo"] }); const expected = pl.DataFrame({ - "foo": [1], - "bar": [6.0], - "ham": ["a"], - "apple": ["x"], + foo: [1], + bar: [6.0], + ham: ["a"], + apple: ["x"], }); expect(actual).toFrameEqual(expected); }); test("on:left&right", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], }); const actual = df.join(otherDF, { leftOn: ["foo_left", "ham"], - rightOn: ["foo_right", "ham"] + rightOn: ["foo_right", "ham"], }); const expected = pl.DataFrame({ - "foo_left": [1], - "bar": [6.0], - "ham": ["a"], - "apple": ["x"], + foo_left: [1], + bar: [6.0], + ham: ["a"], + apple: ["x"], }); expect(actual).toFrameEqual(expected); }); test("on:left&right", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], }); const actual = df.join(otherDF, { leftOn: ["foo_left", "ham"], - rightOn: ["foo_right", "ham"] + rightOn: ["foo_right", "ham"], }); const expected = pl.DataFrame({ - "foo_left": [1], - "bar": [6.0], - "ham": ["a"], - "apple": ["x"], + foo_left: [1], + bar: [6.0], + ham: ["a"], + apple: ["x"], }); expect(actual).toFrameEqual(expected); }); test("on throws error if only 'leftOn' is specified", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - - }); - const f = () => df.join(otherDF, { - leftOn: ["foo_left", "ham"], - } as any); + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }); + const f = () => + df.join(otherDF, { + leftOn: ["foo_left", "ham"], + } as any); expect(f).toThrow(TypeError); }); test("on throws error if only 'rightOn' is specified", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - - }); - const f = () => df.join(otherDF, { - rightOn: ["foo_right", "ham"], - } as any); + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }); + const f = () => + df.join(otherDF, { + rightOn: ["foo_right", "ham"], + } as any); expect(f).toThrow(TypeError); }); test("on takes precedence over left&right", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], }); const actual = df.join(otherDF, { on: "ham", @@ -1203,107 +1321,107 @@ describe("join", () => { rightOn: ["foo_right", "ham"], } as any); const expected = pl.DataFrame({ - "foo_left": [1, 2], - "bar": [6.0, 7.0], - "ham": ["a", "b"], - "apple": ["x", "y"], - "foo_right": [1, 10], + foo_left: [1, 2], + bar: [6.0, 7.0], + ham: ["a", "b"], + apple: ["x", "y"], + foo_right: [1, 10], }); expect(actual).toFrameEqual(expected); }); test("how:left", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo": [1, 10, 11], - + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo: [1, 10, 11], }); const actual = df.join(otherDF, { on: "ham", - how: "left" + how: "left", }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], - "apple": ["x", "y", null], - "fooright": [1, 10, null], + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + apple: ["x", "y", null], + fooright: [1, 10, null], }); expect(actual).toFrameEqual(expected); }); test("how:outer", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y"], - "ham": ["a", "d"], - "foo": [1, 10], - + apple: ["x", "y"], + ham: ["a", "d"], + foo: [1, 10], }); const actual = df.join(otherDF, { on: "ham", - how: "outer" + how: "outer", }); const expected = pl.DataFrame({ - "foo": [1, 2, 3, null], - "bar": [6, 7, 8, null], - "ham": ["a", "b", "c", "d"], - "apple": ["x", null, null, "y"], - "fooright": [1, null, null, 10], + foo: [1, 2, 3, null], + bar: [6, 7, 8, null], + ham: ["a", "b", "c", "d"], + apple: ["x", null, null, "y"], + fooright: [1, null, null, 10], }); expect(actual).toFrameEqual(expected); }); test("suffix", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo": [1, 10, 11], - + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo: [1, 10, 11], }); const actual = df.join(otherDF, { on: "ham", how: "left", - suffix: "_other" + suffix: "_other", }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], - "apple": ["x", "y", null], - "foo_other": [1, 10, null], + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + apple: ["x", "y", null], + foo_other: [1, 10, null], }); expect(actual).toFrameEqual(expected); }); test("asof_cross_join", () => { - const left = pl.DataFrame({"a": [-10, 5, 10], "left_val": ["a", "b", "c"]}); - const right = pl.DataFrame({"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]}); + const left = pl.DataFrame({ a: [-10, 5, 10], left_val: ["a", "b", "c"] }); + const right = pl.DataFrame({ + a: [1, 2, 3, 6, 7], + right_val: [1, 2, 3, 6, 7], + }); // only test dispatch of asof join - let out = left.joinAsof(right, {on:"a"}); - expect(out.shape).toEqual({height: 3, width: 3}); + let out = left.joinAsof(right, { on: "a" }); + expect(out.shape).toEqual({ height: 3, width: 3 }); - out = left.lazy().joinAsof(right.lazy(), {on:"a"}).collectSync(); - expect(out.shape).toEqual({height: 3, width: 3}); + out = left.lazy().joinAsof(right.lazy(), { on: "a" }).collectSync(); + expect(out.shape).toEqual({ height: 3, width: 3 }); // only test dispatch of cross join - out = left.join(right, {how:"cross"}); - expect(out.shape).toEqual({height: 15, width: 4}); + out = left.join(right, { how: "cross" }); + expect(out.shape).toEqual({ height: 15, width: 4 }); - left.lazy().join(right.lazy(), {how:"cross"}).collectSync(); - expect(out.shape).toEqual({height: 15, width: 4}); + left.lazy().join(right.lazy(), { how: "cross" }).collectSync(); + expect(out.shape).toEqual({ height: 15, width: 4 }); }); }); describe("io", () => { @@ -1313,31 +1431,33 @@ describe("io", () => { ]); test("writeCSV:string", () => { const actual = df.clone().writeCSV().toString(); - const expected = "foo,bar\n1,6\n2,2\n9,8\n"; + const expected = "foo,bar\n1,6\n2,2\n9,8\n"; expect(actual).toEqual(expected); }); test("writeCSV:string:sep", () => { - const actual = df.clone().writeCSV({sep: "X"}).toString(); - const expected = "fooXbar\n1X6\n2X2\n9X8\n"; + const actual = df.clone().writeCSV({ sep: "X" }).toString(); + const expected = "fooXbar\n1X6\n2X2\n9X8\n"; expect(actual).toEqual(expected); }); test("writeCSV:string:header", () => { - const actual = df.clone().writeCSV({sep: "X", hasHeader: false}).toString(); - const expected = "1X6\n2X2\n9X8\n"; + const actual = df + .clone() + .writeCSV({ sep: "X", hasHeader: false }) + .toString(); + const expected = "1X6\n2X2\n9X8\n"; expect(actual).toEqual(expected); }); test("writeCSV:stream", (done) => { const df = pl.DataFrame([ pl.Series("foo", [1, 2, 3], pl.UInt32), - pl.Series("bar", ["a", "b", "c"]) + pl.Series("bar", ["a", "b", "c"]), ]); let body = ""; const writeStream = new Stream.Writable({ write(chunk, encoding, callback) { body += chunk; callback(null); - - } + }, }); df.writeCSV(writeStream); const newDF = pl.readCSV(body); @@ -1347,7 +1467,7 @@ describe("io", () => { test("writeCSV:path", (done) => { const df = pl.DataFrame([ pl.Series("foo", [1, 2, 3], pl.UInt32), - pl.Series("bar", ["a", "b", "c"]) + pl.Series("bar", ["a", "b", "c"]), ]); df.writeCSV("./test.csv"); const newDF = pl.readCSV("./test.csv"); @@ -1358,21 +1478,21 @@ describe("io", () => { test("JSON.stringify", () => { const df = pl.DataFrame({ foo: [1], - bar: ["a"] + bar: ["a"], }); const expected = JSON.stringify({ columns: [ { name: "foo", datatype: "Float64", - values: [1.0] + values: [1.0], }, { name: "bar", datatype: "Utf8", - values: ["a"] + values: ["a"], }, - ] + ], }); const actual = JSON.stringify(df); expect(actual).toEqual(expected); @@ -1380,18 +1500,16 @@ describe("io", () => { test("toRecords", () => { const df = pl.DataFrame({ foo: [1], - bar: ["a"] + bar: ["a"], }); - const expected = [ - {foo: 1.0, bar: "a"} - ]; + const expected = [{ foo: 1.0, bar: "a" }]; const actual = df.toRecords(); expect(actual).toEqual(expected); }); test("toObject", () => { const expected = { foo: [1], - bar: ["a"] + bar: ["a"], }; const df = pl.DataFrame(expected); @@ -1399,19 +1517,18 @@ describe("io", () => { expect(actual).toEqual(expected); }); test("writeJSON:lines", () => { - const rows = [ - {foo: 1.1}, - {foo: 3.1}, - {foo: 3.1} - ]; - const actual = pl.DataFrame(rows).writeJSON({format:"lines"}).toString(); - const expected = rows.map(r => JSON.stringify(r)).join("\n").concat("\n"); + const rows = [{ foo: 1.1 }, { foo: 3.1 }, { foo: 3.1 }]; + const actual = pl.DataFrame(rows).writeJSON({ format: "lines" }).toString(); + const expected = rows + .map((r) => JSON.stringify(r)) + .join("\n") + .concat("\n"); expect(actual).toEqual(expected); }); test("writeJSON:stream", (done) => { const df = pl.DataFrame([ pl.Series("foo", [1, 2, 3], pl.UInt32), - pl.Series("bar", ["a", "b", "c"]) + pl.Series("bar", ["a", "b", "c"]), ]); let body = ""; @@ -1419,10 +1536,9 @@ describe("io", () => { write(chunk, encoding, callback) { body += chunk; callback(null); - - } + }, }); - df.writeJSON(writeStream, {format:"lines"}); + df.writeJSON(writeStream, { format: "lines" }); const newDF = pl.readJSON(body).select("foo", "bar"); expect(newDF).toFrameEqual(df); done(); @@ -1430,9 +1546,9 @@ describe("io", () => { test("writeJSON:path", (done) => { const df = pl.DataFrame([ pl.Series("foo", [1, 2, 3], pl.UInt32), - pl.Series("bar", ["a", "b", "c"]) + pl.Series("bar", ["a", "b", "c"]), ]); - df.writeJSON("./test.json", {format:"lines"}); + df.writeJSON("./test.json", { format: "lines" }); const newDF = pl.readJSON("./test.json").select("foo", "bar"); expect(newDF).toFrameEqual(df); fs.rmSync("./test.json"); @@ -1440,13 +1556,12 @@ describe("io", () => { }); test("writeJSON:rows", () => { - const rows = [ - {foo: 1.1}, - {foo: 3.1}, - {foo: 3.1} - ]; + const rows = [{ foo: 1.1 }, { foo: 3.1 }, { foo: 3.1 }]; const expected = JSON.stringify(rows); - const actual = pl.readRecords(rows).writeJSON({format:"json"}).toString(); + const actual = pl + .readRecords(rows) + .writeJSON({ format: "json" }) + .toString(); expect(actual).toEqual(expected); }); test("toSeries", () => { @@ -1522,7 +1637,11 @@ describe("create", () => { }); test("from series-array", () => { const s1 = pl.Series("num", [1, 2, 3]); - const s2 = pl.Series("date", [null, Date.now(), Date.now()], pl.Datetime("ms")); + const s2 = pl.Series( + "date", + [null, Date.now(), Date.now()], + pl.Datetime("ms"), + ); const df = pl.DataFrame([s1, s2]); expect(df.getColumn("num")).toSeriesEqual(s1); expect(df.getColumn("date")).toSeriesEqual(s2); @@ -1530,7 +1649,7 @@ describe("create", () => { test("from arrays", () => { const columns = [ [1, 2, 3], - [1, 2, 2] + [1, 2, 2], ]; const df = pl.DataFrame(columns); @@ -1541,10 +1660,10 @@ describe("create", () => { test("from arrays: orient=col", () => { const columns = [ [1, 2, 3], - [1, 2, 2] + [1, 2, 2], ]; - const df = pl.DataFrame(columns, {orient: "col"}); + const df = pl.DataFrame(columns, { orient: "col" }); expect(df.getColumns()[0].toArray()).toEqual(columns[0]); expect(df.getColumns()[1].toArray()).toEqual(columns[1]); @@ -1552,7 +1671,7 @@ describe("create", () => { test("from arrays: orient=row", () => { const rows = [ [1, 2, 3], - [1, 2, 2] + [1, 2, 2], ]; const df = pl.readRecords(rows); @@ -1563,33 +1682,35 @@ describe("create", () => { test("from arrays with column names: orient=col", () => { const columns = [ [1, 2, 3], - [1, 2, 2] + [1, 2, 2], ]; const expectedColumnNames = ["a", "b"]; - const df = pl.DataFrame(columns, {columns: expectedColumnNames, orient: "col"}); + const df = pl.DataFrame(columns, { + columns: expectedColumnNames, + orient: "col", + }); expect(df.getColumns()[0].toArray()).toEqual(columns[0]); expect(df.getColumns()[1].toArray()).toEqual(columns[1]); expect(df.columns).toEqual(expectedColumnNames); - }); test("from arrays: invalid ", () => { const columns = [ [1, 2, 3], - [1, 2, 2] + [1, 2, 2], ]; - const fn = () => pl.DataFrame(columns, {columns: ["a", "b", "c", "d"]}); + const fn = () => pl.DataFrame(columns, { columns: ["a", "b", "c", "d"] }); expect(fn).toThrow(); }); test("from arrays with columns, orient=row", () => { const rows = [ [1, 2, 3], - [1, 2, 2] + [1, 2, 2], ]; const expectedColumns = ["a", "b", "c"]; - const df = pl.DataFrame(rows, {columns: expectedColumns, orient: "row"}); + const df = pl.DataFrame(rows, { columns: expectedColumns, orient: "row" }); expect(df.row(0).sort()).toEqual(rows[0].sort()); expect(df.row(1).sort()).toEqual(rows[1].sort()); @@ -1597,58 +1718,60 @@ describe("create", () => { }); test("from row objects, inferred schema", () => { const rows = [ - {"num": 1, "date": new Date(Date.now()), "string": "foo1"}, - {"num": 1, "date": new Date(Date.now()), "string": 1} + { num: 1, date: new Date(Date.now()), string: "foo1" }, + { num: 1, date: new Date(Date.now()), string: 1 }, ]; const expected = [ rows[0], - {num: 1, date: rows[1].date, string: rows[1].string.toString()} + { num: 1, date: rows[1].date, string: rows[1].string.toString() }, ]; - const df = pl.readRecords(rows, {inferSchemaLength: 1}); + const df = pl.readRecords(rows, { inferSchemaLength: 1 }); expect(df.toRecords()).toEqual(expected); }); test("from row objects, with schema", () => { const rows = [ - {"num": 1, "date": "foo", "string": "foo1"}, - {"num": 1, "date": "foo"} + { num: 1, date: "foo", string: "foo1" }, + { num: 1, date: "foo" }, ]; const expected = [ - {num: 1, date: rows[0].date.toString(), string: "foo1"}, - {num: 1, date: rows[1].date.toString(), string: null} + { num: 1, date: rows[0].date.toString(), string: "foo1" }, + { num: 1, date: rows[1].date.toString(), string: null }, ]; const schema = { num: pl.Int32, date: pl.Utf8, - string: pl.Utf8 + string: pl.Utf8, }; - const df = pl.readRecords(rows, {schema}); + const df = pl.readRecords(rows, { schema }); expect(df.toRecords()).toEqual(expected); expect(df.schema).toEqual(schema); }); test("from nulls", () => { - const df = pl.DataFrame({"nulls": [null, null, null]}); - const expected = pl.DataFrame([pl.Series("nulls", [null, null, null], pl.Float64)]); + const df = pl.DataFrame({ nulls: [null, null, null] }); + const expected = pl.DataFrame([ + pl.Series("nulls", [null, null, null], pl.Float64), + ]); expect(df).toFrameStrictEqual(expected); }); test("from list types", () => { const int8List = [ Int8Array.from([1, 2, 3]), Int8Array.from([2]), - Int8Array.from([1, 1, 1]) + Int8Array.from([1, 1, 1]), ]; const expected: any = { - "num_list": [[1, 2], [], [3, null]], - "bool_list": [[true, null], [], [false]], - "str_list": [["a", null], ["b", "c"], []], - "bigint_list": [[1n], [2n, 3n], []], - "int8_list": int8List + num_list: [[1, 2], [], [3, null]], + bool_list: [[true, null], [], [false]], + str_list: [["a", null], ["b", "c"], []], + bigint_list: [[1n], [2n, 3n], []], + int8_list: int8List, }; - expected.int8_list = int8List.map(i => [...i]); + expected.int8_list = int8List.map((i) => [...i]); const df = pl.DataFrame(expected); expect(df.toObject()).toEqual(expected); @@ -1656,222 +1779,262 @@ describe("create", () => { }); describe("arithmetic", () => { test("add", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).add(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .add(1); const expected = pl.DataFrame({ - "foo": [2, 3, 4], - "bar": [5, 6, 7] + foo: [2, 3, 4], + bar: [5, 6, 7], }); expect(actual).toFrameEqual(expected); }); test("sub", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).sub(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .sub(1); const expected = pl.DataFrame({ - "foo": [0, 1, 2], - "bar": [3, 4, 5] + foo: [0, 1, 2], + bar: [3, 4, 5], }); expect(actual).toFrameEqual(expected); }); test("div", () => { - const actual = pl.DataFrame({ - "foo": [2, 4, 6], - "bar": [2, 2, 2] - }).div(2); + const actual = pl + .DataFrame({ + foo: [2, 4, 6], + bar: [2, 2, 2], + }) + .div(2); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [1, 1, 1] + foo: [1, 2, 3], + bar: [1, 1, 1], }); expect(actual).toFrameEqual(expected); }); test("mul", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).mul(2); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .mul(2); const expected = pl.DataFrame({ - "foo": [2, 4, 6], - "bar": [6, 4, 2] + foo: [2, 4, 6], + bar: [6, 4, 2], }); expect(actual).toFrameEqual(expected); }); test("rem", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).rem(2); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .rem(2); const expected = pl.DataFrame({ - "foo": [1, 0, 1], - "bar": [1, 0, 1] + foo: [1, 0, 1], + bar: [1, 0, 1], }); expect(actual).toFrameEqual(expected); }); test("plus", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).plus(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .plus(1); const expected = pl.DataFrame({ - "foo": [2, 3, 4], - "bar": [5, 6, 7] + foo: [2, 3, 4], + bar: [5, 6, 7], }); expect(actual).toFrameEqual(expected); }); test("minus", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).minus(1); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .minus(1); const expected = pl.DataFrame({ - "foo": [0, 1, 2], - "bar": [3, 4, 5] + foo: [0, 1, 2], + bar: [3, 4, 5], }); expect(actual).toFrameEqual(expected); }); test("divideBy", () => { - const actual = pl.DataFrame({ - "foo": [2, 4, 6], - "bar": [2, 2, 2] - }).divideBy(2); + const actual = pl + .DataFrame({ + foo: [2, 4, 6], + bar: [2, 2, 2], + }) + .divideBy(2); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [1, 1, 1] + foo: [1, 2, 3], + bar: [1, 1, 1], }); expect(actual).toFrameEqual(expected); }); test("multiplyBy", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).multiplyBy(2); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .multiplyBy(2); const expected = pl.DataFrame({ - "foo": [2, 4, 6], - "bar": [6, 4, 2] + foo: [2, 4, 6], + bar: [6, 4, 2], }); expect(actual).toFrameEqual(expected); }); test("modulo", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).modulo(2); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .modulo(2); const expected = pl.DataFrame({ - "foo": [1, 0, 1], - "bar": [1, 0, 1] + foo: [1, 0, 1], + bar: [1, 0, 1], }); expect(actual).toFrameEqual(expected); }); test("add:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).add(pl.Series([3, 2, 1])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .add(pl.Series([3, 2, 1])); const expected = pl.DataFrame({ - "foo": [4, 4, 4], - "bar": [7, 7, 7] + foo: [4, 4, 4], + bar: [7, 7, 7], }); expect(actual).toFrameEqual(expected); }); test("sub:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).sub(pl.Series([1, 2, 3])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .sub(pl.Series([1, 2, 3])); const expected = pl.DataFrame({ - "foo": [0, 0, 0], - "bar": [3, 3, 3] + foo: [0, 0, 0], + bar: [3, 3, 3], }); expect(actual).toFrameEqual(expected); }); test("div:series", () => { - const actual = pl.DataFrame({ - "foo": [2, 4, 6], - "bar": [2, 2, 2] - }).div(pl.Series([2, 2, 1])); + const actual = pl + .DataFrame({ + foo: [2, 4, 6], + bar: [2, 2, 2], + }) + .div(pl.Series([2, 2, 1])); const expected = pl.DataFrame({ - "foo": [1, 2, 6], - "bar": [1, 1, 2] + foo: [1, 2, 6], + bar: [1, 1, 2], }); expect(actual).toFrameEqual(expected); }); test("mul:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).mul(pl.Series([2, 3, 1])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .mul(pl.Series([2, 3, 1])); const expected = pl.DataFrame({ - "foo": [2, 6, 3], - "bar": [6, 6, 1] + foo: [2, 6, 3], + bar: [6, 6, 1], }); expect(actual).toFrameEqual(expected); }); test("rem:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).rem(pl.Series([1, 1, 3])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .rem(pl.Series([1, 1, 3])); const expected = pl.DataFrame({ - "foo": [0, 0, 0], - "bar": [0, 0, 1] + foo: [0, 0, 0], + bar: [0, 0, 1], }); expect(actual).toFrameEqual(expected); }); test("plus:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).plus(pl.Series([3, 2, 1])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .plus(pl.Series([3, 2, 1])); const expected = pl.DataFrame({ - "foo": [4, 4, 4], - "bar": [7, 7, 7] + foo: [4, 4, 4], + bar: [7, 7, 7], }); expect(actual).toFrameEqual(expected); }); test("minus:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6] - }).minus(pl.Series([1, 2, 3])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .minus(pl.Series([1, 2, 3])); const expected = pl.DataFrame({ - "foo": [0, 0, 0], - "bar": [3, 3, 3] + foo: [0, 0, 0], + bar: [3, 3, 3], }); expect(actual).toFrameEqual(expected); }); test("divideBy:series", () => { - const actual = pl.DataFrame({ - "foo": [2, 4, 6], - "bar": [2, 2, 2] - }).divideBy(pl.Series([2, 2, 1])); + const actual = pl + .DataFrame({ + foo: [2, 4, 6], + bar: [2, 2, 2], + }) + .divideBy(pl.Series([2, 2, 1])); const expected = pl.DataFrame({ - "foo": [1, 2, 6], - "bar": [1, 1, 2] + foo: [1, 2, 6], + bar: [1, 1, 2], }); expect(actual).toFrameEqual(expected); }); test("multiplyBy:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).multiplyBy(pl.Series([2, 3, 1])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .multiplyBy(pl.Series([2, 3, 1])); const expected = pl.DataFrame({ - "foo": [2, 6, 3], - "bar": [6, 6, 1] + foo: [2, 6, 3], + bar: [6, 6, 1], }); expect(actual).toFrameEqual(expected); }); test("modulo:series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [3, 2, 1] - }).modulo(pl.Series([1, 1, 3])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [3, 2, 1], + }) + .modulo(pl.Series([1, 1, 3])); const expected = pl.DataFrame({ - "foo": [0, 0, 0], - "bar": [0, 0, 1] + foo: [0, 0, 0], + bar: [0, 0, 1], }); expect(actual).toFrameEqual(expected); }); @@ -1881,36 +2044,36 @@ describe("meta", () => { test("array destructuring", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); const [col0] = df; expect(col0).toSeriesEqual(df.getColumn("os")); - const [,version] = df; + const [, version] = df; expect(version).toSeriesEqual(df.getColumn("version")); - const [[row0Index0], [,row1Index1]] = df; + const [[row0Index0], [, row1Index1]] = df; expect(row0Index0).toStrictEqual("apple"); expect(row1Index1).toStrictEqual(18.04); }); test("object destructuring", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); - const {os, version} = df; + const { os, version } = df; expect(os).toSeriesEqual(df.getColumn("os")); expect(version).toSeriesEqual(df.getColumn("version")); const df2 = pl.DataFrame({ fruits: ["apple", "orange"], - cars: ["ford", "honda"] + cars: ["ford", "honda"], }); - const df3 = pl.DataFrame({...df, ...df2}); + const df3 = pl.DataFrame({ ...df, ...df2 }); const expected = df.hstack(df2); expect(df3).toFrameEqual(expected); }); test("object bracket notation", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); expect(df["os"]).toSeriesEqual(df.getColumn("os")); @@ -1922,7 +2085,7 @@ describe("meta", () => { test("object.keys shows column names", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); const keys = Object.keys(df); expect(keys).toEqual(df.columns); @@ -1930,7 +2093,7 @@ describe("meta", () => { test("object.values shows column values", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); const values = Object.values(df); expect(values[0]).toSeriesEqual(df["os"]); @@ -1939,7 +2102,7 @@ describe("meta", () => { test("df rows", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); const actual = df[0][0]; expect(actual).toStrictEqual(df.getColumn("os").get(0)); @@ -1948,13 +2111,13 @@ describe("meta", () => { test("proxy:has", () => { const df = pl.DataFrame({ os: ["apple", "linux"], - version: [10.12, 18.04] + version: [10.12, 18.04], }); expect("os" in df).toBe(true); }); test("inspect & toString", () => { const df = pl.DataFrame({ - a: [1] + a: [1], }); const expected = `shape: (1, 1) ┌─────┐ @@ -1971,23 +2134,22 @@ describe("meta", () => { }); }); - describe("additional", () => { test("partitionBy", () => { const df = pl.DataFrame({ label: ["a", "a", "b", "b"], - value: [1, 2, 3, 4] + value: [1, 2, 3, 4], }); - const dfs = df.partitionBy(["label"], true).map(df => df.toObject()); + const dfs = df.partitionBy(["label"], true).map((df) => df.toObject()); const expected = [ { label: ["a", "a"], - value: [1, 2] + value: [1, 2], }, { label: ["b", "b"], - value: [3, 4] - } + value: [3, 4], + }, ]; expect(dfs).toEqual(expected); @@ -1995,18 +2157,18 @@ describe("additional", () => { test("partitionBy with callback", () => { const df = pl.DataFrame({ label: ["a", "a", "b", "b"], - value: [1, 2, 3, 4] + value: [1, 2, 3, 4], }); - const dfs = df.partitionBy(["label"], true, df => df.toObject()); + const dfs = df.partitionBy(["label"], true, (df) => df.toObject()); const expected = [ { label: ["a", "a"], - value: [1, 2] + value: [1, 2], }, { label: ["b", "b"], - value: [3, 4] - } + value: [3, 4], + }, ]; expect(dfs).toEqual(expected); diff --git a/__tests__/datelike.test.ts b/__tests__/datelike.test.ts index 9e9faa577..7f8a31956 100644 --- a/__tests__/datelike.test.ts +++ b/__tests__/datelike.test.ts @@ -2,9 +2,9 @@ import pl from "@polars"; describe("datelike", () => { test("asof join", () => { const fmt = "%F %T%.3f"; - const quotes = pl.DataFrame( - { - dates: pl.Series([ + const quotes = pl.DataFrame({ + dates: pl + .Series([ "2016-05-25 13:30:00.023", "2016-05-25 13:30:00.023", "2016-05-25 13:30:00.030", @@ -12,70 +12,54 @@ describe("datelike", () => { "2016-05-25 13:30:00.048", "2016-05-25 13:30:00.049", "2016-05-25 13:30:00.072", - "2016-05-25 13:30:00.075" - ]).str.strptime(pl.Datetime("ms"), fmt), - ticker: [ - "GOOG", - "MSFT", - "MSFT", - "MSFT", - "GOOG", - "AAPL", - "GOOG", - "MSFT", - ], - bid: [ - 720.5, - 51.95, - 51.97, - 51.99, - 720.50, - 97.99, - 720.50, - 52.01 - ], - }); + "2016-05-25 13:30:00.075", + ]) + .str.strptime(pl.Datetime("ms"), fmt), + ticker: ["GOOG", "MSFT", "MSFT", "MSFT", "GOOG", "AAPL", "GOOG", "MSFT"], + bid: [720.5, 51.95, 51.97, 51.99, 720.5, 97.99, 720.5, 52.01], + }); const trades = pl.DataFrame({ - dates: pl.Series([ - "2016-05-25 13:30:00.023", - "2016-05-25 13:30:00.038", - "2016-05-25 13:30:00.048", - "2016-05-25 13:30:00.048", - "2016-05-25 13:30:00.048" - ]).str.strptime(pl.Datetime("ms"), fmt), - ticker: [ - "MSFT", - "MSFT", - "GOOG", - "GOOG", - "AAPL", - ], - bid: [ - 51.95, - 51.95, - 720.77, - 720.92, - 98.0 - ], + dates: pl + .Series([ + "2016-05-25 13:30:00.023", + "2016-05-25 13:30:00.038", + "2016-05-25 13:30:00.048", + "2016-05-25 13:30:00.048", + "2016-05-25 13:30:00.048", + ]) + .str.strptime(pl.Datetime("ms"), fmt), + ticker: ["MSFT", "MSFT", "GOOG", "GOOG", "AAPL"], + bid: [51.95, 51.95, 720.77, 720.92, 98.0], }); - let out: any = trades.joinAsof(quotes, {on: "dates"}); - expect(out.columns).toEqual(["dates", "ticker", "bid", "ticker_right", "bid_right"]); - expect(out.getColumn("dates").cast(pl.Float64) - .div(1000) - .toArray()).toEqual([ - 1464183000023, - 1464183000038, - 1464183000048, - 1464183000048, - 1464183000048, + let out: any = trades.joinAsof(quotes, { on: "dates" }); + expect(out.columns).toEqual([ + "dates", + "ticker", + "bid", + "ticker_right", + "bid_right", ]); - out = trades.joinAsof(quotes, {on:"dates", strategy:"forward"}).getColumn("bid_right") + expect(out.getColumn("dates").cast(pl.Float64).div(1000).toArray()).toEqual( + [ + 1464183000023, 1464183000038, 1464183000048, 1464183000048, + 1464183000048, + ], + ); + out = trades + .joinAsof(quotes, { on: "dates", strategy: "forward" }) + .getColumn("bid_right") .toArray(); expect(out).toEqual([720.5, 51.99, 720.5, 720.5, 720.5]); - out = trades.joinAsof(quotes, {on:"dates", by:"ticker"}); - expect(out.getColumn("bid_right").toArray()).toEqual([51.95, 51.97, 720.5, 720.5, null]); - out = quotes.joinAsof(trades, {on:"dates", by:"ticker"}); + out = trades.joinAsof(quotes, { on: "dates", by: "ticker" }); + expect(out.getColumn("bid_right").toArray()).toEqual([ + 51.95, + 51.97, + 720.5, + 720.5, + null, + ]); + out = quotes.joinAsof(trades, { on: "dates", by: "ticker" }); expect(out.getColumn("bid_right").toArray()).toEqual([ null, 51.95, @@ -86,37 +70,34 @@ describe("datelike", () => { 720.92, 51.95, ]); - out = quotes.joinAsof(trades, {on:"dates", strategy:"backward", tolerance:"5ms"})[ - "bid_right" - ].toArray(); + out = quotes + .joinAsof(trades, { on: "dates", strategy: "backward", tolerance: "5ms" }) + ["bid_right"].toArray(); expect(out).toEqual([51.95, 51.95, null, 51.95, 98.0, 98.0, null, null]); - out = quotes.joinAsof(trades, {on:"dates", strategy:"forward", tolerance:"5ms"})[ - "bid_right" - ].toArray(); + out = quotes + .joinAsof(trades, { on: "dates", strategy: "forward", tolerance: "5ms" }) + ["bid_right"].toArray(); expect(out).toEqual([51.95, 51.95, null, null, 720.77, null, null, null]); }); test("asofjoin tolerance grouper", () => { + const df1 = pl.DataFrame({ + date: [new Date(2020, 1, 5), new Date(2020, 1, 10)], + by: [1, 1], + }); + const df2 = pl.DataFrame({ + date: [new Date(2020, 1, 5), new Date(2020, 1, 6)], + by: [1, 1], + values: [100, 200], + }); - const df1 = pl.DataFrame({"date": [new Date(2020, 1, 5), new Date(2020, 1, 10)], "by": [1, 1]}); - const df2 = pl.DataFrame( - { - "date": [new Date(2020, 1, 5), new Date(2020, 1, 6)], - "by": [1, 1], - "values": [100, 200], - } - ); - - const out = df1.joinAsof(df2, {by: "by", on:"date", tolerance:"3d"}); + const out = df1.joinAsof(df2, { by: "by", on: "date", tolerance: "3d" }); - const expected = pl.DataFrame( - { - "date": [new Date(2020, 1, 5), new Date(2020, 1, 10)], - "by": [1, 1], - "values": [100, null], - } - ); + const expected = pl.DataFrame({ + date: [new Date(2020, 1, 5), new Date(2020, 1, 10)], + by: [1, 1], + values: [100, null], + }); expect(out).toFrameEqual(expected); - }); }); diff --git a/__tests__/expr.test.ts b/__tests__/expr.test.ts index fa407a55c..d7bf84139 100644 --- a/__tests__/expr.test.ts +++ b/__tests__/expr.test.ts @@ -1351,7 +1351,8 @@ describe("expr.lst", () => { expect( df .select(pl.concatList(["a", "b"]).alias("a")) - .getColumn("a").seriesEqual(expected), + .getColumn("a") + .seriesEqual(expected), ).toBeTruthy(); expect( df diff --git a/__tests__/functions.test.ts b/__tests__/functions.test.ts index 5c81fd2f4..ba868a631 100644 --- a/__tests__/functions.test.ts +++ b/__tests__/functions.test.ts @@ -3,17 +3,17 @@ import pl from "@polars"; describe("concat", () => { it("can concat multiple dataframes vertically", () => { const df1 = pl.DataFrame({ - "a": [1, 2, 3], - "b": ["a", "b", "c"] + a: [1, 2, 3], + b: ["a", "b", "c"], }); const df2 = pl.DataFrame({ - "a": [4, 5, 6], - "b": ["d", "e", "f"] + a: [4, 5, 6], + b: ["d", "e", "f"], }); const actual = pl.concat([df1, df2]); const expected = pl.DataFrame({ - "a": [1, 2, 3, 4, 5, 6], - "b": ["a", "b", "c", "d", "e", "f"] + a: [1, 2, 3, 4, 5, 6], + b: ["a", "b", "c", "d", "e", "f"], }); expect(actual).toFrameEqual(expected); }); @@ -36,18 +36,20 @@ describe("concat", () => { expect(fn).toThrowError(); }); test("horizontal concat", () => { - const a = pl.DataFrame({"a": ["a", "b"], "b": [1, 2]}); - const b = pl.DataFrame({"c": [5, 7, 8, 9], "d": [1, 2, 1, 2], "e": [1, 2, 1, 2]}); - const actual = pl.concat([a, b], {how:"horizontal"}); - const expected = pl.DataFrame( - { - "a": ["a", "b", null, null], - "b": [1, 2, null, null], - "c": [5, 7, 8, 9], - "d": [1, 2, 1, 2], - "e": [1, 2, 1, 2], - } - ); + const a = pl.DataFrame({ a: ["a", "b"], b: [1, 2] }); + const b = pl.DataFrame({ + c: [5, 7, 8, 9], + d: [1, 2, 1, 2], + e: [1, 2, 1, 2], + }); + const actual = pl.concat([a, b], { how: "horizontal" }); + const expected = pl.DataFrame({ + a: ["a", "b", null, null], + b: [1, 2, null, null], + c: [5, 7, 8, 9], + d: [1, 2, 1, 2], + e: [1, 2, 1, 2], + }); expect(actual).toFrameEqual(expected); }); }); @@ -55,7 +57,10 @@ describe("repeat", () => { it("repeats a value n number of times into a series", () => { const value = "foobar"; const actual = pl.repeat(value, 4, "foo"); - const expected = pl.Series("foo", Array.from({length: 4}, () => value)); + const expected = pl.Series( + "foo", + Array.from({ length: 4 }, () => value), + ); expect(actual).toSeriesEqual(expected); }); diff --git a/__tests__/groupby.test.ts b/__tests__/groupby.test.ts index d6299e798..8e1627547 100644 --- a/__tests__/groupby.test.ts +++ b/__tests__/groupby.test.ts @@ -1,185 +1,155 @@ import pl from "@polars"; - describe("groupby", () => { let df: pl.DataFrame; beforeEach(() => { df = pl.DataFrame({ - "name": ["a", "b", "a", "c", "b"], - "foo": [1, 3, 3, 5, 7], - "bar": [2, 4, 4, 6, 8] + name: ["a", "b", "a", "c", "b"], + foo: [1, 3, 3, 5, 7], + bar: [2, 4, 4, 6, 8], }); }); test("aggList", () => { const s = pl.Series("a", [1], pl.Int16); - const actual = df - .groupBy("name") - .aggList() - .sort("name"); + const actual = df.groupBy("name").aggList().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [[1, 3], [3, 7], [5]], - "bar": [[2, 4], [4, 8], [6]] + name: ["a", "b", "c"], + foo: [[1, 3], [3, 7], [5]], + bar: [[2, 4], [4, 8], [6]], }); expect(actual).toFrameEqual(expected); }); test("agg:column", () => { - const actual = df.groupBy("name").agg({ - "foo": "min" - }) + const actual = df + .groupBy("name") + .agg({ + foo: "min", + }) .sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [1, 3, 5] + name: ["a", "b", "c"], + foo: [1, 3, 5], }); expect(actual).toFrameEqual(expected); }); test("agg:columns", () => { - const actual = df.groupBy("name").agg({ - "foo": "min", - "bar": "sum" - }) + const actual = df + .groupBy("name") + .agg({ + foo: "min", + bar: "sum", + }) .sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [1, 3, 5], - "bar": [6, 12, 6] + name: ["a", "b", "c"], + foo: [1, 3, 5], + bar: [6, 12, 6], }); expect(actual).toFrameEqual(expected); }); test("count", () => { - const actual = df.groupBy("name").count() - .sort("name"); + const actual = df.groupBy("name").count().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo_count": [2, 2, 1], - "bar_count": [2, 2, 1] + name: ["a", "b", "c"], + foo_count: [2, 2, 1], + bar_count: [2, 2, 1], }); expect(actual).toFrameEqual(expected); }); test("first", () => { - const actual = df.groupBy("name").first() - .sort("name"); + const actual = df.groupBy("name").first().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [1, 3, 5], - "bar": [2, 4, 6] + name: ["a", "b", "c"], + foo: [1, 3, 5], + bar: [2, 4, 6], }); expect(actual).toFrameEqual(expected); }); test("head", () => { - const actual = df - .groupBy("name") - .head(1) - .sort("name"); + const actual = df.groupBy("name").head(1).sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [[1], [3], [5]], - "bar": [[2], [4], [6]] + name: ["a", "b", "c"], + foo: [[1], [3], [5]], + bar: [[2], [4], [6]], }); expect(actual).toFrameEqual(expected); }); test("last", () => { - const actual = df - .groupBy("name") - .last() - .sort("name"); + const actual = df.groupBy("name").last().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [3, 7, 5], - "bar": [4, 8, 6] + name: ["a", "b", "c"], + foo: [3, 7, 5], + bar: [4, 8, 6], }); expect(actual).toFrameEqual(expected); }); test("tail", () => { - const actual = df - .groupBy("name") - .tail(1) - .sort("name"); + const actual = df.groupBy("name").tail(1).sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [[3], [7], [5]], - "bar": [[4], [8], [6]] + name: ["a", "b", "c"], + foo: [[3], [7], [5]], + bar: [[4], [8], [6]], }); expect(actual).toFrameEqual(expected); }); test("max", () => { - const actual = df - .groupBy("name") - .max() - .sort("name"); + const actual = df.groupBy("name").max().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [3, 7, 5], - "bar": [4, 8, 6] + name: ["a", "b", "c"], + foo: [3, 7, 5], + bar: [4, 8, 6], }); expect(actual).toFrameEqual(expected); }); test("mean", () => { - const actual = df - .groupBy("name") - .mean() - .sort("name"); + const actual = df.groupBy("name").mean().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [2, 5, 5], - "bar": [3, 6, 6] + name: ["a", "b", "c"], + foo: [2, 5, 5], + bar: [3, 6, 6], }); expect(actual).toFrameEqual(expected); }); test("median", () => { - const actual = df - .groupBy("name") - .median() - .sort("name"); + const actual = df.groupBy("name").median().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [2, 5, 5], - "bar": [3, 6, 6] + name: ["a", "b", "c"], + foo: [2, 5, 5], + bar: [3, 6, 6], }); expect(actual).toFrameEqual(expected); }); test("min", () => { - const actual = df - .groupBy("name") - .min() - .sort("name"); + const actual = df.groupBy("name").min().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [1, 3, 5], - "bar": [2, 4, 6] + name: ["a", "b", "c"], + foo: [1, 3, 5], + bar: [2, 4, 6], }); expect(actual).toFrameEqual(expected); }); test("nUnique", () => { - const actual = df - .groupBy("name") - .nUnique() - .sort("name"); + const actual = df.groupBy("name").nUnique().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [2, 2, 1], - "bar": [2, 2, 1] + name: ["a", "b", "c"], + foo: [2, 2, 1], + bar: [2, 2, 1], }); expect(actual).toFrameEqual(expected); }); test("sum", () => { - const actual = df - .groupBy("name") - .sum() - .sort("name"); + const actual = df.groupBy("name").sum().sort("name"); const expected = pl.DataFrame({ - "name": ["a", "b", "c"], - "foo": [4, 10, 5], - "bar": [6, 12, 6] + name: ["a", "b", "c"], + foo: [4, 10, 5], + bar: [6, 12, 6], }); expect(actual).toFrameEqual(expected); }); test.todo("groups"); - }); describe("groupby ops", () => { test("rolling", () => { @@ -193,41 +163,37 @@ describe("groupby ops", () => { ]; const df = pl - .DataFrame({"dt": dates, "a": [3, 7, 5, 9, 2, 1]}) + .DataFrame({ dt: dates, a: [3, 7, 5, 9, 2, 1] }) .withColumn(pl.col("dt").str.strptime(pl.Datetime("ms"))); const a = pl.col("a"); - const out = df.groupByRolling({indexColumn:"dt", period:"2d"}).agg( - a.sum().as("sum_a"), - a.min().as("min_a"), - a.max().as("max_a"), - ); + const out = df + .groupByRolling({ indexColumn: "dt", period: "2d" }) + .agg(a.sum().as("sum_a"), a.min().as("min_a"), a.max().as("max_a")); expect(out["sum_a"].toArray()).toEqual([3, 10, 15, 24, 11, 1]); expect(out["max_a"].toArray()).toEqual([3, 7, 7, 9, 9, 1]); expect(out["min_a"].toArray()).toEqual([3, 3, 3, 3, 2, 1]); }); test("dynamic - 1", () => { const df = pl.DataFrame({ - "event_date": [ + event_date: [ new Date("2021-04-11"), new Date("2021-04-29"), new Date("2021-05-29"), ], - "adm1_code": [1, 2, 1], - "five_type": ["a", "b", "a"], - "actor": ["a", "a", "a"], - "admin": ["a", "a", "a"], - "fatalities": [10, 20, 30], + adm1_code: [1, 2, 1], + five_type: ["a", "b", "a"], + actor: ["a", "a", "a"], + admin: ["a", "a", "a"], + fatalities: [10, 20, 30], }); - const out = df.groupByDynamic({ - by: ["admin", "five_type", "actor"], - indexColumn: "event_date", - every: "1mo", - }).agg( - pl.col("adm1_code").unique(), - pl.col("fatalities").gt(0) - .sum() - ); + const out = df + .groupByDynamic({ + by: ["admin", "five_type", "actor"], + indexColumn: "event_date", + every: "1mo", + }) + .agg(pl.col("adm1_code").unique(), pl.col("fatalities").gt(0).sum()); const expected = [ new Date("2021-04-01"), new Date("2021-05-01"), @@ -235,33 +201,27 @@ describe("groupby ops", () => { ]; const actual = out.getColumn("event_date"); expect(actual.toArray()).toEqual(expected); - }); test("dynamic - 2", () => { - const df = pl.DataFrame( - { - "event_date": [ - new Date("2021-04-11"), - new Date("2021-04-29"), - new Date("2021-05-29"), - ], - "adm1_code": [1, 2, 1], - "five_type": ["a", "b", "a"], - "actor": ["a", "a", "a"], - "admin": ["a", "a", "a"], - "fatalities": [10, 20, 30], - } - ); - const out = df.groupByDynamic({ - indexColumn: "event_date", - every: "1mo", - by: ["admin", "five_type", "actor"] - }).agg( - pl.col("adm1_code").unique(), - pl.col("fatalities") - .gt(0) - .sum() - ); + const df = pl.DataFrame({ + event_date: [ + new Date("2021-04-11"), + new Date("2021-04-29"), + new Date("2021-05-29"), + ], + adm1_code: [1, 2, 1], + five_type: ["a", "b", "a"], + actor: ["a", "a", "a"], + admin: ["a", "a", "a"], + fatalities: [10, 20, 30], + }); + const out = df + .groupByDynamic({ + indexColumn: "event_date", + every: "1mo", + by: ["admin", "five_type", "actor"], + }) + .agg(pl.col("adm1_code").unique(), pl.col("fatalities").gt(0).sum()); const expected = [ new Date("2021-04-01"), new Date("2021-05-01"), @@ -277,19 +237,24 @@ describe("groupby ops", () => { new Date("2020-02-01"), new Date("2020-03-01"), ]; - const df = pl.DataFrame({dt: dates, idx: Array.from({length: dates.length}, (_v, k) => k)}); - const actual = df.groupByDynamic({ - indexColumn: "dt", - every: "1mo", - closed: "right" - }).agg(pl.col("idx")); + const df = pl.DataFrame({ + dt: dates, + idx: Array.from({ length: dates.length }, (_v, k) => k), + }); + const actual = df + .groupByDynamic({ + indexColumn: "dt", + every: "1mo", + closed: "right", + }) + .agg(pl.col("idx")); const expected = pl.DataFrame({ - "dt": [ + dt: [ new Date("2019-12-01"), new Date("2020-01-01"), new Date("2020-02-01"), ], - "idx": [[0], [1, 2], [3]], + idx: [[0], [1, 2], [3]], }); expect(actual).toFrameEqual(expected); }); diff --git a/__tests__/io.test.ts b/__tests__/io.test.ts index ca7c0512f..daea0c1dc 100644 --- a/__tests__/io.test.ts +++ b/__tests__/io.test.ts @@ -1,6 +1,6 @@ import pl from "@polars"; import path from "path"; -import {Stream} from "stream"; +import { Stream } from "stream"; import fs from "fs"; // eslint-disable-next-line no-undef const csvpath = path.resolve(__dirname, "./examples/datasets/foods1.csv"); @@ -15,35 +15,36 @@ const jsonpath = path.resolve(__dirname, "./examples/foods.json"); describe("read:csv", () => { it("can read from a csv file", () => { const df = pl.readCSV(csvpath); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can read from a relative file", () => { const df = pl.readCSV(csvpath); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can read from a csv file with options", () => { - const df = pl.readCSV(csvpath, {hasHeader: false, skipRows: 1, nRows: 4}); - expect(df.shape).toEqual({height: 4, width: 4}); + const df = pl.readCSV(csvpath, { hasHeader: false, skipRows: 1, nRows: 4 }); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); it("can read from a csv string", () => { const csvString = "foo,bar,baz\n1,2,3\n4,5,6\n"; const df = pl.readCSV(csvString); - expect(df.toCSV().toString() - .slice(0, 22)).toEqual(csvString.slice(0, 22)); + expect(df.toCSV().toString().slice(0, 22)).toEqual(csvString.slice(0, 22)); }); it("can read from a csv buffer", () => { const csvBuffer = Buffer.from("foo,bar,baz\n1,2,3\n4,5,6\n", "utf-8"); const df = pl.readCSV(csvBuffer); - expect(df.toCSV().toString("utf-8") - .slice(0, 22)).toEqual(csvBuffer.toString("utf-8").slice(0, 22)); + expect(df.toCSV().toString("utf-8").slice(0, 22)).toEqual( + csvBuffer.toString("utf-8").slice(0, 22), + ); }); it("can read from a csv buffer with options", () => { const csvBuffer = Buffer.from("foo,bar,baz\n1,2,3\n4,5,6\n", "utf-8"); - const df = pl.readCSV(csvBuffer, {hasHeader: true, chunkSize: 10}); + const df = pl.readCSV(csvBuffer, { hasHeader: true, chunkSize: 10 }); // the newline characters are confusing jest - expect(df.toCSV().toString("utf-8") - .slice(0, 22)).toEqual(csvBuffer.toString("utf-8").slice(0, 22)); + expect(df.toCSV().toString("utf-8").slice(0, 22)).toEqual( + csvBuffer.toString("utf-8").slice(0, 22), + ); }); it("can parse datetimes", () => { const csv = `timestamp,open,high @@ -51,26 +52,29 @@ describe("read:csv", () => { 2021-01-01 00:15:00,0.00298800,0.00300400 2021-01-01 00:30:00,0.00298300,0.00300100 2021-01-01 00:45:00,0.00299400,0.00304000`; - const df = pl.readCSV(csv, {parseDates: true}); - expect(df.dtypes.map(dt => dt.toJSON())).toEqual([pl.Datetime("us").toJSON(), pl.Float64.toJSON(), pl.Float64.toJSON()]); + const df = pl.readCSV(csv, { parseDates: true }); + expect(df.dtypes.map((dt) => dt.toJSON())).toEqual([ + pl.Datetime("us").toJSON(), + pl.Float64.toJSON(), + pl.Float64.toJSON(), + ]); }); it.each` - csv | nullValues - ${"a,b,c\nna,b,c\na,na,c"} | ${"na"} - ${"a,b,c\nna,b,c\na,n/a,c"} | ${["na", "n/a"]} - ${"a,b,c\nna,b,c\na,n/a,c"} | ${{"a": "na", "b": "n/a"}} - `("can handle null values", ({csv, nullValues}) => { - const df = pl.readCSV(csv, {nullValues}); + csv | nullValues + ${"a,b,c\nna,b,c\na,na,c"} | ${"na"} + ${"a,b,c\nna,b,c\na,n/a,c"} | ${["na", "n/a"]} + ${"a,b,c\nna,b,c\na,n/a,c"} | ${{ a: "na", b: "n/a" }} + `("can handle null values", ({ csv, nullValues }) => { + const df = pl.readCSV(csv, { nullValues }); expect(df.getColumn("a")[0]).toBeNull(); expect(df.getColumn("b")[1]).toBeNull(); }); test("csv with rowcount", () => { - const df = pl.readCSV(csvpath, {rowCount: {name: "rc", offset: 11}}); + const df = pl.readCSV(csvpath, { rowCount: { name: "rc", offset: 11 } }); const expectedMaxRowCount = df.height + 10; const maxRowCount = df.getColumn("rc").max(); expect(expectedMaxRowCount).toStrictEqual(maxRowCount); - }); it.todo("can read from a stream"); }); @@ -78,73 +82,72 @@ describe("read:csv", () => { describe("read:json", () => { it("can read from a json file", () => { const df = pl.readJSON(jsonpath); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can specify read options", () => { - const df = pl.readJSON(jsonpath, {batchSize: 10, inferSchemaLength: 100}); - expect(df.shape).toEqual({height: 27, width: 4}); + const df = pl.readJSON(jsonpath, { batchSize: 10, inferSchemaLength: 100 }); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can read from a json buffer", () => { const json = [ - JSON.stringify({bar: "1", foo: 1}), - JSON.stringify({bar: "1", foo: 2}), - "" + JSON.stringify({ bar: "1", foo: 1 }), + JSON.stringify({ bar: "1", foo: 2 }), + "", ].join("\n"); const df = pl.readJSON(Buffer.from(json)); - expect(df.writeJSON({format:"lines"}).toString() - .slice(0, 30)).toEqual(json.slice(0, 30)); - + expect(df.writeJSON({ format: "lines" }).toString().slice(0, 30)).toEqual( + json.slice(0, 30), + ); }); }); describe("scan", () => { it("can lazy load (scan) from a csv file", () => { const df = pl.scanCSV(csvpath).collectSync(); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can lazy load (scan) from a json file", () => { const df = pl.scanJson(jsonpath).collectSync(); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can lazy load (scan) from a csv file with options", () => { const df = pl .scanCSV(csvpath, { hasHeader: false, skipRows: 1, - nRows: 4 + nRows: 4, }) .collectSync(); - expect(df.shape).toEqual({height: 4, width: 4}); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); it("can lazy load (scan) from a ipc file", () => { const df = pl.scanCSV(csvpath).collectSync(); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); it("can lazy load (scan) from a csv file with options", () => { const df = pl .scanCSV(csvpath, { hasHeader: false, skipRows: 1, - nRows: 4 + nRows: 4, }) .collectSync(); - expect(df.shape).toEqual({height: 4, width: 4}); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); it("can lazy load (scan) from a parquet file with options", () => { - pl - .readCSV(csvpath, { - hasHeader: false, - skipRows: 1, - nRows: 4 - }).writeParquet(parquetpath); + pl.readCSV(csvpath, { + hasHeader: false, + skipRows: 1, + nRows: 4, + }).writeParquet(parquetpath); const df = pl.scanParquet(parquetpath).collectSync(); - expect(df.shape).toEqual({height: 4, width: 4}); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); }); @@ -158,34 +161,34 @@ describe("parquet", () => { test("read", () => { const df = pl.readParquet(parquetpath); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("read:buffer", () => { const buff = fs.readFileSync(parquetpath); const df = pl.readParquet(buff); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("read:compressed", () => { const csvDF = pl.readCSV(csvpath); - csvDF.writeParquet(parquetpath, {compression: "lz4"}); + csvDF.writeParquet(parquetpath, { compression: "lz4" }); const df = pl.readParquet(parquetpath); expect(df).toFrameEqual(csvDF); }); test("read:options", () => { - const df = pl.readParquet(parquetpath, {numRows: 4}); - expect(df.shape).toEqual({height: 4, width: 4}); + const df = pl.readParquet(parquetpath, { numRows: 4 }); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); test("scan", () => { const df = pl.scanParquet(parquetpath).collectSync(); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("scan:options", () => { - const df = pl.scanParquet(parquetpath, {numRows: 4}).collectSync(); - expect(df.shape).toEqual({height: 4, width: 4}); + const df = pl.scanParquet(parquetpath, { numRows: 4 }).collectSync(); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); }); @@ -199,34 +202,33 @@ describe("ipc", () => { test("read", () => { const df = pl.readIPC(ipcpath); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("read/write:buffer", () => { - - const buff = pl.readCSV(csvpath).writeIPC(); + const buff = pl.readCSV(csvpath).writeIPC(); const df = pl.readIPC(buff); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("read:compressed", () => { const csvDF = pl.readCSV(csvpath); - csvDF.writeIPC(ipcpath, {compression: "lz4"}); + csvDF.writeIPC(ipcpath, { compression: "lz4" }); const ipcDF = pl.readIPC(ipcpath); expect(ipcDF).toFrameEqual(csvDF); }); test.skip("read:options", () => { - const df = pl.readIPC(ipcpath, {nRows: 4}); - expect(df.shape).toEqual({height: 4, width: 4}); + const df = pl.readIPC(ipcpath, { nRows: 4 }); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); test("scan", () => { const df = pl.scanIPC(ipcpath).collectSync(); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test.skip("scan:options", () => { - const df = pl.scanIPC(ipcpath, {nRows: 4}).collectSync(); - expect(df.shape).toEqual({height: 4, width: 4}); + const df = pl.scanIPC(ipcpath, { nRows: 4 }).collectSync(); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); test("writeIPC", () => { @@ -235,10 +237,8 @@ describe("ipc", () => { const ipcDF = pl.readIPC(ipcpath); expect(ipcDF).toFrameEqual(csvDF); }); - }); - describe("avro", () => { beforeEach(() => { pl.readCSV(csvpath).writeAvro(avropath); @@ -250,7 +250,7 @@ describe("avro", () => { test("round trip", () => { const expected = pl.DataFrame({ foo: [1, 2, 3], - bar: ["a", "b", "c"] + bar: ["a", "b", "c"], }); const buf = expected.writeAvro(); const actual = pl.readAvro(buf); @@ -258,83 +258,85 @@ describe("avro", () => { }); test("read", () => { const df = pl.readAvro(avropath); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("read:buffer", () => { const buff = fs.readFileSync(avropath); const df = pl.readAvro(buff); - expect(df.shape).toEqual({height: 27, width: 4}); + expect(df.shape).toEqual({ height: 27, width: 4 }); }); test("read:compressed", () => { const csvDF = pl.readCSV(csvpath); - csvDF.writeAvro(avropath, {compression: "snappy"}); + csvDF.writeAvro(avropath, { compression: "snappy" }); const df = pl.readAvro(avropath); expect(df).toFrameEqual(csvDF); }); test.skip("read:options", () => { - const df = pl.readAvro(avropath, {nRows: 4}); - expect(df.shape).toEqual({height: 4, width: 4}); + const df = pl.readAvro(avropath, { nRows: 4 }); + expect(df.shape).toEqual({ height: 4, width: 4 }); }); }); describe("stream", () => { test("readCSV", async () => { - const readStream = new Stream.Readable({read(){}}); - readStream.push(`a,b\n`); - readStream.push(`1,2\n`); - readStream.push(`2,2\n`); - readStream.push(`3,2\n`); - readStream.push(`4,2\n`); + const readStream = new Stream.Readable({ read() {} }); + readStream.push("a,b\n"); + readStream.push("1,2\n"); + readStream.push("2,2\n"); + readStream.push("3,2\n"); + readStream.push("4,2\n"); readStream.push(null); const expected = pl.DataFrame({ a: pl.Series("a", [1, 2, 3, 4], pl.Int64), - b: pl.Series("b", [2, 2, 2, 2], pl.Int64) + b: pl.Series("b", [2, 2, 2, 2], pl.Int64), }); - const df = await pl.readCSVStream(readStream, {chunkSize: 2}); + const df = await pl.readCSVStream(readStream, { chunkSize: 2 }); expect(df).toFrameEqual(expected); }); test("readCSV:schema mismatch", async () => { - const readStream = new Stream.Readable({read(){}}); - readStream.push(`a,b,c\n`); - readStream.push(`1,2\n`); - readStream.push(`2,2\n`); - readStream.push(`3,2\n`); - readStream.push(`11,1,2,3,4,5,1\n`); - readStream.push(`null`); + const readStream = new Stream.Readable({ read() {} }); + readStream.push("a,b,c\n"); + readStream.push("1,2\n"); + readStream.push("2,2\n"); + readStream.push("3,2\n"); + readStream.push("11,1,2,3,4,5,1\n"); + readStream.push("null"); readStream.push(null); - const promise = pl.readCSVStream(readStream, {inferSchemaLength: 2, ignoreErrors: false}); + const promise = pl.readCSVStream(readStream, { + inferSchemaLength: 2, + ignoreErrors: false, + }); await expect(promise).rejects.toBeDefined(); }); test("readJSON", async () => { - const readStream = new Stream.Readable({read(){}}); - readStream.push(`${JSON.stringify({a: 1, b: 2})} \n`); - readStream.push(`${JSON.stringify({a: 2, b: 2})} \n`); - readStream.push(`${JSON.stringify({a: 3, b: 2})} \n`); - readStream.push(`${JSON.stringify({a: 4, b: 2})} \n`); + const readStream = new Stream.Readable({ read() {} }); + readStream.push(`${JSON.stringify({ a: 1, b: 2 })} \n`); + readStream.push(`${JSON.stringify({ a: 2, b: 2 })} \n`); + readStream.push(`${JSON.stringify({ a: 3, b: 2 })} \n`); + readStream.push(`${JSON.stringify({ a: 4, b: 2 })} \n`); readStream.push(null); const expected = pl.DataFrame({ a: pl.Series("a", [1, 2, 3, 4], pl.Int64), - b: pl.Series("b", [2, 2, 2, 2], pl.Int64) + b: pl.Series("b", [2, 2, 2, 2], pl.Int64), }); const df = await pl.readJSONStream(readStream); expect(df).toFrameEqual(expected); }); test.skip("readJSON:error", async () => { - const readStream = new Stream.Readable({read(){}}); - readStream.push(`${JSON.stringify({a: 1, b: 2})} \n`); - readStream.push(`${JSON.stringify({a: 2, b: 2})} \n`); - readStream.push(`${JSON.stringify({a: 3, b: 2})} \n`); - readStream.push(`not parseable json `); + const readStream = new Stream.Readable({ read() {} }); + readStream.push(`${JSON.stringify({ a: 1, b: 2 })} \n`); + readStream.push(`${JSON.stringify({ a: 2, b: 2 })} \n`); + readStream.push(`${JSON.stringify({ a: 3, b: 2 })} \n`); + readStream.push("not parseable json "); readStream.push(null); await expect(pl.readJSONStream(readStream)).rejects.toBeDefined(); - }); }); diff --git a/__tests__/lazy_functions.test.ts b/__tests__/lazy_functions.test.ts index 0dc0f5d49..e86e9be07 100644 --- a/__tests__/lazy_functions.test.ts +++ b/__tests__/lazy_functions.test.ts @@ -1,142 +1,163 @@ -import pl, {col, cols, lit} from "@polars/index"; -import {df as _df} from "./setup"; +import pl, { col, cols, lit } from "@polars/index"; +import { df as _df } from "./setup"; describe("lazy functions", () => { test("col:string", () => { const expected = pl.Series("foo", [1, 2, 3]); const other = pl.Series("other", [1, 2, 3]); - const df = pl.DataFrame([ - expected, - other - ]); + const df = pl.DataFrame([expected, other]); const actual = df.select(col("foo")); expect(actual).toFrameEqual(expected.toFrame()); }); test("col:string[]", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - "other": ["a", "b", "c"] - }).select(col(["foo", "bar"])); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + other: ["a", "b", "c"], + }) + .select(col(["foo", "bar"])); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], + foo: [1, 2, 3], + bar: [4, 5, 6], }); expect(actual).toFrameEqual(expected); }); test("col:series", () => { const columnsToSelect = pl.Series(["foo", "bar"]); - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - "other": ["a", "b", "c"] - }).select(col(columnsToSelect)); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + other: ["a", "b", "c"], + }) + .select(col(columnsToSelect)); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], + foo: [1, 2, 3], + bar: [4, 5, 6], }); expect(actual).toFrameEqual(expected); }); test("cols", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - "other": ["a", "b", "c"] - }).select(cols("foo", "bar")); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + other: ["a", "b", "c"], + }) + .select(cols("foo", "bar")); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], + foo: [1, 2, 3], + bar: [4, 5, 6], }); expect(actual).toFrameEqual(expected); }); describe("lit", () => { test("string", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - }).select(col("foo"), lit("a").as("lit_a")); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .select(col("foo"), lit("a").as("lit_a")); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "lit_a": ["a", "a", "a"], + foo: [1, 2, 3], + lit_a: ["a", "a", "a"], }); expect(actual).toFrameEqual(expected); }); test("number", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - }).select(col("foo"), lit(-99).as("number")); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .select(col("foo"), lit(-99).as("number")); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "number": [-99, -99, -99], + foo: [1, 2, 3], + number: [-99, -99, -99], }); expect(actual).toFrameEqual(expected); }); test("bigint", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - }).select(col("foo"), lit(999283899189222n).as("bigint")); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .select(col("foo"), lit(999283899189222n).as("bigint")); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bigint": [999283899189222n, 999283899189222n, 999283899189222n], + foo: [1, 2, 3], + bigint: [999283899189222n, 999283899189222n, 999283899189222n], }); expect(actual).toFrameEqual(expected); }); test("series", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - }).select(col("foo"), lit(pl.Series(["one", "two", "three"])).as("series:string")); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .select( + col("foo"), + lit(pl.Series(["one", "two", "three"])).as("series:string"), + ); const expected = pl.DataFrame({ - "foo": [1, 2, 3], + foo: [1, 2, 3], "series:string": ["one", "two", "three"], }); expect(actual).toFrameEqual(expected); }); test("null", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [4, 5, 6], - }).select(col("foo"), lit(null).as("nulls")); + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [4, 5, 6], + }) + .select(col("foo"), lit(null).as("nulls")); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "nulls": [null, null, null], + foo: [1, 2, 3], + nulls: [null, null, null], }); expect(actual).toFrameEqual(expected); }); }); test("arange:positional", () => { const df = pl.DataFrame({ - "foo": [1, 1, 1], + foo: [1, 1, 1], }); - const expected = pl.DataFrame({"foo": [1, 1]}); + const expected = pl.DataFrame({ foo: [1, 1] }); const actual = df.filter(pl.col("foo").gtEq(pl.arange(0, 3))); expect(actual).toFrameEqual(expected); }); test("arange:named", () => { const df = pl.DataFrame({ - "foo": [1, 1, 1], + foo: [1, 1, 1], }); - const expected = pl.DataFrame({"foo": [1, 1]}); - const actual = df.filter(pl.col("foo").gtEq(pl.arange({low: 0, high: 3}))); + const expected = pl.DataFrame({ foo: [1, 1] }); + const actual = df.filter( + pl.col("foo").gtEq(pl.arange({ low: 0, high: 3 })), + ); expect(actual).toFrameEqual(expected); }); test("arange:eager", () => { const df = pl.DataFrame({ - "foo": [1, 1, 1], + foo: [1, 1, 1], }); - const expected = pl.DataFrame({"foo": [1, 1]}); - const actual = df.filter(pl.col("foo").gtEq(pl.arange({low: 0, high: 3, eager: true}))); + const expected = pl.DataFrame({ foo: [1, 1] }); + const actual = df.filter( + pl.col("foo").gtEq(pl.arange({ low: 0, high: 3, eager: true })), + ); expect(actual).toFrameEqual(expected); }); test.skip("argSortBy", () => { - const actual = _df().select(pl.argSortBy(["int_nulls", "floats"], [false, true])) + const actual = _df() + .select(pl.argSortBy(["int_nulls", "floats"], [false, true])) .getColumn("int_nulls"); }); test("avg", () => { - const df = pl.DataFrame({"foo": [4, 5, 6, 4, 5, 6]}); + const df = pl.DataFrame({ foo: [4, 5, 6, 4, 5, 6] }); const expected = pl.select(lit(5).as("foo")); const actual = df.select(pl.avg("foo")); @@ -156,7 +177,9 @@ describe("lazy functions", () => { const s1 = pl.Series("b", ["d", "e", "f"]); const expected = pl.Series("concat", ["a,d", "b,e", "c,f"]); const df = pl.DataFrame([s0, s1]); - const actual = df.select(pl.concatString(["a", "b"]).as("concat")).getColumn("concat"); + const actual = df + .select(pl.concatString(["a", "b"]).as("concat")) + .getColumn("concat"); expect(actual).toSeriesEqual(expected); }); test("concatString:sep", () => { @@ -164,7 +187,9 @@ describe("lazy functions", () => { const s1 = pl.Series("b", ["d", "e", "f"]); const expected = pl.Series("concat", ["a=d", "b=e", "c=f"]); const df = pl.DataFrame([s0, s1]); - const actual = df.select(pl.concatString(["a", "b"], "=").as("concat")).getColumn("concat"); + const actual = df + .select(pl.concatString(["a", "b"], "=").as("concat")) + .getColumn("concat"); expect(actual).toSeriesEqual(expected); }); test("concatString:named", () => { @@ -172,7 +197,9 @@ describe("lazy functions", () => { const s1 = pl.Series("b", ["d", "e", "f"]); const expected = pl.Series("concat", ["a=d", "b=e", "c=f"]); const df = pl.DataFrame([s0, s1]); - const actual = df.select(pl.concatString({exprs: ["a", "b"], sep: "="}).as("concat")).getColumn("concat"); + const actual = df + .select(pl.concatString({ exprs: ["a", "b"], sep: "=" }).as("concat")) + .getColumn("concat"); expect(actual).toSeriesEqual(expected); }); test("count:series", () => { @@ -184,11 +211,7 @@ describe("lazy functions", () => { test("count:column", () => { const s0 = pl.Series("a", [1, 2, 3, 4, 5]).cast(pl.Int32); const s1 = pl.Series("b", [11, 22, 33, 44, 55]).cast(pl.Int32); - const expected = pl.select( - lit(5) - .cast(pl.Int32) - .as("a") - ); + const expected = pl.select(lit(5).cast(pl.Int32).as("a")); const actual = pl.DataFrame([s0, s1]).select(pl.count("a")); expect(actual).toFrameEqual(expected); }); @@ -227,9 +250,7 @@ describe("lazy functions", () => { pl.Series("B", [5, 4, 3, 2, 1]), pl.Series("C", ["a", "b", "c", "d", "e"]), ]); - const expected = pl.DataFrame([ - pl.Series("C", ["a", "b", "c", "d", "e"]), - ]); + const expected = pl.DataFrame([pl.Series("C", ["a", "b", "c", "d", "e"])]); const actual = df.select(pl.exclude("A", "B")); expect(actual).toFrameEqual(expected); }); @@ -239,8 +260,7 @@ describe("lazy functions", () => { expect(actual).toStrictEqual(1); }); test("first:df", () => { - const actual = _df().select(pl.first("bools")) - .row(0)[0]; + const actual = _df().select(pl.first("bools")).row(0)[0]; expect(actual).toStrictEqual(false); }); test("first:invalid", () => { @@ -249,26 +269,33 @@ describe("lazy functions", () => { expect(fn).toThrow(); }); test("format:tag", () => { - const df = pl.DataFrame({ - "a": ["a", "b", "c"], - "b": [1, 2, 3], + const df = pl.DataFrame({ + a: ["a", "b", "c"], + b: [1, 2, 3], }); - const expected = pl.DataFrame({"eq": ["a=a;b=1.0", "a=b;b=2.0", "a=c;b=3.0"]}); - const actual = df.select(pl.format`${lit("a")}=${col("a")};b=${col("b")}`.as("eq")); + const expected = pl.DataFrame({ + eq: ["a=a;b=1.0", "a=b;b=2.0", "a=c;b=3.0"], + }); + const actual = df.select( + pl.format`${lit("a")}=${col("a")};b=${col("b")}`.as("eq"), + ); expect(actual).toFrameEqual(expected); }); test("format:pattern", () => { - const df = pl.DataFrame({ - "a": ["a", "b", "c"], - "b": [1, 2, 3], + const df = pl.DataFrame({ + a: ["a", "b", "c"], + b: [1, 2, 3], }); const fmt = pl.format("{}={};b={}", lit("a"), col("a"), col("b")).as("eq"); - const expected = pl.DataFrame({"eq": ["a=a;b=1.0", "a=b;b=2.0", "a=c;b=3.0"]}); + const expected = pl.DataFrame({ + eq: ["a=a;b=1.0", "a=b;b=2.0", "a=c;b=3.0"], + }); const actual = df.select(fmt); expect(actual).toFrameEqual(expected); }); test("format:invalid", () => { - const fn = () => pl.format("{}{}={};b={}", lit("a"), col("a"), col("b")).as("eq"); + const fn = () => + pl.format("{}{}={};b={}", lit("a"), col("a"), col("b")).as("eq"); expect(fn).toThrow(); }); test("head:series", () => { @@ -278,12 +305,12 @@ describe("lazy functions", () => { }); test("head:df", () => { const df = pl.DataFrame({ - "a": [1, 2, 5], - "b": ["foo", "bar", "baz"] + a: [1, 2, 5], + b: ["foo", "bar", "baz"], }); const expected = pl.DataFrame({ - "a": [1], - "b": ["foo"] + a: [1], + b: ["foo"], }); const actual = df.select(pl.head("*", 1)); @@ -291,12 +318,12 @@ describe("lazy functions", () => { }); test("head:expr", () => { const df = pl.DataFrame({ - "a": [1, 2, 5], - "b": ["foo", "bar", "baz"] + a: [1, 2, 5], + b: ["foo", "bar", "baz"], }); const expected = pl.DataFrame({ - "a": [1], - "b": ["foo"] + a: [1], + b: ["foo"], }); const actual = df.select(pl.head(col("*"), 1)); @@ -308,16 +335,16 @@ describe("lazy functions", () => { }); test("last:string", () => { const df = pl.DataFrame({ - "a": [1, 2, 5], - "b": ["foo", "bar", "baz"] + a: [1, 2, 5], + b: ["foo", "bar", "baz"], }); const actual = df.select(pl.last("b")); expect(actual).toFrameEqual(pl.select(lit("baz").as("b"))); }); test("last:col", () => { const df = pl.DataFrame({ - "a": [1, 2, 5], - "b": ["foo", "bar", "baz"] + a: [1, 2, 5], + b: ["foo", "bar", "baz"], }); const actual = df.select(pl.last(col("b"))); expect(actual).toFrameEqual(pl.select(lit("baz").as("b"))); @@ -328,19 +355,17 @@ describe("lazy functions", () => { }); test("list", () => { const df = pl.DataFrame({ - "a": [1, 2, 3], - "b": ["a", "b", "c"], + a: [1, 2, 3], + b: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "a": [1, 2, 3], - "b": [["a"], ["b"], ["c"]] + a: [1, 2, 3], + b: [["a"], ["b"], ["c"]], }); - const actual = df.groupBy("a") - .agg( - pl.list("b") - .keepName() - ) - .sort({by:"a"}); + const actual = df + .groupBy("a") + .agg(pl.list("b").keepName()) + .sort({ by: "a" }); expect(actual).toFrameEqual(expected); }); test("mean:series", () => { @@ -348,12 +373,12 @@ describe("lazy functions", () => { expect(actual).toStrictEqual(4); }); test("mean:string", () => { - const df = pl.DataFrame({"a": [2, 2, 8]}); + const df = pl.DataFrame({ a: [2, 2, 8] }); const actual = df.select(pl.mean("a")).getColumn("a")[0]; expect(actual).toStrictEqual(4); }); test("mean:col", () => { - const df = pl.DataFrame({"a": [2, 2, 8]}); + const df = pl.DataFrame({ a: [2, 2, 8] }); const actual = df.select(pl.mean(col("a"))).getColumn("a")[0]; expect(actual).toStrictEqual(4); }); @@ -362,12 +387,12 @@ describe("lazy functions", () => { expect(actual).toStrictEqual(2); }); test("median:string", () => { - const df = pl.DataFrame({"a": [2, 2, 8]}); + const df = pl.DataFrame({ a: [2, 2, 8] }); const actual = df.select(pl.median("a")).getColumn("a")[0]; expect(actual).toStrictEqual(2); }); test("median:col", () => { - const df = pl.DataFrame({"a": [2, 2, 8]}); + const df = pl.DataFrame({ a: [2, 2, 8] }); const actual = df.select(pl.median(col("a"))).getColumn("a")[0]; expect(actual).toStrictEqual(2); }); @@ -376,12 +401,12 @@ describe("lazy functions", () => { expect(actual).toStrictEqual(2); }); test("nUnique:string", () => { - const df = pl.DataFrame({"a": [2, 2, 8]}); + const df = pl.DataFrame({ a: [2, 2, 8] }); const actual = df.select(pl.nUnique("a")).getColumn("a")[0]; expect(actual).toStrictEqual(2); }); test("nUnique:col", () => { - const df = pl.DataFrame({"a": [2, 2, 8]}); + const df = pl.DataFrame({ a: [2, 2, 8] }); const actual = df.select(pl.nUnique(col("a"))).getColumn("a")[0]; expect(actual).toStrictEqual(2); }); @@ -390,10 +415,7 @@ describe("lazy functions", () => { pl.Series("A", [1, 2, 3, 4]), pl.Series("B", [2, 4, 6, 8]), ]); - const actual = df.select( - pl.pearsonCorr("A", "B").round(1) - ) - .row(0)[0]; + const actual = df.select(pl.pearsonCorr("A", "B").round(1)).row(0)[0]; expect(actual).toStrictEqual(1); }); test("quantile:series", () => { @@ -402,12 +424,12 @@ describe("lazy functions", () => { expect(actual).toStrictEqual(2); }); test("quantile:string", () => { - const df = pl.DataFrame({"a": [1, 2, 3]}); + const df = pl.DataFrame({ a: [1, 2, 3] }); const actual = df.select(pl.quantile("a", 0.5)).getColumn("a")[0]; expect(actual).toStrictEqual(2); }); test("quantile:col", () => { - const df = pl.DataFrame({"a": [1, 2, 3]}); + const df = pl.DataFrame({ a: [1, 2, 3] }); const actual = df.select(pl.quantile(col("a"), 0.5)).getColumn("a")[0]; expect(actual).toStrictEqual(2); }); @@ -416,10 +438,7 @@ describe("lazy functions", () => { pl.Series("A", [1, 2, 3, 4]), pl.Series("B", [2, 4, 6, 8]), ]); - const actual = df.select( - pl.spearmanRankCorr("A", "B").round(1) - ) - .row(0)[0]; + const actual = df.select(pl.spearmanRankCorr("A", "B").round(1)).row(0)[0]; expect(actual).toStrictEqual(1); }); test("tail:series", () => { @@ -429,23 +448,31 @@ describe("lazy functions", () => { expect(actual).toSeriesEqual(expected); }); test("tail:string", () => { - const df = pl.DataFrame({"a": [1, 2, 3]}); + const df = pl.DataFrame({ a: [1, 2, 3] }); const expected = pl.Series("a", [2, 3]); const actual = df.select(pl.tail("a", 2)).getColumn("a"); expect(actual).toSeriesEqual(expected); }); test("tail:col", () => { - const df = pl.DataFrame({"a": [1, 2, 3]}); + const df = pl.DataFrame({ a: [1, 2, 3] }); const expected = pl.Series("a", [2, 3]); const actual = df.select(pl.tail(col("a"), 2)).getColumn("a"); expect(actual).toSeriesEqual(expected); }); test("element", () => { const df = pl.DataFrame({ - a: [[1, 2], [3, 4], [5, 6]], + a: [ + [1, 2], + [3, 4], + [5, 6], + ], }); const expected = pl.DataFrame({ - a: [[2, 4], [6, 8], [10, 12]], + a: [ + [2, 4], + [6, 8], + [10, 12], + ], }); const actual = df.select(pl.col("a").lst.eval(pl.element().mul(2))); expect(actual).toFrameEqual(expected); diff --git a/__tests__/lazyframe.test.ts b/__tests__/lazyframe.test.ts index 84430eabe..1163f86ad 100644 --- a/__tests__/lazyframe.test.ts +++ b/__tests__/lazyframe.test.ts @@ -2,710 +2,793 @@ import pl from "@polars"; describe("lazyframe", () => { test("columns", () => { - const df = pl.DataFrame({ - "foo": [1, 2], - "bar": ["a", "b"] - }).lazy(); + const df = pl + .DataFrame({ + foo: [1, 2], + bar: ["a", "b"], + }) + .lazy(); const actual = df.columns; expect(actual).toEqual(["foo", "bar"]); }); test("collectSync", () => { const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": ["a", "b"] + foo: [1, 2], + bar: ["a", "b"], }); const actual = expected.lazy().collectSync(); expect(actual).toFrameEqual(expected); }); test("collect", async () => { const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": ["a", "b"] + foo: [1, 2], + bar: ["a", "b"], }); const actual = await expected.lazy().collect(); expect(actual).toFrameEqual(expected); }); test("describeOptimizedPlan", () => { - const df = pl.DataFrame({ - "foo": [1, 2], - "bar": ["a", "b"] - }).lazy(); + const df = pl + .DataFrame({ + foo: [1, 2], + bar: ["a", "b"], + }) + .lazy(); const actual = df.describeOptimizedPlan().replace(/\s+/g, " "); expect(actual).toEqual( - ` DF ["foo", "bar"]; PROJECT */2 COLUMNS; SELECTION: "None" `); + ` DF ["foo", "bar"]; PROJECT */2 COLUMNS; SELECTION: "None" `, + ); }); test("drop", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], - "apple": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + apple: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const actual = df.lazy() - .drop("apple") - .collectSync(); + const actual = df.lazy().drop("apple").collectSync(); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("drop:array", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], - "apple": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + apple: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], }); - const actual = df.lazy() - .drop(["apple", "ham"]) - .collectSync(); + const actual = df.lazy().drop(["apple", "ham"]).collectSync(); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("drop:rest", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], - "apple": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], + apple: ["a", "b", "c"], }); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], }); - const actual = df.lazy() - .drop("apple", "ham") - .collectSync(); + const actual = df.lazy().drop("apple", "ham").collectSync(); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("unique", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 2, 3], - "bar": [1, 2, 2, 4], - "ham": ["a", "d", "d", "c"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 2, 3], + bar: [1, 2, 2, 4], + ham: ["a", "d", "d", "c"], + }) + .lazy() .unique() .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [1, 2, 4], - "ham": ["a", "d", "c"], + foo: [1, 2, 3], + bar: [1, 2, 4], + ham: ["a", "d", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("unique:subset", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 2, 2], - "bar": [1, 2, 2, 2], - "ham": ["a", "b", "c", "c"], - }).lazy() - .unique({subset: ["foo", "ham"]}) + const actual = pl + .DataFrame({ + foo: [1, 2, 2, 2], + bar: [1, 2, 2, 2], + ham: ["a", "b", "c", "c"], + }) + .lazy() + .unique({ subset: ["foo", "ham"] }) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 2], - "bar": [1, 2, 2], - "ham": ["a", "b", "c"], + foo: [1, 2, 2], + bar: [1, 2, 2], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); // run this test 100 times to make sure it is deterministic. test("unique:maintainOrder", () => { - 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() - .unique({maintainOrder: true}) + 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() + .unique({ maintainOrder: true }) .collectSync(); const expected = pl.DataFrame({ - "foo": [0, 1, 2], - "bar": [0, 1, 2], - "ham": ["0", "a", "b"], + 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("unique: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() - .unique({maintainOrder: true, subset: "foo"}) + 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() + .unique({ maintainOrder: true, subset: "foo" }) .collectSync(); const expected = pl.DataFrame({ - "foo": [0, 1, 2], - "bar": [0, 1, 2], - "ham": ["0", "a", "b"], + 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("unique: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() - .unique({maintainOrder: true, subset: ["foo", "ham"]}) + 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() + .unique({ 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"], + foo: [0, 1, 2, 2], + bar: [0, 1, 2, 2], + ham: ["0", "a", "b", "c"], }); expect(actual).toFrameEqual(expected); }); }); test("dropNulls", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .lazy() .dropNulls() .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"], + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("dropNulls:array", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, null, 8.0], - "ham": ["a", "d", "b", "c"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, null, 8.0], + ham: ["a", "d", "b", "c"], + }) + .lazy() .dropNulls(["foo"]) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, null, 8.0], - "ham": ["a", "b", "c"], + foo: [1, 2, 3], + bar: [6.0, null, 8.0], + ham: ["a", "b", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("dropNulls:rest", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, null, 8.0], - "ham": ["a", "d", "b", "c"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, null, 8.0], + ham: ["a", "d", "b", "c"], + }) + .lazy() .dropNulls("foo", "bar") .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 3], - "bar": [6.0, 8.0], - "ham": ["a", "c"], + foo: [1, 3], + bar: [6.0, 8.0], + ham: ["a", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("explode", () => { - const actual = pl.DataFrame({ - "letters": ["c", "a"], - "list_1": [[1, 2], [1, 3]], - }).lazy() + const actual = pl + .DataFrame({ + letters: ["c", "a"], + list_1: [ + [1, 2], + [1, 3], + ], + }) + .lazy() .explode("list_1") .collectSync(); const expected = pl.DataFrame({ - "letters": ["c", "c", "a", "a"], - "list_1": [1, 2, 1, 3], + letters: ["c", "c", "a", "a"], + list_1: [1, 2, 1, 3], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("fetch", async () => { const df = pl.DataFrame({ - "foo": [1, 2], - "bar": ["a", "b"] + foo: [1, 2], + bar: ["a", "b"], }); const expected = pl.DataFrame({ - "foo": [1], - "bar": ["a"] + foo: [1], + bar: ["a"], }); - const actual = await df - .lazy() - .select("*") - .fetch(1); + const actual = await df.lazy().select("*").fetch(1); expect(actual).toFrameEqual(expected); }); test("fetchSync", () => { const df = pl.DataFrame({ - "foo": [1, 2], - "bar": ["a", "b"] + foo: [1, 2], + bar: ["a", "b"], }); const expected = pl.DataFrame({ - "foo": [1], - "bar": ["a"] + foo: [1], + bar: ["a"], }); - const actual = df - .lazy() - .select("*") - .fetchSync(1); + const actual = df.lazy().select("*").fetchSync(1); expect(actual).toFrameEqual(expected); }); test("fillNull:zero", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .lazy() .fillNull(0) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 0, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], + foo: [1, 0, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("fillNull:expr", () => { - const actual = pl.DataFrame({ - "foo": [1, null, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, null, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], + }) + .lazy() .fillNull(pl.lit(1)) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 1, 2, 3], - "bar": [6.0, .5, 7.0, 8.0], - "ham": ["a", "d", "b", "c"], + foo: [1, 1, 2, 3], + bar: [6.0, 0.5, 7.0, 8.0], + ham: ["a", "d", "b", "c"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("filter", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .filter(pl.col("foo").eq(2)) .collectSync(); const expected = pl.DataFrame({ - "foo": [2, 2], - "bar": [2, 3] + foo: [2, 2], + bar: [2, 3], }); expect(actual).toFrameEqual(expected); }); test("filter:lit", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .filter(pl.col("foo").eq(pl.lit(2))) .collectSync(); const expected = pl.DataFrame({ - "foo": [2, 2], - "bar": [2, 3] + foo: [2, 2], + bar: [2, 3], }); expect(actual).toFrameEqual(expected); }); - describe("groupby", () => { }); + describe("groupby", () => {}); test("head", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .lazy() .head(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [1], - "ham": ["a"] + foo: [1], + ham: ["a"], }); expect(actual).toFrameEqual(expected); }); describe("join", () => { test("on", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"] - }).lazy(); - const actual = df.lazy().join(otherDF, {on: "ham"}) - .collectSync(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + }) + .lazy(); + const actual = df.lazy().join(otherDF, { on: "ham" }).collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": [6.0, 7.0], - "ham": ["a", "b"], - "apple": ["x", "y"], + foo: [1, 2], + bar: [6.0, 7.0], + ham: ["a", "b"], + apple: ["x", "y"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("on:multiple-columns", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo: [1, 10, 11], + }) + .lazy(); - const actual = df.lazy().join(otherDF, {on: ["ham", "foo"]}) + const actual = df + .lazy() + .join(otherDF, { on: ["ham", "foo"] }) .collectSync(); const expected = pl.DataFrame({ - "foo": [1], - "bar": [6.0], - "ham": ["a"], - "apple": ["x"], + foo: [1], + bar: [6.0], + ham: ["a"], + apple: ["x"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("on:left&right", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }) + .lazy(); - const actual = df.lazy().join(otherDF, { - leftOn: ["foo_left", "ham"], - rightOn: ["foo_right", "ham"] - }) + const actual = df + .lazy() + .join(otherDF, { + leftOn: ["foo_left", "ham"], + rightOn: ["foo_right", "ham"], + }) .collectSync(); const expected = pl.DataFrame({ - "foo_left": [1], - "bar": [6.0], - "ham": ["a"], - "apple": ["x"], + foo_left: [1], + bar: [6.0], + ham: ["a"], + apple: ["x"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("on:left&right", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }) + .lazy(); - const actual = df.lazy().join(otherDF, { - leftOn: ["foo_left", "ham"], - rightOn: ["foo_right", "ham"] - }) + const actual = df + .lazy() + .join(otherDF, { + leftOn: ["foo_left", "ham"], + rightOn: ["foo_right", "ham"], + }) .collectSync(); const expected = pl.DataFrame({ - "foo_left": [1], - "bar": [6.0], - "ham": ["a"], - "apple": ["x"], + foo_left: [1], + bar: [6.0], + ham: ["a"], + apple: ["x"], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("on throws error if only 'leftOn' is specified", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }) + .lazy(); - const f = () => df.lazy().join(otherDF, { - leftOn: ["foo_left", "ham"], - } as any); + const f = () => + df.lazy().join(otherDF, { + leftOn: ["foo_left", "ham"], + } as any); expect(f).toThrow(TypeError); }); test("on throws error if only 'rightOn' is specified", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }) + .lazy(); - const f = () => df.lazy().join(otherDF, { - rightOn: ["foo_right", "ham"], - } as any) - .collectSync(); + const f = () => + df + .lazy() + .join(otherDF, { + rightOn: ["foo_right", "ham"], + } as any) + .collectSync(); expect(f).toThrow(TypeError); }); test("on takes precedence over left&right", () => { const df = pl.DataFrame({ - "foo_left": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo_left: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo_right": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo_right: [1, 10, 11], + }) + .lazy(); - const actual = df.lazy().join(otherDF, { - on: "ham", - leftOn: ["foo_left", "ham"], - rightOn: ["foo_right", "ham"], - } as any) + const actual = df + .lazy() + .join(otherDF, { + on: "ham", + leftOn: ["foo_left", "ham"], + rightOn: ["foo_right", "ham"], + } as any) .collectSync(); const expected = pl.DataFrame({ - "foo_left": [1, 2], - "bar": [6.0, 7.0], - "ham": ["a", "b"], - "apple": ["x", "y"], - "foo_right": [1, 10], + foo_left: [1, 2], + bar: [6.0, 7.0], + ham: ["a", "b"], + apple: ["x", "y"], + foo_right: [1, 10], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("how:left", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo: [1, 10, 11], + }) + .lazy(); - const actual = df.lazy().join(otherDF, { - on: "ham", - how: "left" - }) + const actual = df + .lazy() + .join(otherDF, { + on: "ham", + how: "left", + }) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], - "apple": ["x", "y", null], - "fooright": [1, 10, null], + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + apple: ["x", "y", null], + fooright: [1, 10, null], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("how:outer", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y"], - "ham": ["a", "d"], - "foo": [1, 10], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y"], + ham: ["a", "d"], + foo: [1, 10], + }) + .lazy(); - const actual = df.lazy().join(otherDF, { - on: "ham", - how: "outer" - }) + const actual = df + .lazy() + .join(otherDF, { + on: "ham", + how: "outer", + }) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3, null], - "bar": [6, 7, 8, null], - "ham": ["a", "b", "c", "d"], - "apple": ["x", null, null, "y"], - "fooright": [1, null, null, 10], + foo: [1, 2, 3, null], + bar: [6, 7, 8, null], + ham: ["a", "b", "c", "d"], + apple: ["x", null, null, "y"], + fooright: [1, null, null, 10], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); test("suffix", () => { const df = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6.0, 7.0, 8.0], - "ham": ["a", "b", "c"] + foo: [1, 2, 3], + bar: [6.0, 7.0, 8.0], + ham: ["a", "b", "c"], }); - const otherDF = pl.DataFrame({ - "apple": ["x", "y", "z"], - "ham": ["a", "b", "d"], - "foo": [1, 10, 11], - }).lazy(); + const otherDF = pl + .DataFrame({ + apple: ["x", "y", "z"], + ham: ["a", "b", "d"], + foo: [1, 10, 11], + }) + .lazy(); - const actual = df.lazy().join(otherDF, { - on: "ham", - how: "left", - suffix: "_other" - }) + const actual = df + .lazy() + .join(otherDF, { + on: "ham", + how: "left", + suffix: "_other", + }) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"], - "apple": ["x", "y", null], - "foo_other": [1, 10, null], + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + apple: ["x", "y", null], + foo_other: [1, 10, null], }); expect(actual).toFrameEqualIgnoringOrder(expected); }); }); test("last", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .lazy() .last() .collectSync(); const expected = pl.DataFrame({ - "foo": [3], - "ham": ["c"] + foo: [3], + ham: ["c"], }); expect(actual).toFrameEqual(expected); }); test("limit", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .lazy() .limit(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [1], - "ham": ["a"] + foo: [1], + ham: ["a"], }); expect(actual).toFrameEqual(expected); }); test("max", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 11] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 11], + }) + .lazy() .max() .collectSync(); const expected = pl.DataFrame({ - "foo": [4], - "bar": [11] + foo: [4], + bar: [11], }); expect(actual).toFrameEqual(expected); }); test("mean", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .mean() .collectSync(); const expected = pl.DataFrame({ - "foo": [2.75], - "bar": [1.75] + foo: [2.75], + bar: [1.75], }); expect(actual).toFrameEqual(expected); }); test("median", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .median() .collectSync(); const expected = pl.DataFrame({ - "foo": [2.5], - "bar": [1.5] + foo: [2.5], + bar: [1.5], }); expect(actual).toFrameEqual(expected); }); test("min", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 11] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 11], + }) + .lazy() .min() .collectSync(); const expected = pl.DataFrame({ - "foo": [2], - "bar": [1] + foo: [2], + bar: [1], }); expect(actual).toFrameEqual(expected); }); test("quantile", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .lazy() .quantile(0.5) .collectSync(); expect(actual.row(0)).toEqual([2, 7, null]); }); test("rename", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "bar": [6, 7, 8], - "ham": ["a", "b", "c"] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + bar: [6, 7, 8], + ham: ["a", "b", "c"], + }) + .lazy() .rename({ - "foo": "foo_new", - "bar": "bar_new", - "ham": "ham_new" + foo: "foo_new", + bar: "bar_new", + ham: "ham_new", }) .collectSync(); expect(actual.columns).toEqual(["foo_new", "bar_new", "ham_new"]); }); test("reverse", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .reverse() .collectSync(); const expected = pl.DataFrame({ - "foo": [4, 3, 2, 2], - "bar": [1, 1, 3, 2] + foo: [4, 3, 2, 2], + bar: [1, 1, 3, 2], }); expect(actual).toFrameEqual(expected); }); test("tail", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3], - "ham": ["a", "b", "c"] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3], + ham: ["a", "b", "c"], + }) + .lazy() .tail(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [3], - "ham": ["c"] + foo: [3], + ham: ["c"], }); expect(actual).toFrameEqual(expected); }); test("select:single", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .lazy() .select("ham") .collectSync(); const ham = pl.Series("ham", ["a", "b", "c", null]); @@ -714,11 +797,13 @@ describe("lazyframe", () => { expect(actual.getColumn("ham")).toSeriesEqual(ham); }); test("select:strings", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .lazy() .select("ham", "foo") .collectSync(); const foo = pl.Series("foo", [1, 2, 3, 1]); @@ -728,11 +813,13 @@ describe("lazyframe", () => { expect(actual.getColumn("ham")).toSeriesEqual(ham); }); test("select:expr", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - "ham": ["a", "b", "c", null] - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + ham: ["a", "b", "c", null], + }) + .lazy() .select(pl.col("foo"), "ham") .collectSync(); const foo = pl.Series("foo", [1, 2, 3, 1]); @@ -742,189 +829,214 @@ describe("lazyframe", () => { expect(actual.getColumn("ham")).toSeriesEqual(ham); }); test("shift:pos", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() .shift(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [null, 1, 2, 3], - "bar": [null, 6, 7, 8], + foo: [null, 1, 2, 3], + bar: [null, 6, 7, 8], }); expect(actual).toFrameEqual(expected); }); test("shift:neg", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() .shift(-1) .collectSync(); const expected = pl.DataFrame({ - "foo": [2, 3, 1, null], - "bar": [7, 8, 1, null], + foo: [2, 3, 1, null], + bar: [7, 8, 1, null], }); expect(actual).toFrameEqual(expected); }); test("shiftAndFill:positional", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() .shiftAndFill(-1, 99) .collectSync(); const expected = pl.DataFrame({ - "foo": [2, 3, 1, 99], - "bar": [7, 8, 1, 99], + foo: [2, 3, 1, 99], + bar: [7, 8, 1, 99], }); expect(actual).toFrameEqual(expected); }); test("shiftAndFill:named", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() - .shiftAndFill({periods: -1, fillValue: 99}) + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() + .shiftAndFill({ periods: -1, fillValue: 99 }) .collectSync(); const expected = pl.DataFrame({ - "foo": [2, 3, 1, 99], - "bar": [7, 8, 1, 99], + foo: [2, 3, 1, 99], + bar: [7, 8, 1, 99], }); expect(actual).toFrameEqual(expected); }); test("shiftAndFill:expr", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() - .shiftAndFill({periods: -1, fillValue: pl.lit(99)}) + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() + .shiftAndFill({ periods: -1, fillValue: pl.lit(99) }) .collectSync(); const expected = pl.DataFrame({ - "foo": [2, 3, 1, 99], - "bar": [7, 8, 1, 99], + foo: [2, 3, 1, 99], + bar: [7, 8, 1, 99], }); expect(actual).toFrameEqual(expected); }); test("slice:positional", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() .slice(0, 2) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": [6, 7], + foo: [1, 2], + bar: [6, 7], }); expect(actual).toFrameEqual(expected); }); test("slice:named", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() - .slice({offset: 0, length: 2}) + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() + .slice({ offset: 0, length: 2 }) .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 2], - "bar": [6, 7], + foo: [1, 2], + bar: [6, 7], }); expect(actual).toFrameEqual(expected); }); test("sort:positional", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() .sort("bar") .collectSync(); const expected = pl.DataFrame({ - "foo": [1, 1, 2, 3], - "bar": [1, 6, 7, 8], + foo: [1, 1, 2, 3], + bar: [1, 6, 7, 8], }); expect(actual).toFrameEqual(expected); }); test("sort:named", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, 1], - "bar": [6, 7, 8, 1], - }).lazy() - .sort({by: "bar", reverse: true}) + const actual = pl + .DataFrame({ + foo: [1, 2, 3, 1], + bar: [6, 7, 8, 1], + }) + .lazy() + .sort({ by: "bar", reverse: true }) .collectSync(); const expected = pl.DataFrame({ - "foo": [3, 2, 1, 1], - "bar": [8, 7, 6, 1], + foo: [3, 2, 1, 1], + bar: [8, 7, 6, 1], }); expect(actual).toFrameEqual(expected); }); test("sort:multi-args", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 3, -1], - "bar": [6, 7, 8, 2], - "baz": ["a", "b", "d", "A"], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 3, -1], + bar: [6, 7, 8, 2], + baz: ["a", "b", "d", "A"], + }) + .lazy() .sort({ - by: [ - pl.col("baz"), - pl.col("bar") - ] + by: [pl.col("baz"), pl.col("bar")], }) .collectSync(); const expected = pl.DataFrame({ - "foo": [-1, 1, 2, 3], - "bar": [2, 6, 7, 8], - "baz": ["A", "a", "b", "d"], + foo: [-1, 1, 2, 3], + bar: [2, 6, 7, 8], + baz: ["A", "a", "b", "d"], }); expect(actual).toFrameEqual(expected); }); test("sum", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 11] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 11], + }) + .lazy() .sum() .collectSync(); const expected = pl.DataFrame({ - "foo": [11], - "bar": [17] + foo: [11], + bar: [17], }); expect(actual).toFrameEqual(expected); }); test("std", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .std() .collectSync(); const expected = pl.DataFrame({ - "foo": [0.9574271077563381], - "bar": [0.9574271077563381] + foo: [0.9574271077563381], + bar: [0.9574271077563381], }); expect(actual).toFrameEqual(expected); }); test("var", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .var() .collectSync(); const expected = pl.DataFrame({ - "foo": [0.9166666666666666], - "bar": [0.9166666666666666] + foo: [0.9166666666666666], + bar: [0.9166666666666666], }); expect(actual).toFrameEqual(expected); }); test("withColumn", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .lazy() .withColumn(pl.lit("a").alias("col_a")) .collectSync(); @@ -936,14 +1048,13 @@ describe("lazyframe", () => { expect(actual).toFrameEqualIgnoringOrder(expected); }); test("withColumns", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).lazy() - .withColumns( - pl.lit("a").alias("col_a"), - pl.lit("b").alias("col_b") - ) + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .lazy() + .withColumns(pl.lit("a").alias("col_a"), pl.lit("b").alias("col_b")) .collectSync(); const expected = pl.DataFrame([ pl.Series("foo", [1, 2, 9], pl.Int16), @@ -954,14 +1065,13 @@ describe("lazyframe", () => { expect(actual).toFrameEqualIgnoringOrder(expected); }); test("withColumns:array", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).lazy() - .withColumns([ - pl.lit("a").alias("col_a"), - pl.lit("b").alias("col_b") - ]) + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .lazy() + .withColumns([pl.lit("a").alias("col_a"), pl.lit("b").alias("col_b")]) .collectSync(); const expected = pl.DataFrame([ pl.Series("foo", [1, 2, 9], pl.Int16), @@ -972,10 +1082,12 @@ describe("lazyframe", () => { expect(actual).toFrameEqualIgnoringOrder(expected); }); test("withColumnRenamed", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .lazy() .withColumnRenamed("foo", "apple") .collectSync(); @@ -986,10 +1098,12 @@ describe("lazyframe", () => { expect(actual).toFrameEqual(expected); }); test("withRowCount", () => { - const actual = pl.DataFrame({ - "foo": [1, 2, 9], - "bar": [6, 2, 8], - }).lazy() + const actual = pl + .DataFrame({ + foo: [1, 2, 9], + bar: [6, 2, 8], + }) + .lazy() .withRowCount() .collectSync(); @@ -1001,83 +1115,89 @@ describe("lazyframe", () => { expect(actual).toFrameEqual(expected); }); test("tail", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .tail(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [4], - "bar": [1] + foo: [4], + bar: [1], }); expect(actual).toFrameEqual(expected); }); test("head", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .head(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [2], - "bar": [2] + foo: [2], + bar: [2], }); expect(actual).toFrameEqual(expected); }); test("limit", () => { - const actual = pl.DataFrame({ - "foo": [2, 2, 3, 4], - "bar": [2, 3, 1, 1] - }).lazy() + const actual = pl + .DataFrame({ + foo: [2, 2, 3, 4], + bar: [2, 3, 1, 1], + }) + .lazy() .limit(1) .collectSync(); const expected = pl.DataFrame({ - "foo": [2], - "bar": [2] + foo: [2], + bar: [2], }); expect(actual).toFrameEqual(expected); }); test("str:padStart", () => { - const actual = pl.DataFrame({ - "ham": ["a", "b", "c"] - }).lazy() - .withColumn( - pl.col("ham").str.padStart(3, "-") - ) + const actual = pl + .DataFrame({ + ham: ["a", "b", "c"], + }) + .lazy() + .withColumn(pl.col("ham").str.padStart(3, "-")) .collectSync(); const expected = pl.DataFrame({ - "ham": ["--a", "--b", "--c"] + ham: ["--a", "--b", "--c"], }); expect(actual).toFrameEqual(expected); }); test("str:padEnd", () => { - const actual = pl.DataFrame({ - "ham": ["a", "b", "c"] - }).lazy() - .withColumn( - pl.col("ham").str.padEnd(3, "-") - ) + const actual = pl + .DataFrame({ + ham: ["a", "b", "c"], + }) + .lazy() + .withColumn(pl.col("ham").str.padEnd(3, "-")) .collectSync(); const expected = pl.DataFrame({ - "ham": ["a--", "b--", "c--"] + ham: ["a--", "b--", "c--"], }); expect(actual).toFrameEqual(expected); }); test("str:zFill", () => { - const actual = pl.DataFrame({ - "ham": ["a", "b", "c"] - }).lazy() - .withColumn( - pl.col("ham").str.zFill(3) - ) + const actual = pl + .DataFrame({ + ham: ["a", "b", "c"], + }) + .lazy() + .withColumn(pl.col("ham").str.zFill(3)) .collectSync(); const expected = pl.DataFrame({ - "ham": ["00a", "00b", "00c"] + ham: ["00a", "00b", "00c"], }); expect(actual).toFrameEqual(expected); }); diff --git a/__tests__/serde.test.ts b/__tests__/serde.test.ts index 5734cb57d..7cb596c7e 100644 --- a/__tests__/serde.test.ts +++ b/__tests__/serde.test.ts @@ -38,7 +38,7 @@ describe("serde", () => { test("dataframe:json", () => { const df = pl.DataFrame({ foo: [1, 2], - bar: [2, 3] + bar: [2, 3], }); const buf = df.serialize("json"); const expected = pl.DataFrame.deserialize(buf, "json"); @@ -47,7 +47,7 @@ describe("serde", () => { test("dataframe:bincode", () => { const df = pl.DataFrame({ foo: [1, 2], - bar: [2, 3] + bar: [2, 3], }); const buf = df.serialize("bincode"); const expected = pl.DataFrame.deserialize(buf, "bincode"); @@ -57,7 +57,7 @@ describe("serde", () => { test("dataframe:unsupported", () => { const df = pl.DataFrame({ foo: [1, 2], - bar: [2, 3] + bar: [2, 3], }); const ser = () => df.serialize("yaml" as any); const buf = df.serialize("bincode"); diff --git a/__tests__/series.test.ts b/__tests__/series.test.ts index b204ebec0..c2237004e 100644 --- a/__tests__/series.test.ts +++ b/__tests__/series.test.ts @@ -1,9 +1,8 @@ /* eslint-disable newline-per-chained-call */ import pl from "@polars"; -import {InvalidOperationError} from "../polars/error"; +import { InvalidOperationError } from "../polars/error"; import Chance from "chance"; - describe("from lists", () => { test("bool", () => { const expected = [[true, false], [true], [null], []]; @@ -34,11 +33,8 @@ describe("typedArrays", () => { expect(actual).toEqual(expected); }); test("int8:list", () => { - const int8Arrays = [ - new Int8Array([1, 2, 3]), - new Int8Array([33, 44, 55]), - ]; - const expected = int8Arrays.map(i => [...i]); + const int8Arrays = [new Int8Array([1, 2, 3]), new Int8Array([33, 44, 55])]; + const expected = int8Arrays.map((i) => [...i]); const actual = pl.Series(int8Arrays).toArray(); expect(actual).toEqual(expected); }); @@ -54,7 +50,7 @@ describe("typedArrays", () => { new Int16Array([33, 44, 55]), ]; const actual = pl.Series(int16Arrays).toArray(); - const expected = int16Arrays.map(i => [...i]); + const expected = int16Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); test("int32", () => { @@ -68,7 +64,7 @@ describe("typedArrays", () => { new Int32Array([33, 44, 55]), ]; const actual = pl.Series(int32Arrays).toArray(); - const expected = int32Arrays.map(i => [...i]); + const expected = int32Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); @@ -91,7 +87,7 @@ describe("typedArrays", () => { const actual = pl.Series(int64Arrays).toArray(); const expected = [ [1, 2, 3], - [33, 44, 55] + [33, 44, 55], ]; expect(actual).toEqual(expected); }); @@ -107,7 +103,7 @@ describe("typedArrays", () => { new Uint8Array([33, 44, 55]), ]; const actual = pl.Series(uint8Arrays).toArray(); - const expected = uint8Arrays.map(i => [...i]); + const expected = uint8Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); test("uint16", () => { @@ -122,7 +118,7 @@ describe("typedArrays", () => { new Uint16Array([33, 44, 55]), ]; const actual = pl.Series(uint16Arrays).toArray(); - const expected = uint16Arrays.map(i => [...i]); + const expected = uint16Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); test("uint32", () => { @@ -137,7 +133,7 @@ describe("typedArrays", () => { new Uint32Array([33, 44, 55]), ]; const actual = pl.Series(uint32Arrays).toArray(); - const expected = uint32Arrays.map(i => [...i]); + const expected = uint32Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); test("uint64", () => { @@ -152,7 +148,7 @@ describe("typedArrays", () => { new BigUint64Array([33n, 44n, 55n]), ]; const actual = pl.Series(uint64Arrays).toArray(); - const expected = uint64Arrays.map(i => [...i]); + const expected = uint64Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); test("float32", () => { @@ -167,7 +163,7 @@ describe("typedArrays", () => { new Float32Array([33, 44, 55]), ]; const actual = pl.Series(float32Arrays).toArray(); - const expected = float32Arrays.map(i => [...i]); + const expected = float32Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); test("float64", () => { @@ -182,26 +178,23 @@ describe("typedArrays", () => { new Float64Array([33, 44, 55]), ]; const actual = pl.Series(float64Arrays).toArray(); - const expected = float64Arrays.map(i => [...i]); + const expected = float64Arrays.map((i) => [...i]); expect(actual).toEqual(expected); }); - }); describe("series", () => { const chance = new Chance(); describe("create series", () => { - - it.each` - values | dtype | type - ${["foo", "bar", "baz"]} | ${pl.Utf8} | ${"string"} - ${[1, 2, 3]} | ${pl.Float64} | ${"number"} - ${[1n, 2n, 3n]} | ${pl.UInt64} | ${"bigint"} - ${[true, false]} | ${pl.Bool} | ${"boolean"} - ${[]} | ${pl.Float64} | ${"empty"} + values | dtype | type + ${["foo", "bar", "baz"]} | ${pl.Utf8} | ${"string"} + ${[1, 2, 3]} | ${pl.Float64} | ${"number"} + ${[1n, 2n, 3n]} | ${pl.UInt64} | ${"bigint"} + ${[true, false]} | ${pl.Bool} | ${"boolean"} + ${[]} | ${pl.Float64} | ${"empty"} ${[new Date(Date.now())]} | ${pl.Datetime("ms")} | ${"Date"} - `("defaults to $dtype for \"$type\"", ({ values, dtype}) => { + `('defaults to $dtype for "$type"', ({ values, dtype }) => { const name = chance.string(); const s = pl.Series(name, values); expect(s.name).toStrictEqual(name); @@ -222,12 +215,11 @@ describe("series", () => { expect(s.dtype).toStrictEqual(dtype); }); }); - }); describe("series", () => { const numSeries = () => pl.Series("foo", [1, 2, 3], pl.Int32); const fltSeries = () => pl.Series("float", [1, 2, 3], pl.Float64); - const boolSeries = () => pl.Series("bool", [true, false, false]); + const boolSeries = () => pl.Series("bool", [true, false, false]); const other = () => pl.Series("bar", [3, 4, 5], pl.Int32); const chance = new Chance(); @@ -239,11 +231,11 @@ describe("series", () => { // expect(s).toStrictEqual(actual); // }); it.each` - series | getter - ${numSeries()} | ${"dtype"} - ${numSeries()} | ${"name"} - ${numSeries()} | ${"length"} - `("$# $getter does not error", ({series, getter}) => { + series | getter + ${numSeries()} | ${"dtype"} + ${numSeries()} | ${"name"} + ${numSeries()} | ${"length"} + `("$# $getter does not error", ({ series, getter }) => { try { series[getter]; } catch (err) { @@ -251,172 +243,172 @@ describe("series", () => { } }); it.each` - series | method | args - ${numSeries()} | ${"abs"} | ${[]} - ${numSeries()} | ${"as"} | ${[chance.string()]} - ${numSeries()} | ${"alias"} | ${[chance.string()]} - ${numSeries()} | ${"append"} | ${[other()]} - ${numSeries()} | ${"argMax"} | ${[]} - ${numSeries()} | ${"argMin"} | ${[]} - ${numSeries()} | ${"argSort"} | ${[]} - ${boolSeries()} | ${"argTrue"} | ${[]} - ${numSeries()} | ${"argUnique"} | ${[]} - ${numSeries()} | ${"cast"} | ${[pl.UInt32]} - ${numSeries()} | ${"chunkLengths"} | ${[]} - ${numSeries()} | ${"clone"} | ${[]} - ${numSeries()} | ${"cumMax"} | ${[]} - ${numSeries()} | ${"cumMin"} | ${[]} - ${numSeries()} | ${"cumProd"} | ${[]} - ${numSeries()} | ${"cumSum"} | ${[]} - ${numSeries()} | ${"describe"} | ${[]} - ${numSeries()} | ${"diff"} | ${[]} - ${numSeries()} | ${"diff"} | ${[{n: 1, nullBehavior: "drop"}]} - ${numSeries()} | ${"diff"} | ${[{nullBehavior: "drop"}]} - ${numSeries()} | ${"diff"} | ${[1, "drop"]} - ${numSeries()} | ${"dot"} | ${[other()]} - ${numSeries()} | ${"dropNulls"} | ${[]} - ${numSeries()} | ${"fillNull"} | ${["zero"]} - ${numSeries()} | ${"fillNull"} | ${[{strategy: "zero"}]} - ${numSeries()} | ${"filter"} | ${[boolSeries()]} - ${fltSeries()} | ${"floor"} | ${[]} - ${numSeries()} | ${"hasValidity"} | ${[]} - ${numSeries()} | ${"hash"} | ${[]} - ${numSeries()} | ${"hash"} | ${[{k0: 10}]} - ${numSeries()} | ${"hash"} | ${[{k0: 10, k1: 29}]} - ${numSeries()} | ${"hash"} | ${[{k0: 10, k1: 29, k2: 3}]} - ${numSeries()} | ${"hash"} | ${[{k0: 10, k1: 29, k3: 1, k2: 3}]} - ${numSeries()} | ${"hash"} | ${[1]} - ${numSeries()} | ${"hash"} | ${[1, 2]} - ${numSeries()} | ${"hash"} | ${[1, 2, 3]} - ${numSeries()} | ${"hash"} | ${[1, 2, 3, 4]} - ${numSeries()} | ${"head"} | ${[]} - ${numSeries()} | ${"head"} | ${[1]} - ${numSeries()} | ${"inner"} | ${[]} - ${numSeries()} | ${"interpolate"} | ${[]} - ${numSeries()} | ${"isBoolean"} | ${[]} - ${numSeries()} | ${"isDateTime"} | ${[]} - ${numSeries()} | ${"isDuplicated"} | ${[]} - ${fltSeries()} | ${"isFinite"} | ${[]} - ${numSeries()} | ${"isFirst"} | ${[]} - ${numSeries()} | ${"isFloat"} | ${[]} - ${numSeries()} | ${"isIn"} | ${[other()]} - ${numSeries()} | ${"isIn"} | ${[[1, 2, 3]]} - ${fltSeries()} | ${"isInfinite"} | ${[]} - ${numSeries()} | ${"isNotNull"} | ${[]} - ${numSeries()} | ${"isNull"} | ${[]} - ${numSeries()} | ${"isNumeric"} | ${[]} - ${numSeries()} | ${"isUnique"} | ${[]} - ${numSeries()} | ${"isUtf8"} | ${[]} - ${numSeries()} | ${"kurtosis"} | ${[]} - ${numSeries()} | ${"kurtosis"} | ${[{fisher: true, bias: true}]} - ${numSeries()} | ${"kurtosis"} | ${[{bias: false}]} - ${numSeries()} | ${"kurtosis"} | ${[{fisher: false}]} - ${numSeries()} | ${"kurtosis"} | ${[false, false]} - ${numSeries()} | ${"kurtosis"} | ${[false]} - ${numSeries()} | ${"len"} | ${[]} - ${numSeries()} | ${"limit"} | ${[]} - ${numSeries()} | ${"limit"} | ${[2]} - ${numSeries()} | ${"max"} | ${[]} - ${numSeries()} | ${"mean"} | ${[]} - ${numSeries()} | ${"median"} | ${[]} - ${numSeries()} | ${"min"} | ${[]} - ${numSeries()} | ${"mode"} | ${[]} - ${numSeries()} | ${"nChunks"} | ${[]} - ${numSeries()} | ${"nUnique"} | ${[]} - ${numSeries()} | ${"nullCount"} | ${[]} - ${numSeries()} | ${"peakMax"} | ${[]} - ${numSeries()} | ${"peakMin"} | ${[]} - ${numSeries()} | ${"quantile"} | ${[0.4]} - ${numSeries()} | ${"rank"} | ${[]} - ${numSeries()} | ${"rank"} | ${["average"]} - ${numSeries()} | ${"rechunk"} | ${[]} - ${numSeries()} | ${"rechunk"} | ${[true]} - ${numSeries()} | ${"rename"} | ${["new name"]} - ${numSeries()} | ${"rename"} | ${["new name", true]} - ${numSeries()} | ${"rename"} | ${[{name: "new name"}]} - ${numSeries()} | ${"rename"} | ${[{name: "new name", inPlace: true}]} - ${numSeries()} | ${"rename"} | ${[{name: "new name"}]} - ${numSeries()} | ${"rollingMax"} | ${[{windowSize: 1}]} - ${numSeries()} | ${"rollingMax"} | ${[{windowSize: 1, weights: [.33]}]} - ${numSeries()} | ${"rollingMax"} | ${[{windowSize: 1, weights: [.11], minPeriods: 1}]} - ${numSeries()} | ${"rollingMax"} | ${[{windowSize: 1, weights: [.44], minPeriods: 1, center: false}]} - ${numSeries()} | ${"rollingMax"} | ${[1]} - ${numSeries()} | ${"rollingMax"} | ${[1, [.11]]} - ${numSeries()} | ${"rollingMax"} | ${[1, [.11], 1]} - ${numSeries()} | ${"rollingMax"} | ${[1, [.23], 1, true]} - ${numSeries()} | ${"rollingMean"} | ${[{windowSize: 1}]} - ${numSeries()} | ${"rollingMean"} | ${[{windowSize: 1, weights: [.33]}]} - ${numSeries()} | ${"rollingMean"} | ${[{windowSize: 1, weights: [.11], minPeriods: 1}]} - ${numSeries()} | ${"rollingMean"} | ${[{windowSize: 1, weights: [.44], minPeriods: 1, center: false}]} - ${numSeries()} | ${"rollingMean"} | ${[1]} - ${numSeries()} | ${"rollingMean"} | ${[1, [.11]]} - ${numSeries()} | ${"rollingMean"} | ${[1, [.11], 1]} - ${numSeries()} | ${"rollingMean"} | ${[1, [.23], 1, true]} - ${numSeries()} | ${"rollingMin"} | ${[{windowSize: 1}]} - ${numSeries()} | ${"rollingMin"} | ${[{windowSize: 1, weights: [.33]}]} - ${numSeries()} | ${"rollingMin"} | ${[{windowSize: 1, weights: [.11], minPeriods: 1}]} - ${numSeries()} | ${"rollingMin"} | ${[{windowSize: 1, weights: [.44], minPeriods: 1, center: false}]} - ${numSeries()} | ${"rollingMin"} | ${[1]} - ${numSeries()} | ${"rollingMin"} | ${[1, [.11]]} - ${numSeries()} | ${"rollingMin"} | ${[1, [.11], 1]} - ${numSeries()} | ${"rollingMin"} | ${[1, [.23], 1, true]} - ${numSeries()} | ${"rollingSum"} | ${[{windowSize: 1}]} - ${numSeries()} | ${"rollingSum"} | ${[{windowSize: 1, weights: [.33]}]} - ${numSeries()} | ${"rollingSum"} | ${[{windowSize: 1, weights: [.11], minPeriods: 1}]} - ${numSeries()} | ${"rollingSum"} | ${[{windowSize: 1, weights: [.44], minPeriods: 1, center: false}]} - ${numSeries()} | ${"rollingSum"} | ${[1]} - ${numSeries()} | ${"rollingSum"} | ${[1, [.11]]} - ${numSeries()} | ${"rollingSum"} | ${[1, [.11], 1]} - ${numSeries()} | ${"rollingSum"} | ${[1, [.23], 1, true]} - ${numSeries()} | ${"rollingVar"} | ${[{windowSize: 1}]} - ${numSeries()} | ${"rollingVar"} | ${[{windowSize: 1, weights: [.33]}]} - ${numSeries()} | ${"rollingVar"} | ${[{windowSize: 1, weights: [.11], minPeriods: 1}]} - ${numSeries()} | ${"rollingVar"} | ${[{windowSize: 1, weights: [.44], minPeriods: 1, center: false}]} - ${numSeries()} | ${"rollingVar"} | ${[1]} - ${numSeries()} | ${"rollingVar"} | ${[1, [.11]]} - ${numSeries()} | ${"rollingVar"} | ${[1, [.11], 1]} - ${numSeries()} | ${"rollingVar"} | ${[1, [.23], 1, true]} - ${fltSeries()} | ${"round"} | ${[1]} - ${numSeries()} | ${"sample"} | ${[]} - ${numSeries()} | ${"sample"} | ${[1, null, true]} - ${numSeries()} | ${"sample"} | ${[null, 1]} - ${numSeries()} | ${"sample"} | ${[{n: 1}]} - ${numSeries()} | ${"sample"} | ${[{frac: 0.5}]} - ${numSeries()} | ${"sample"} | ${[{n: 1, withReplacement: true}]} - ${numSeries()} | ${"sample"} | ${[{frac: 0.1, withReplacement: true}]} - ${numSeries()} | ${"sample"} | ${[{frac: 0.1, withReplacement: true, seed: 1n}]} - ${numSeries()} | ${"sample"} | ${[{frac: 0.1, withReplacement: true, seed: 1}]} - ${numSeries()} | ${"sample"} | ${[{n: 1, withReplacement: true, seed: 1}]} - ${numSeries()} | ${"seriesEqual"} | ${[other()]} - ${numSeries()} | ${"seriesEqual"} | ${[other(), true]} - ${numSeries()} | ${"seriesEqual"} | ${[other(), false]} - ${numSeries()} | ${"set"} | ${[boolSeries(), 2]} - ${fltSeries()} | ${"setAtIdx"} | ${[[0, 1], 1]} - ${numSeries()} | ${"shift"} | ${[]} - ${numSeries()} | ${"shift"} | ${[1]} - ${numSeries()} | ${"shiftAndFill"} | ${[1, 2]} - ${numSeries()} | ${"shiftAndFill"} | ${[{periods: 1, fillValue: 2}]} - ${numSeries()} | ${"skew"} | ${[]} - ${numSeries()} | ${"skew"} | ${[true]} - ${numSeries()} | ${"skew"} | ${[false]} - ${numSeries()} | ${"skew"} | ${[{bias: true}]} - ${numSeries()} | ${"skew"} | ${[{bias: false}]} - ${numSeries()} | ${"slice"} | ${[1, 2]} - ${numSeries()} | ${"slice"} | ${[{offset: 1, length: 2}]} - ${numSeries()} | ${"sort"} | ${[]} - ${numSeries()} | ${"sort"} | ${[false]} - ${numSeries()} | ${"sort"} | ${[true]} - ${numSeries()} | ${"sort"} | ${[{reverse: true}]} - ${numSeries()} | ${"sort"} | ${[{reverse: false}]} - ${numSeries()} | ${"sum"} | ${[]} - ${numSeries()} | ${"tail"} | ${[]} - ${numSeries()} | ${"take"} | ${[[1, 2]]} - ${numSeries()} | ${"takeEvery"} | ${[1]} - ${numSeries()} | ${"toArray"} | ${[]} - ${numSeries()} | ${"unique"} | ${[]} - ${numSeries()} | ${"valueCounts"} | ${[]} - ${numSeries()} | ${"zipWith"} | ${[boolSeries(), other()]} - `("$# $method is callable", ({series, method, args}) => { + series | method | args + ${numSeries()} | ${"abs"} | ${[]} + ${numSeries()} | ${"as"} | ${[chance.string()]} + ${numSeries()} | ${"alias"} | ${[chance.string()]} + ${numSeries()} | ${"append"} | ${[other()]} + ${numSeries()} | ${"argMax"} | ${[]} + ${numSeries()} | ${"argMin"} | ${[]} + ${numSeries()} | ${"argSort"} | ${[]} + ${boolSeries()} | ${"argTrue"} | ${[]} + ${numSeries()} | ${"argUnique"} | ${[]} + ${numSeries()} | ${"cast"} | ${[pl.UInt32]} + ${numSeries()} | ${"chunkLengths"} | ${[]} + ${numSeries()} | ${"clone"} | ${[]} + ${numSeries()} | ${"cumMax"} | ${[]} + ${numSeries()} | ${"cumMin"} | ${[]} + ${numSeries()} | ${"cumProd"} | ${[]} + ${numSeries()} | ${"cumSum"} | ${[]} + ${numSeries()} | ${"describe"} | ${[]} + ${numSeries()} | ${"diff"} | ${[]} + ${numSeries()} | ${"diff"} | ${[{ n: 1, nullBehavior: "drop" }]} + ${numSeries()} | ${"diff"} | ${[{ nullBehavior: "drop" }]} + ${numSeries()} | ${"diff"} | ${[1, "drop"]} + ${numSeries()} | ${"dot"} | ${[other()]} + ${numSeries()} | ${"dropNulls"} | ${[]} + ${numSeries()} | ${"fillNull"} | ${["zero"]} + ${numSeries()} | ${"fillNull"} | ${[{ strategy: "zero" }]} + ${numSeries()} | ${"filter"} | ${[boolSeries()]} + ${fltSeries()} | ${"floor"} | ${[]} + ${numSeries()} | ${"hasValidity"} | ${[]} + ${numSeries()} | ${"hash"} | ${[]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10 }]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29 }]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29, k2: 3 }]} + ${numSeries()} | ${"hash"} | ${[{ k0: 10, k1: 29, k3: 1, k2: 3 }]} + ${numSeries()} | ${"hash"} | ${[1]} + ${numSeries()} | ${"hash"} | ${[1, 2]} + ${numSeries()} | ${"hash"} | ${[1, 2, 3]} + ${numSeries()} | ${"hash"} | ${[1, 2, 3, 4]} + ${numSeries()} | ${"head"} | ${[]} + ${numSeries()} | ${"head"} | ${[1]} + ${numSeries()} | ${"inner"} | ${[]} + ${numSeries()} | ${"interpolate"} | ${[]} + ${numSeries()} | ${"isBoolean"} | ${[]} + ${numSeries()} | ${"isDateTime"} | ${[]} + ${numSeries()} | ${"isDuplicated"} | ${[]} + ${fltSeries()} | ${"isFinite"} | ${[]} + ${numSeries()} | ${"isFirst"} | ${[]} + ${numSeries()} | ${"isFloat"} | ${[]} + ${numSeries()} | ${"isIn"} | ${[other()]} + ${numSeries()} | ${"isIn"} | ${[[1, 2, 3]]} + ${fltSeries()} | ${"isInfinite"} | ${[]} + ${numSeries()} | ${"isNotNull"} | ${[]} + ${numSeries()} | ${"isNull"} | ${[]} + ${numSeries()} | ${"isNumeric"} | ${[]} + ${numSeries()} | ${"isUnique"} | ${[]} + ${numSeries()} | ${"isUtf8"} | ${[]} + ${numSeries()} | ${"kurtosis"} | ${[]} + ${numSeries()} | ${"kurtosis"} | ${[{ fisher: true, bias: true }]} + ${numSeries()} | ${"kurtosis"} | ${[{ bias: false }]} + ${numSeries()} | ${"kurtosis"} | ${[{ fisher: false }]} + ${numSeries()} | ${"kurtosis"} | ${[false, false]} + ${numSeries()} | ${"kurtosis"} | ${[false]} + ${numSeries()} | ${"len"} | ${[]} + ${numSeries()} | ${"limit"} | ${[]} + ${numSeries()} | ${"limit"} | ${[2]} + ${numSeries()} | ${"max"} | ${[]} + ${numSeries()} | ${"mean"} | ${[]} + ${numSeries()} | ${"median"} | ${[]} + ${numSeries()} | ${"min"} | ${[]} + ${numSeries()} | ${"mode"} | ${[]} + ${numSeries()} | ${"nChunks"} | ${[]} + ${numSeries()} | ${"nUnique"} | ${[]} + ${numSeries()} | ${"nullCount"} | ${[]} + ${numSeries()} | ${"peakMax"} | ${[]} + ${numSeries()} | ${"peakMin"} | ${[]} + ${numSeries()} | ${"quantile"} | ${[0.4]} + ${numSeries()} | ${"rank"} | ${[]} + ${numSeries()} | ${"rank"} | ${["average"]} + ${numSeries()} | ${"rechunk"} | ${[]} + ${numSeries()} | ${"rechunk"} | ${[true]} + ${numSeries()} | ${"rename"} | ${["new name"]} + ${numSeries()} | ${"rename"} | ${["new name", true]} + ${numSeries()} | ${"rename"} | ${[{ name: "new name" }]} + ${numSeries()} | ${"rename"} | ${[{ name: "new name", inPlace: true }]} + ${numSeries()} | ${"rename"} | ${[{ name: "new name" }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingMax"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingMax"} | ${[1]} + ${numSeries()} | ${"rollingMax"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingMax"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingMax"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingMean"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingMean"} | ${[1]} + ${numSeries()} | ${"rollingMean"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingMean"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingMean"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingMin"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingMin"} | ${[1]} + ${numSeries()} | ${"rollingMin"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingMin"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingMin"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingSum"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingSum"} | ${[1]} + ${numSeries()} | ${"rollingSum"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingSum"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingSum"} | ${[1, [0.23], 1, true]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1 }]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.33] }]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.11], minPeriods: 1 }]} + ${numSeries()} | ${"rollingVar"} | ${[{ windowSize: 1, weights: [0.44], minPeriods: 1, center: false }]} + ${numSeries()} | ${"rollingVar"} | ${[1]} + ${numSeries()} | ${"rollingVar"} | ${[1, [0.11]]} + ${numSeries()} | ${"rollingVar"} | ${[1, [0.11], 1]} + ${numSeries()} | ${"rollingVar"} | ${[1, [0.23], 1, true]} + ${fltSeries()} | ${"round"} | ${[1]} + ${numSeries()} | ${"sample"} | ${[]} + ${numSeries()} | ${"sample"} | ${[1, null, true]} + ${numSeries()} | ${"sample"} | ${[null, 1]} + ${numSeries()} | ${"sample"} | ${[{ n: 1 }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.5 }]} + ${numSeries()} | ${"sample"} | ${[{ n: 1, withReplacement: true }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true, seed: 1n }]} + ${numSeries()} | ${"sample"} | ${[{ frac: 0.1, withReplacement: true, seed: 1 }]} + ${numSeries()} | ${"sample"} | ${[{ n: 1, withReplacement: true, seed: 1 }]} + ${numSeries()} | ${"seriesEqual"} | ${[other()]} + ${numSeries()} | ${"seriesEqual"} | ${[other(), true]} + ${numSeries()} | ${"seriesEqual"} | ${[other(), false]} + ${numSeries()} | ${"set"} | ${[boolSeries(), 2]} + ${fltSeries()} | ${"setAtIdx"} | ${[[0, 1], 1]} + ${numSeries()} | ${"shift"} | ${[]} + ${numSeries()} | ${"shift"} | ${[1]} + ${numSeries()} | ${"shiftAndFill"} | ${[1, 2]} + ${numSeries()} | ${"shiftAndFill"} | ${[{ periods: 1, fillValue: 2 }]} + ${numSeries()} | ${"skew"} | ${[]} + ${numSeries()} | ${"skew"} | ${[true]} + ${numSeries()} | ${"skew"} | ${[false]} + ${numSeries()} | ${"skew"} | ${[{ bias: true }]} + ${numSeries()} | ${"skew"} | ${[{ bias: false }]} + ${numSeries()} | ${"slice"} | ${[1, 2]} + ${numSeries()} | ${"slice"} | ${[{ offset: 1, length: 2 }]} + ${numSeries()} | ${"sort"} | ${[]} + ${numSeries()} | ${"sort"} | ${[false]} + ${numSeries()} | ${"sort"} | ${[true]} + ${numSeries()} | ${"sort"} | ${[{ reverse: true }]} + ${numSeries()} | ${"sort"} | ${[{ reverse: false }]} + ${numSeries()} | ${"sum"} | ${[]} + ${numSeries()} | ${"tail"} | ${[]} + ${numSeries()} | ${"take"} | ${[[1, 2]]} + ${numSeries()} | ${"takeEvery"} | ${[1]} + ${numSeries()} | ${"toArray"} | ${[]} + ${numSeries()} | ${"unique"} | ${[]} + ${numSeries()} | ${"valueCounts"} | ${[]} + ${numSeries()} | ${"zipWith"} | ${[boolSeries(), other()]} + `("$# $method is callable", ({ series, method, args }) => { try { series[method](...args); } catch (err) { @@ -425,107 +417,107 @@ describe("series", () => { }); it.each` - name | actual | expected - ${"dtype:Utf8"} | ${pl.Series(["foo"]).dtype} | ${pl.Utf8} - ${"dtype:UInt64"} | ${pl.Series([1n]).dtype} | ${pl.UInt64} - ${"dtype:Float64"} | ${pl.Series([1]).dtype} | ${pl.Float64} - ${"dtype"} | ${pl.Series(["foo"]).dtype} | ${pl.Utf8} - ${"name"} | ${pl.Series("a", ["foo"]).name} | ${"a"} - ${"length"} | ${pl.Series([1, 2, 3, 4]).length} | ${4} - ${"abs"} | ${pl.Series([1, 2, -3]).abs()} | ${pl.Series([1, 2, 3])} - ${"alias"} | ${pl.Series([1, 2, 3]).as("foo")} | ${pl.Series("foo", [1, 2, 3])} - ${"alias"} | ${pl.Series([1, 2, 3]).alias("foo")} | ${pl.Series("foo", [1, 2, 3])} - ${"argMax"} | ${pl.Series([1, 2, 3]).argMax()} | ${2} - ${"argMin"} | ${pl.Series([1, 2, 3]).argMin()} | ${0} - ${"argSort"} | ${pl.Series([3, 2, 1]).argSort()} | ${pl.Series([2, 1, 0])} - ${"argTrue"} | ${pl.Series([true, false]).argTrue()} | ${pl.Series([0])} - ${"argUnique"} | ${pl.Series([1, 1, 2]).argUnique()} | ${pl.Series([0, 2])} - ${"cast-Int16"} | ${pl.Series("", [1, 1, 2]).cast(pl.Int16)} | ${pl.Series("", [1, 1, 2], pl.Int16)} - ${"cast-Int32"} | ${pl.Series("", [1, 1, 2]).cast(pl.Int32)} | ${pl.Series("", [1, 1, 2], pl.Int32)} - ${"cast-Int64"} | ${pl.Series("", [1, 1, 2]).cast(pl.Int64)} | ${pl.Series("", [1, 1, 2], pl.Int64)} - ${"cast-UInt16"} | ${pl.Series("", [1, 1, 2]).cast(pl.UInt16)} | ${pl.Series("", [1, 1, 2], pl.UInt16)} - ${"cast-UInt32"} | ${pl.Series("", [1, 1, 2]).cast(pl.UInt32)} | ${pl.Series("", [1, 1, 2], pl.UInt32)} - ${"cast-UInt64"} | ${pl.Series("", [1, 1, 2]).cast(pl.UInt64)} | ${pl.Series("", [1n, 1n, 2n])} - ${"cast-Utf8"} | ${pl.Series("", [1, 1, 2]).cast(pl.Utf8)} | ${pl.Series("", ["1.0", "1.0", "2.0"])} - ${"chunkLengths"} | ${pl.Series([1, 2, 3]).chunkLengths()[0]} | ${3} - ${"clone"} | ${pl.Series([1, 2, 3]).clone()} | ${pl.Series([1, 2, 3])} - ${"concat"} | ${pl.Series([1]).concat(pl.Series([2, 3]))} | ${pl.Series([1, 2, 3])} - ${"cumMax"} | ${pl.Series([3, 2, 4]).cumMax()} | ${pl.Series([3, 3, 4])} - ${"cumMin"} | ${pl.Series([3, 2, 4]).cumMin()} | ${pl.Series([3, 2, 2])} - ${"cumProd"} | ${pl.Series("", [1, 2, 3], pl.Int32).cumProd()} | ${pl.Series("", [1, 2, 6], pl.Int64)} - ${"cumSum"} | ${pl.Series("", [1, 2, 3], pl.Int32).cumSum()} | ${pl.Series("", [1, 3, 6], pl.Int32)} - ${"diff"} | ${pl.Series([1, 2, 12]).diff(1, "drop").toObject()} | ${pl.Series([1, 10]).toObject()} - ${"diff"} | ${pl.Series([1, 11]).diff(1, "ignore")} | ${pl.Series("", [null, 10], pl.Float64)} - ${"dropNulls"} | ${pl.Series([1, null, 2]).dropNulls()} | ${pl.Series([1, 2])} - ${"dropNulls"} | ${pl.Series([1, undefined, 2]).dropNulls()} | ${pl.Series([1, 2])} - ${"dropNulls"} | ${pl.Series(["a", null, "f"]).dropNulls()} | ${pl.Series(["a", "f"])} - ${"fillNull:zero"} | ${pl.Series([1, null, 2]).fillNull("zero")} | ${pl.Series([1, 0, 2])} - ${"fillNull:one"} | ${pl.Series([1, null, 2]).fillNull("one")} | ${pl.Series([1, 1, 2])} - ${"fillNull:max"} | ${pl.Series([1, null, 5]).fillNull("max")} | ${pl.Series([1, 5, 5])} - ${"fillNull:min"} | ${pl.Series([1, null, 5]).fillNull("min")} | ${pl.Series([1, 1, 5])} - ${"fillNull:mean"} | ${pl.Series([1, 1, null, 10]).fillNull("mean")} | ${pl.Series([1, 1, 4, 10])} - ${"fillNull:back"} | ${pl.Series([1, 1, null, 10]).fillNull("backward")} | ${pl.Series([1, 1, 10, 10])} - ${"fillNull:fwd"} | ${pl.Series([1, 1, null, 10]).fillNull("forward")} | ${pl.Series([1, 1, 1, 10])} - ${"floor"} | ${pl.Series([1.1, 2.2]).floor()} | ${pl.Series([1, 2])} - ${"get"} | ${pl.Series(["foo"]).get(0)} | ${"foo"} - ${"get"} | ${pl.Series([1, 2, 3]).get(2)} | ${3} - ${"getIndex"} | ${pl.Series(["a", "b", "c"]).getIndex(0)} | ${"a"} - ${"hasValidity"} | ${pl.Series([1, null, 2]).hasValidity()} | ${true} - ${"hasValidity"} | ${pl.Series([1, 1, 2]).hasValidity()} | ${false} - ${"hash"} | ${pl.Series([1]).hash()} | ${pl.Series([5246693565886627840n])} - ${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head()} | ${pl.Series([1, 2, 3, 4, 5])} - ${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head(2)} | ${pl.Series([1, 2])} - ${"interpolate"} | ${pl.Series([1, 2, null, null, 5]).interpolate()} | ${pl.Series([1, 2, 3, 4, 5])} - ${"isBoolean"} | ${pl.Series([1, 2, 3]).isBoolean()} | ${false} - ${"isBoolean"} | ${pl.Series([true, false]).isBoolean()} | ${true} - ${"isDateTime"} | ${pl.Series([new Date(Date.now())]).isDateTime()} | ${true} - ${"isDuplicated"} | ${pl.Series([1, 3, 3]).isDuplicated()} | ${pl.Series([false, true, true])} - ${"isFinite"} | ${pl.Series([1.0, 3.1]).isFinite()} | ${pl.Series([true, true])} - ${"isInfinite"} | ${pl.Series([1.0, 2]).isInfinite()} | ${pl.Series([false, false])} - ${"isNotNull"} | ${pl.Series([1, null, undefined, 2]).isNotNull()} | ${pl.Series([true, false, false, true])} - ${"isNull"} | ${pl.Series([1, null, undefined, 2]).isNull()} | ${pl.Series([false, true, true, false])} - ${"isNumeric"} | ${pl.Series([1, 2, 3]).isNumeric()} | ${true} - ${"isUnique"} | ${pl.Series([1, 2, 3, 1]).isUnique()} | ${pl.Series([false, true, true, false])} - ${"isUtf8"} | ${pl.Series([1, 2, 3, 1]).isUtf8()} | ${false} - ${"kurtosis"} | ${pl.Series([1, 2, 3, 3, 4]).kurtosis()?.toFixed(6)} | ${"-1.044379"} - ${"isUtf8"} | ${pl.Series(["foo"]).isUtf8()} | ${true} - ${"len"} | ${pl.Series([1, 2, 3, 4, 5]).len()} | ${5} - ${"limit"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).limit(2)} | ${pl.Series([1, 2])} - ${"max"} | ${pl.Series([-1, 10, 3]).max()} | ${10} - ${"mean"} | ${pl.Series([1, 1, 10]).mean()} | ${4} - ${"median"} | ${pl.Series([1, 1, 10]).median()} | ${1} - ${"min"} | ${pl.Series([-1, 10, 3]).min()} | ${-1} - ${"nChunks"} | ${pl.Series([1, 2, 3, 4, 4]).nChunks()} | ${1} - ${"nullCount"} | ${pl.Series([1, null, null, 4, 4]).nullCount()} | ${2} - ${"peakMax"} | ${pl.Series([9, 4, 5]).peakMax()} | ${pl.Series([true, false, true])} - ${"peakMin"} | ${pl.Series([4, 1, 3, 2, 5]).peakMin()} | ${pl.Series([false, true, false, true, false])} - ${"quantile"} | ${pl.Series([1, 2, 3]).quantile(0.5)} | ${2} - ${"rank"} | ${pl.Series([1, 2, 3, 2, 2, 3, 0]).rank("dense")} | ${pl.Series("", [2, 3, 4, 3, 3, 4, 1], pl.UInt32)} - ${"rename"} | ${pl.Series([1, 3, 0]).rename("b")} | ${pl.Series("b", [1, 3, 0])} - ${"rollingMax"} | ${pl.Series([1, 2, 3, 2, 1]).rollingMax(2)} | ${pl.Series("", [null, 2, 3, 3, 2], pl.Float64)} - ${"rollingMin"} | ${pl.Series([1, 2, 3, 2, 1]).rollingMin(2)} | ${pl.Series("", [null, 1, 2, 2, 1], pl.Float64)} - ${"rollingSum"} | ${pl.Series([1, 2, 3, 2, 1]).rollingSum(2)} | ${pl.Series("", [null, 3, 5, 5, 3], pl.Float64)} - ${"rollingMean"} | ${pl.Series([1, 2, 3, 2, 1]).rollingMean(2)} | ${pl.Series("", [null, 1.5, 2.5, 2.5, 1.5], pl.Float64)} - ${"rollingVar"} | ${pl.Series([1, 2, 3, 2, 1]).rollingVar(2)[1]} | ${0.5} - ${"sample:n"} | ${pl.Series([1, 2, 3, 4, 5]).sample(2).len()} | ${2} - ${"sample:frac"} | ${pl.Series([1, 2, 3, 4, 5]).sample({frac:.4, seed:0}).len()}| ${2} - ${"shift"} | ${pl.Series([1, 2, 3]).shift(1)} | ${pl.Series([null, 1, 2])} - ${"shift"} | ${pl.Series([1, 2, 3]).shift(-1)} | ${pl.Series([2, 3, null])} - ${"skew"} | ${pl.Series([1, 2, 3, 3, 0]).skew()?.toPrecision(6)} | ${"-0.363173"} - ${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(-3, 3)} | ${pl.Series([3, 3, 0])} - ${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(1, 3)} | ${pl.Series([2, 3, 3])} - ${"sort"} | ${pl.Series([4, 2, 5, 1, 2, 3, 3, 0]).sort()} | ${pl.Series([0, 1, 2, 2, 3, 3, 4, 5])} - ${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({reverse:true})} | ${pl.Series([5, 4, 2, 0])} - ${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({reverse:false})} | ${pl.Series([0, 2, 4, 5])} - ${"sum"} | ${pl.Series([1, 2, 2, 1]).sum()} | ${6} - ${"tail"} | ${pl.Series([1, 2, 2, 1]).tail(2)} | ${pl.Series([2, 1])} - ${"takeEvery"} | ${pl.Series([1, 3, 2, 9, 1]).takeEvery(2)} | ${pl.Series([1, 2, 1])} - ${"take"} | ${pl.Series([1, 3, 2, 9, 1]).take([0, 1, 3])} | ${pl.Series([1, 3, 9])} - ${"toArray"} | ${pl.Series([1, 2, 3]).toArray()} | ${[1, 2, 3]} - ${"unique"} | ${pl.Series([1, 2, 3, 3]).unique().sort()} | ${pl.Series([1, 2, 3])} - ${"shiftAndFill"} | ${pl.Series("foo", [1, 2, 3]).shiftAndFill(1, 99)} | ${pl.Series("foo", [99, 1, 2])} - `("$# $name: expected matches actual ", ({expected, actual}) => { - if(pl.Series.isSeries(expected) && pl.Series.isSeries(actual)) { + name | actual | expected + ${"dtype:Utf8"} | ${pl.Series(["foo"]).dtype} | ${pl.Utf8} + ${"dtype:UInt64"} | ${pl.Series([1n]).dtype} | ${pl.UInt64} + ${"dtype:Float64"} | ${pl.Series([1]).dtype} | ${pl.Float64} + ${"dtype"} | ${pl.Series(["foo"]).dtype} | ${pl.Utf8} + ${"name"} | ${pl.Series("a", ["foo"]).name} | ${"a"} + ${"length"} | ${pl.Series([1, 2, 3, 4]).length} | ${4} + ${"abs"} | ${pl.Series([1, 2, -3]).abs()} | ${pl.Series([1, 2, 3])} + ${"alias"} | ${pl.Series([1, 2, 3]).as("foo")} | ${pl.Series("foo", [1, 2, 3])} + ${"alias"} | ${pl.Series([1, 2, 3]).alias("foo")} | ${pl.Series("foo", [1, 2, 3])} + ${"argMax"} | ${pl.Series([1, 2, 3]).argMax()} | ${2} + ${"argMin"} | ${pl.Series([1, 2, 3]).argMin()} | ${0} + ${"argSort"} | ${pl.Series([3, 2, 1]).argSort()} | ${pl.Series([2, 1, 0])} + ${"argTrue"} | ${pl.Series([true, false]).argTrue()} | ${pl.Series([0])} + ${"argUnique"} | ${pl.Series([1, 1, 2]).argUnique()} | ${pl.Series([0, 2])} + ${"cast-Int16"} | ${pl.Series("", [1, 1, 2]).cast(pl.Int16)} | ${pl.Series("", [1, 1, 2], pl.Int16)} + ${"cast-Int32"} | ${pl.Series("", [1, 1, 2]).cast(pl.Int32)} | ${pl.Series("", [1, 1, 2], pl.Int32)} + ${"cast-Int64"} | ${pl.Series("", [1, 1, 2]).cast(pl.Int64)} | ${pl.Series("", [1, 1, 2], pl.Int64)} + ${"cast-UInt16"} | ${pl.Series("", [1, 1, 2]).cast(pl.UInt16)} | ${pl.Series("", [1, 1, 2], pl.UInt16)} + ${"cast-UInt32"} | ${pl.Series("", [1, 1, 2]).cast(pl.UInt32)} | ${pl.Series("", [1, 1, 2], pl.UInt32)} + ${"cast-UInt64"} | ${pl.Series("", [1, 1, 2]).cast(pl.UInt64)} | ${pl.Series("", [1n, 1n, 2n])} + ${"cast-Utf8"} | ${pl.Series("", [1, 1, 2]).cast(pl.Utf8)} | ${pl.Series("", ["1.0", "1.0", "2.0"])} + ${"chunkLengths"} | ${pl.Series([1, 2, 3]).chunkLengths()[0]} | ${3} + ${"clone"} | ${pl.Series([1, 2, 3]).clone()} | ${pl.Series([1, 2, 3])} + ${"concat"} | ${pl.Series([1]).concat(pl.Series([2, 3]))} | ${pl.Series([1, 2, 3])} + ${"cumMax"} | ${pl.Series([3, 2, 4]).cumMax()} | ${pl.Series([3, 3, 4])} + ${"cumMin"} | ${pl.Series([3, 2, 4]).cumMin()} | ${pl.Series([3, 2, 2])} + ${"cumProd"} | ${pl.Series("", [1, 2, 3], pl.Int32).cumProd()} | ${pl.Series("", [1, 2, 6], pl.Int64)} + ${"cumSum"} | ${pl.Series("", [1, 2, 3], pl.Int32).cumSum()} | ${pl.Series("", [1, 3, 6], pl.Int32)} + ${"diff"} | ${pl.Series([1, 2, 12]).diff(1, "drop").toObject()} | ${pl.Series([1, 10]).toObject()} + ${"diff"} | ${pl.Series([1, 11]).diff(1, "ignore")} | ${pl.Series("", [null, 10], pl.Float64)} + ${"dropNulls"} | ${pl.Series([1, null, 2]).dropNulls()} | ${pl.Series([1, 2])} + ${"dropNulls"} | ${pl.Series([1, undefined, 2]).dropNulls()} | ${pl.Series([1, 2])} + ${"dropNulls"} | ${pl.Series(["a", null, "f"]).dropNulls()} | ${pl.Series(["a", "f"])} + ${"fillNull:zero"} | ${pl.Series([1, null, 2]).fillNull("zero")} | ${pl.Series([1, 0, 2])} + ${"fillNull:one"} | ${pl.Series([1, null, 2]).fillNull("one")} | ${pl.Series([1, 1, 2])} + ${"fillNull:max"} | ${pl.Series([1, null, 5]).fillNull("max")} | ${pl.Series([1, 5, 5])} + ${"fillNull:min"} | ${pl.Series([1, null, 5]).fillNull("min")} | ${pl.Series([1, 1, 5])} + ${"fillNull:mean"} | ${pl.Series([1, 1, null, 10]).fillNull("mean")} | ${pl.Series([1, 1, 4, 10])} + ${"fillNull:back"} | ${pl.Series([1, 1, null, 10]).fillNull("backward")} | ${pl.Series([1, 1, 10, 10])} + ${"fillNull:fwd"} | ${pl.Series([1, 1, null, 10]).fillNull("forward")} | ${pl.Series([1, 1, 1, 10])} + ${"floor"} | ${pl.Series([1.1, 2.2]).floor()} | ${pl.Series([1, 2])} + ${"get"} | ${pl.Series(["foo"]).get(0)} | ${"foo"} + ${"get"} | ${pl.Series([1, 2, 3]).get(2)} | ${3} + ${"getIndex"} | ${pl.Series(["a", "b", "c"]).getIndex(0)} | ${"a"} + ${"hasValidity"} | ${pl.Series([1, null, 2]).hasValidity()} | ${true} + ${"hasValidity"} | ${pl.Series([1, 1, 2]).hasValidity()} | ${false} + ${"hash"} | ${pl.Series([1]).hash()} | ${pl.Series([5246693565886627840n])} + ${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head()} | ${pl.Series([1, 2, 3, 4, 5])} + ${"head"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).head(2)} | ${pl.Series([1, 2])} + ${"interpolate"} | ${pl.Series([1, 2, null, null, 5]).interpolate()} | ${pl.Series([1, 2, 3, 4, 5])} + ${"isBoolean"} | ${pl.Series([1, 2, 3]).isBoolean()} | ${false} + ${"isBoolean"} | ${pl.Series([true, false]).isBoolean()} | ${true} + ${"isDateTime"} | ${pl.Series([new Date(Date.now())]).isDateTime()} | ${true} + ${"isDuplicated"} | ${pl.Series([1, 3, 3]).isDuplicated()} | ${pl.Series([false, true, true])} + ${"isFinite"} | ${pl.Series([1.0, 3.1]).isFinite()} | ${pl.Series([true, true])} + ${"isInfinite"} | ${pl.Series([1.0, 2]).isInfinite()} | ${pl.Series([false, false])} + ${"isNotNull"} | ${pl.Series([1, null, undefined, 2]).isNotNull()} | ${pl.Series([true, false, false, true])} + ${"isNull"} | ${pl.Series([1, null, undefined, 2]).isNull()} | ${pl.Series([false, true, true, false])} + ${"isNumeric"} | ${pl.Series([1, 2, 3]).isNumeric()} | ${true} + ${"isUnique"} | ${pl.Series([1, 2, 3, 1]).isUnique()} | ${pl.Series([false, true, true, false])} + ${"isUtf8"} | ${pl.Series([1, 2, 3, 1]).isUtf8()} | ${false} + ${"kurtosis"} | ${pl.Series([1, 2, 3, 3, 4]).kurtosis()?.toFixed(6)} | ${"-1.044379"} + ${"isUtf8"} | ${pl.Series(["foo"]).isUtf8()} | ${true} + ${"len"} | ${pl.Series([1, 2, 3, 4, 5]).len()} | ${5} + ${"limit"} | ${pl.Series([1, 2, 3, 4, 5, 5, 5]).limit(2)} | ${pl.Series([1, 2])} + ${"max"} | ${pl.Series([-1, 10, 3]).max()} | ${10} + ${"mean"} | ${pl.Series([1, 1, 10]).mean()} | ${4} + ${"median"} | ${pl.Series([1, 1, 10]).median()} | ${1} + ${"min"} | ${pl.Series([-1, 10, 3]).min()} | ${-1} + ${"nChunks"} | ${pl.Series([1, 2, 3, 4, 4]).nChunks()} | ${1} + ${"nullCount"} | ${pl.Series([1, null, null, 4, 4]).nullCount()} | ${2} + ${"peakMax"} | ${pl.Series([9, 4, 5]).peakMax()} | ${pl.Series([true, false, true])} + ${"peakMin"} | ${pl.Series([4, 1, 3, 2, 5]).peakMin()} | ${pl.Series([false, true, false, true, false])} + ${"quantile"} | ${pl.Series([1, 2, 3]).quantile(0.5)} | ${2} + ${"rank"} | ${pl.Series([1, 2, 3, 2, 2, 3, 0]).rank("dense")} | ${pl.Series("", [2, 3, 4, 3, 3, 4, 1], pl.UInt32)} + ${"rename"} | ${pl.Series([1, 3, 0]).rename("b")} | ${pl.Series("b", [1, 3, 0])} + ${"rollingMax"} | ${pl.Series([1, 2, 3, 2, 1]).rollingMax(2)} | ${pl.Series("", [null, 2, 3, 3, 2], pl.Float64)} + ${"rollingMin"} | ${pl.Series([1, 2, 3, 2, 1]).rollingMin(2)} | ${pl.Series("", [null, 1, 2, 2, 1], pl.Float64)} + ${"rollingSum"} | ${pl.Series([1, 2, 3, 2, 1]).rollingSum(2)} | ${pl.Series("", [null, 3, 5, 5, 3], pl.Float64)} + ${"rollingMean"} | ${pl.Series([1, 2, 3, 2, 1]).rollingMean(2)} | ${pl.Series("", [null, 1.5, 2.5, 2.5, 1.5], pl.Float64)} + ${"rollingVar"} | ${pl.Series([1, 2, 3, 2, 1]).rollingVar(2)[1]} | ${0.5} + ${"sample:n"} | ${pl.Series([1, 2, 3, 4, 5]).sample(2).len()} | ${2} + ${"sample:frac"} | ${pl.Series([1, 2, 3, 4, 5]).sample({ frac: 0.4, seed: 0 }).len()} | ${2} + ${"shift"} | ${pl.Series([1, 2, 3]).shift(1)} | ${pl.Series([null, 1, 2])} + ${"shift"} | ${pl.Series([1, 2, 3]).shift(-1)} | ${pl.Series([2, 3, null])} + ${"skew"} | ${pl.Series([1, 2, 3, 3, 0]).skew()?.toPrecision(6)} | ${"-0.363173"} + ${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(-3, 3)} | ${pl.Series([3, 3, 0])} + ${"slice"} | ${pl.Series([1, 2, 3, 3, 0]).slice(1, 3)} | ${pl.Series([2, 3, 3])} + ${"sort"} | ${pl.Series([4, 2, 5, 1, 2, 3, 3, 0]).sort()} | ${pl.Series([0, 1, 2, 2, 3, 3, 4, 5])} + ${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ reverse: true })} | ${pl.Series([5, 4, 2, 0])} + ${"sort"} | ${pl.Series([4, 2, 5, 0]).sort({ reverse: false })} | ${pl.Series([0, 2, 4, 5])} + ${"sum"} | ${pl.Series([1, 2, 2, 1]).sum()} | ${6} + ${"tail"} | ${pl.Series([1, 2, 2, 1]).tail(2)} | ${pl.Series([2, 1])} + ${"takeEvery"} | ${pl.Series([1, 3, 2, 9, 1]).takeEvery(2)} | ${pl.Series([1, 2, 1])} + ${"take"} | ${pl.Series([1, 3, 2, 9, 1]).take([0, 1, 3])} | ${pl.Series([1, 3, 9])} + ${"toArray"} | ${pl.Series([1, 2, 3]).toArray()} | ${[1, 2, 3]} + ${"unique"} | ${pl.Series([1, 2, 3, 3]).unique().sort()} | ${pl.Series([1, 2, 3])} + ${"shiftAndFill"} | ${pl.Series("foo", [1, 2, 3]).shiftAndFill(1, 99)} | ${pl.Series("foo", [99, 1, 2])} + `("$# $name: expected matches actual ", ({ expected, actual }) => { + if (pl.Series.isSeries(expected) && pl.Series.isSeries(actual)) { expect(actual).toSeriesEqual(expected); } else { expect(actual).toEqual(expected); @@ -559,12 +551,12 @@ describe("series", () => { expect(() => pl.Series([1, 2, 3]).set(mask, 99)).toThrow(); }); it.each` - name | fn | errorType - ${"isFinite"} | ${pl.Series(["foo"]).isFinite} | ${TypeError} - ${"isInfinite"} | ${pl.Series(["foo"]).isInfinite} | ${TypeError} - ${"rollingMax"} | ${() => pl.Series(["foo"]).rollingMax(null as any)} | ${Error} - ${"sample"} | ${() => pl.Series(["foo"]).sample(null as any)} | ${Error} - `("$# $name throws an error ", ({fn, errorType}) => { + name | fn | errorType + ${"isFinite"} | ${pl.Series(["foo"]).isFinite} | ${TypeError} + ${"isInfinite"} | ${pl.Series(["foo"]).isInfinite} | ${TypeError} + ${"rollingMax"} | ${() => pl.Series(["foo"]).rollingMax(null as any)} | ${Error} + ${"sample"} | ${() => pl.Series(["foo"]).sample(null as any)} | ${Error} + `("$# $name throws an error ", ({ fn, errorType }) => { expect(fn).toThrow(errorType); }); test("reinterpret", () => { @@ -602,7 +594,7 @@ describe("series", () => { test("round:named", () => { const s = pl.Series([1.1111, 2.2222]); const expected = pl.Series([1.11, 2.22]); - const actual = s.round({decimals: 2}); + const actual = s.round({ decimals: 2 }); expect(actual).toSeriesEqual(expected); }); }); @@ -682,16 +674,15 @@ describe("comparators & math", () => { }); describe("StringFunctions", () => { it.each` - name | actual | expected - ${"toUpperCase"} | ${pl.Series(["foo"]).str.toUpperCase()} | ${pl.Series(["FOO"])} - ${"lstrip"} | ${pl.Series([" foo"]).str.lstrip()} | ${pl.Series(["foo"])} - ${"rstrip"} | ${pl.Series(["foo "]).str.rstrip()} | ${pl.Series(["foo"])} - ${"toLowerCase"} | ${pl.Series(["FOO"]).str.toLowerCase()} | ${pl.Series(["foo"])} - ${"contains"} | ${pl.Series(["f1", "f0"]).str.contains(/[0]/)} | ${pl.Series([false, true])} - ${"lengths"} | ${pl.Series(["apple", "ham"]).str.lengths()} | ${pl.Series([5, 3])} - ${"slice"} | ${pl.Series(["apple", "ham"]).str.slice(1)} | ${pl.Series(["pple", "am"])} - `("$# $name expected matches actual", ({expected, actual}) => { - + name | actual | expected + ${"toUpperCase"} | ${pl.Series(["foo"]).str.toUpperCase()} | ${pl.Series(["FOO"])} + ${"lstrip"} | ${pl.Series([" foo"]).str.lstrip()} | ${pl.Series(["foo"])} + ${"rstrip"} | ${pl.Series(["foo "]).str.rstrip()} | ${pl.Series(["foo"])} + ${"toLowerCase"} | ${pl.Series(["FOO"]).str.toLowerCase()} | ${pl.Series(["foo"])} + ${"contains"} | ${pl.Series(["f1", "f0"]).str.contains(/[0]/)} | ${pl.Series([false, true])} + ${"lengths"} | ${pl.Series(["apple", "ham"]).str.lengths()} | ${pl.Series([5, 3])} + ${"slice"} | ${pl.Series(["apple", "ham"]).str.slice(1)} | ${pl.Series(["pple", "am"])} + `("$# $name expected matches actual", ({ expected, actual }) => { expect(expected).toStrictEqual(actual); }); @@ -709,8 +700,9 @@ describe("StringFunctions", () => { }); test("hex decode strict", () => { const s = pl.Series("encoded", ["666f6f", "626172", "invalid", null]); - const fn0 = () => s.str.decode("hex", true).alias("decoded"); - const fn1 = () => s.str.decode({encoding: "hex", strict: true}).alias("decoded"); + const fn0 = () => s.str.decode("hex", true).alias("decoded"); + const fn1 = () => + s.str.decode({ encoding: "hex", strict: true }).alias("decoded"); expect(fn0).toThrow(); expect(fn1).toThrow(); }); @@ -721,9 +713,15 @@ describe("StringFunctions", () => { expect(encoded).toSeriesEqual(expected); }); test("base64 decode strict", () => { - const s = pl.Series("encoded", ["Zm9v", "YmFy", "not base64 encoded", null]); - const fn0 = () => s.str.decode("base64", true).alias("decoded"); - const fn1 = () => s.str.decode({encoding: "base64", strict: true}).alias("decoded"); + const s = pl.Series("encoded", [ + "Zm9v", + "YmFy", + "not base64 encoded", + null, + ]); + const fn0 = () => s.str.decode("base64", true).alias("decoded"); + const fn1 = () => + s.str.decode({ encoding: "base64", strict: true }).alias("decoded"); expect(fn0).toThrow(); expect(fn1).toThrow(); }); @@ -731,7 +729,7 @@ describe("StringFunctions", () => { const s = pl.Series("encoded", ["Zm9v", "YmFy", "invalid", null]); const decoded = pl.Series("decoded", ["foo", "bar", null, null]); - const actual = s.str.decode("base64").alias("decoded"); + const actual = s.str.decode("base64").alias("decoded"); expect(actual).toSeriesEqual(decoded); }); }); diff --git a/__tests__/setup.ts b/__tests__/setup.ts index 8c6ed70da..68f0f411d 100644 --- a/__tests__/setup.ts +++ b/__tests__/setup.ts @@ -1,15 +1,14 @@ import pl from "@polars/index"; expect.extend({ - toSeriesStrictEqual(actual, expected){ + toSeriesStrictEqual(actual, expected) { const seriesEq = actual.seriesEqual(expected); const typesEq = actual.dtype.equals(expected.dtype); - if(seriesEq && typesEq) { + if (seriesEq && typesEq) { return { message: () => "series matches", - pass: true + pass: true, }; - } else { return { message: () => ` @@ -17,18 +16,17 @@ Expected: >>${expected} Received: >>${actual}`, - pass: false + pass: false, }; } }, toSeriesEqual(actual, expected) { const pass = actual.seriesEqual(expected); - if(pass) { + if (pass) { return { message: () => "series matches", - pass: true + pass: true, }; - } else { return { message: () => ` @@ -36,36 +34,35 @@ Expected: >>${expected} Received: >>${actual}`, - pass: false + pass: false, }; } }, toFrameEqual(actual, expected, nullEqual?) { const pass = actual.frameEqual(expected, nullEqual); - if(pass) { + if (pass) { return { message: () => "dataframes match", - pass: true + pass: true, }; } else { - return { message: () => ` Expected: >>${expected} Received: >>${actual}`, - pass: false + pass: false, }; } }, toFrameStrictEqual(actual, expected) { const frameEq = actual.frameEqual(expected); const dtypesEq = this.equals(actual.dtypes, expected.dtypes); - if(frameEq && dtypesEq) { + if (frameEq && dtypesEq) { return { message: () => "dataframes match", - pass: true + pass: true, }; } else { return { @@ -74,7 +71,7 @@ Expected: >>${expected} Received: >>${actual}`, - pass: false + pass: false, }; } }, @@ -82,47 +79,43 @@ Received: actual = actual.sort(actual.columns.sort()); expected = expected.sort(expected.columns.sort()); const pass = actual.frameEqual(expected); - if(pass) { + if (pass) { return { message: () => "dataframes match", - pass: true + pass: true, }; } else { - return { message: () => ` Expected: >>${expected} Received: >>${actual}`, - pass: false + pass: false, }; } - } + }, }); export const df = () => { - const df = pl.DataFrame( - { - "bools": [false, true, false], - "bools_nulls": [null, true, false], - "int": [1, 2, 3], - "int_nulls": [1, null, 3], - "bigint": [1n, 2n, 3n], - "bigint_nulls": [1n, null, 3n], - "floats": [1.0, 2.0, 3.0], - "floats_nulls": [1.0, null, 3.0], - "strings": ["foo", "bar", "ham"], - "strings_nulls": ["foo", null, "ham"], - "date": [new Date(), new Date(), new Date()], - "datetime": [13241324, 12341256, 12341234], - }); + const df = pl.DataFrame({ + bools: [false, true, false], + bools_nulls: [null, true, false], + int: [1, 2, 3], + int_nulls: [1, null, 3], + bigint: [1n, 2n, 3n], + bigint_nulls: [1n, null, 3n], + floats: [1.0, 2.0, 3.0], + floats_nulls: [1.0, null, 3.0], + strings: ["foo", "bar", "ham"], + strings_nulls: ["foo", null, "ham"], + date: [new Date(), new Date(), new Date()], + datetime: [13241324, 12341256, 12341234], + }); return df.withColumns( - pl.col("date").cast(pl.Date), pl.col("datetime").cast(pl.Datetime("ms")), - pl.col("strings").cast(pl.Categorical) - .alias("cat") + pl.col("strings").cast(pl.Categorical).alias("cat"), ); }; diff --git a/__tests__/struct.test.ts b/__tests__/struct.test.ts index e78d67a4b..8c695fa3e 100644 --- a/__tests__/struct.test.ts +++ b/__tests__/struct.test.ts @@ -1,11 +1,10 @@ - import pl from "@polars"; describe("struct", () => { test("series <--> array round trip", () => { const data = [ - {utf8: "a", f64: 1, }, - {utf8: "b", f64: 2, } + { utf8: "a", f64: 1 }, + { utf8: "b", f64: 2 }, ]; const name = "struct"; const s = pl.Series(name, data); @@ -13,10 +12,12 @@ describe("struct", () => { expect(s.toArray()).toEqual(data); }); test("pli.struct", () => { - const expected = pl.DataFrame({ - foo: [1], - bar: [2] - }).toStruct("foo"); + const expected = pl + .DataFrame({ + foo: [1], + bar: [2], + }) + .toStruct("foo"); const foo = pl.Series("foo", [1]); const bar = pl.Series("bar", [2]); const actual = pl.struct([foo, bar]).rename("foo"); @@ -25,7 +26,7 @@ describe("struct", () => { test("pli.struct dataframe", () => { const df = pl.DataFrame({ foo: [1], - bar: [2] + bar: [2], }); const actual = df .select(pl.struct(pl.cols("foo", "bar")).alias("s")) @@ -33,17 +34,18 @@ describe("struct", () => { expect(actual).toSeriesEqual(df.toStruct("s")); }); test("struct toArray", () => { - const actual = pl.DataFrame({ - foo: [1, 10, 100], - bar: [2, null, 200] - }) + const actual = pl + .DataFrame({ + foo: [1, 10, 100], + bar: [2, null, 200], + }) .toStruct("foobar") .toArray(); const expected = [ - {foo: 1, bar: 2}, - {foo: 10, bar: null}, - {foo: 100, bar: 200} + { foo: 1, bar: 2 }, + { foo: 10, bar: null }, + { foo: 100, bar: 200 }, ]; expect(actual).toEqual(expected); }); diff --git a/__tests__/whenthen.test.ts b/__tests__/whenthen.test.ts index 36d76b057..12f4ba6ea 100644 --- a/__tests__/whenthen.test.ts +++ b/__tests__/whenthen.test.ts @@ -1,4 +1,4 @@ -import pl, {col, lit, when} from "@polars"; +import pl, { col, lit, when } from "@polars"; describe("when", () => { test("when(a).then(b).otherwise(c)", () => { @@ -7,15 +7,17 @@ describe("when", () => { .otherwise(lit(-1)) .as("when"); - const actual = pl.DataFrame({ - "foo": [1, 3, 4], - "bar": [3, 4, 0] - }).withColumn(expr); + const actual = pl + .DataFrame({ + foo: [1, 3, 4], + bar: [3, 4, 0], + }) + .withColumn(expr); const expected = pl.DataFrame({ - "foo": [1, 3, 4], - "bar": [3, 4, 0], - "when": [-1, 1, 1] + foo: [1, 3, 4], + bar: [3, 4, 0], + when: [-1, 1, 1], }); expect(actual).toFrameEqual(expected); }); @@ -24,21 +26,22 @@ describe("when", () => { .then(lit("foo=1")) .when(col("foo").eq(3)) .then(lit("foo=3")) - .when(col("bar").eq(0) - .and(col("foo").eq(4))) + .when(col("bar").eq(0).and(col("foo").eq(4))) .then(lit("bar=0, foo=4")) .otherwise(lit("unknown")) .as("when"); - const actual = pl.DataFrame({ - "foo": [1, 3, 4, 5], - "bar": [3, 4, 0, 1] - }).withColumn(expr); + const actual = pl + .DataFrame({ + foo: [1, 3, 4, 5], + bar: [3, 4, 0, 1], + }) + .withColumn(expr); const expected = pl.DataFrame({ - "foo": [1, 3, 4, 5], - "bar": [3, 4, 0, 1], - "when": ["foo=1", "foo=3", "bar=0, foo=4", "unknown"] + foo: [1, 3, 4, 5], + bar: [3, 4, 0, 1], + when: ["foo=1", "foo=3", "bar=0, foo=4", "unknown"], }); expect(actual).toFrameEqual(expected); }); diff --git a/package.json b/package.json index 50f8dd4ff..2b02321c9 100644 --- a/package.json +++ b/package.json @@ -43,36 +43,27 @@ "build:ts": " rm -rf bin; tsc -p tsconfig.build.json", "cp:bin": "cp ./polars/*.node bin/", "format:rs": "cargo fmt", - "format:source": "prettier --config ./package.json --write './**/*.{js,ts}'", - "format:yaml": "prettier --parser yaml --write './**/*.{yml,yaml}'", - "lint:ts": "eslint -c ./.eslintrc.json 'polars/**/*.{ts,tsx,js}' '__tests__/*.ts'", + "lint:ts:fix": "rome check --apply-suggested {polars,__tests__} && rome format --write {polars,__tests__}", + "lint:ts": "rome check {polars,__tests__} && rome format {polars,__tests__}", + "lint": "yarn lint:ts && yarn format:rs", "prepublishOnly": "napi prepublish -t npm", "test": "jest", - "version": "napi version" + "version": "napi version", + "precommit": "yarn lint && yarn test" }, "devDependencies": { "@napi-rs/cli": "^2.14.1", "@types/chance": "^1.1.3", "@types/jest": "^27.0.3", "@types/node": "^16.11.9", - "@typescript-eslint/eslint-plugin": "^5.4.0", - "@typescript-eslint/parser": "^5.4.0", "chance": "^1.1.8", - "eslint": "^8.1.0", - "eslint-config-prettier": "^8.3.0", - "eslint-plugin-import": "^2.25.3", - "eslint-plugin-jest": "^25.2.4", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-prettier": "^4.0.0", - "husky": "^7.0.4", "jest": "^27.3.1", - "lint-staged": "^11.2.6", - "prettier": "^2.4.1", + "rome": "^11.0.0", "source-map-support": "^0.5.21", "ts-jest": "^27.1.0", "ts-node": "^10.4.0", - "typedoc": "^0.22.9", - "typescript": "4.4.3" + "typedoc": "^0.23", + "typescript": "4.9" }, "packageManager": "yarn@3.3.1", "workspaces": [ diff --git a/polars/cfg.ts b/polars/cfg.ts index cd5a96506..ba1c6eeb8 100644 --- a/polars/cfg.ts +++ b/polars/cfg.ts @@ -1,24 +1,31 @@ import pli from "./native-polars"; + +/** + * Configure polars; offers options for table formatting and more. + */ export interface Config { /** Use utf8 characters to print tables */ - setUtf8Tables(): Config + setUtf8Tables(): Config; /** Use ascii characters to print tables */ - setAsciiTables(): Config + setAsciiTables(): Config; /** Set the number of character used to draw the table */ - setTblWidthChars(width: number): Config + setTblWidthChars(width: number): Config; /** Set the number of rows used to print tables */ - setTblRows(n: number): Config + setTblRows(n: number): Config; /** Set the number of columns used to print tables */ - setTblCols(n: number): Config + setTblCols(n: number): Config; /** Turn on the global string cache */ - setGlobalStringCache(): Config + setGlobalStringCache(): Config; /** Turn off the global string cache */ - unsetGlobalStringCache(): Config + unsetGlobalStringCache(): Config; } + +/** + * @ignore + */ export const Config: Config = { setUtf8Tables() { - - delete process.env["POLARS_FMT_NO_UTF8"]; + process.env["POLARS_FMT_NO_UTF8"] = undefined; return this; }, @@ -28,7 +35,6 @@ export const Config: Config = { return this; }, setTblWidthChars(width) { - process.env["POLARS_TABLE_WIDTH"] = String(width); return this; @@ -52,5 +58,5 @@ export const Config: Config = { pli.toggleStringCache(false); return this; - } + }, }; diff --git a/polars/dataframe.ts b/polars/dataframe.ts index feab1a7ae..de1e53921 100644 --- a/polars/dataframe.ts +++ b/polars/dataframe.ts @@ -1,19 +1,26 @@ import pli from "./internals/polars_internal"; -import {arrayToJsDataFrame} from "./internals/construction"; -import {DynamicGroupBy, GroupBy, RollingGroupBy} from "./groupby"; -import {LazyDataFrame, _LazyDataFrame} from "./lazy/dataframe"; -import {concat} from "./functions"; -import {Expr} from "./lazy/expr"; -import {Series, _Series} from "./series/series"; -import {Stream, Writable} from "stream"; +import { arrayToJsDataFrame } from "./internals/construction"; +import { DynamicGroupBy, _GroupBy, GroupBy, RollingGroupBy } from "./groupby"; +import { LazyDataFrame, _LazyDataFrame } from "./lazy/dataframe"; +import { concat } from "./functions"; +import { Expr } from "./lazy/expr"; +import { Series, _Series } from "./series"; +import { Stream, Writable } from "stream"; +import { + WriteCsvOptions, + WriteIPCOptions, + WriteParquetOptions, + WriteAvroOptions, + FillNullStrategy, + JoinOptions, +} from "./types"; -import {DataType, JoinBaseOptions} from "./datatypes"; +import { DataType } from "./datatypes"; import { columnOrColumns, columnOrColumnsStrict, ColumnSelection, - FillNullStrategy, isSeriesArray, ColumnsOrExpr, ValueOrArray, @@ -27,39 +34,14 @@ import { Sample, Serialize, } from "./shared_traits"; -import {col, element} from "./lazy/functions"; -const inspect = Symbol.for("nodejs.util.inspect.custom"); - -type WriteCsvOptions = { - hasHeader?: boolean; - sep?: string; -}; +import { col, element } from "./lazy/functions"; -type WriteJsonOptions = { - orient?: "row" | "col" | "dataframe"; - multiline?: boolean; -}; - -type WriteParquetOptions = { - compression?: - | "uncompressed" - | "snappy" - | "gzip" - | "lzo" - | "brotli" - | "lz4" - | "zstd"; -}; - -type WriteIPCOptions = { - compression?: "uncompressed" | "lz4" | "zstd"; -}; - -type WriteAvroOptions = { - compression?: "uncompressed" | "snappy" | "deflate"; -}; +const inspect = Symbol.for("nodejs.util.inspect.custom"); +/** + * Write methods for DataFrame + */ interface WriteMethods { /** * __Write DataFrame to comma-separated values file (csv).__ @@ -72,33 +54,34 @@ interface WriteMethods { * @param options.sep - Separate CSV fields with this symbol. _defaults to `,`_ * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.writeCSV() + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.writeCSV() * foo,bar,ham * 1,6,a * 2,7,b * 3,8,c * * // using a file path - * >>> df.head(1).writeCSV("./foo.csv") + * > df.head(1).writeCSV("./foo.csv") * // foo.csv * foo,bar,ham * 1,6,a * * // using a write stream - * >>> const writeStream = new Stream.Writable({ - * >>> write(chunk, encoding, callback) { - * >>> console.log("writeStream: %O', chunk.toString()); - * >>> callback(null); - * >>> } - * >>> }); - * >>> df.head(1).writeCSV(writeStream, {hasHeader: false}) + * > const writeStream = new Stream.Writable({ + * ... write(chunk, encoding, callback) { + * ... console.log("writeStream: %O', chunk.toString()); + * ... callback(null); + * ... } + * ... }); + * > df.head(1).writeCSV(writeStream, {hasHeader: false}) * writeStream: '1,6,a' * ``` + * @category IO */ writeCSV(): Buffer; writeCSV(options: WriteCsvOptions): Buffer; @@ -110,34 +93,36 @@ interface WriteMethods { * @param options.format - json | lines * @example * ``` - * >>> const df = pl.DataFrame({ - * >>> foo: [1,2,3], - * >>> bar: ['a','b','c'] - * >>> }) + * > const df = pl.DataFrame({ + * ... foo: [1,2,3], + * ... bar: ['a','b','c'] + * ... }) * * - * >>> df.writeJSON({format:"json"}) + * > df.writeJSON({format:"json"}) * `[ {"foo":1.0,"bar":"a"}, {"foo":2.0,"bar":"b"}, {"foo":3.0,"bar":"c"}]` * - * >>> df.writeJSON({format:"lines"}) + * > df.writeJSON({format:"lines"}) * `{"foo":1.0,"bar":"a"} * {"foo":2.0,"bar":"b"} * {"foo":3.0,"bar":"c"}` * * // writing to a file - * >>> df.writeJSON("/path/to/file.json", {format:'lines'}) + * > df.writeJSON("/path/to/file.json", {format:'lines'}) * ``` + * @category IO */ - writeJSON(options?: {format: "lines" | "json"}): Buffer; + writeJSON(options?: { format: "lines" | "json" }): Buffer; writeJSON( destination: string | Writable, - options?: {format: "lines" | "json"} + options?: { format: "lines" | "json" }, ): void; /** * Write to Arrow IPC binary stream, or a feather file. * @param file File path to which the file should be written. * @param options.compression Compression method *defaults to "uncompressed"* - * */ + * @category IO + */ writeIPC(options?: WriteIPCOptions): Buffer; writeIPC(destination: string | Writable, options?: WriteIPCOptions): void; @@ -145,110 +130,108 @@ interface WriteMethods { * Write the DataFrame disk in parquet format. * @param file File path to which the file should be written. * @param options.compression Compression method *defaults to "uncompressed"* - * */ + * @category IO + */ writeParquet(options?: WriteParquetOptions): Buffer; writeParquet( destination: string | Writable, - options?: WriteParquetOptions + options?: WriteParquetOptions, ): void; /** * Write the DataFrame disk in avro format. * @param file File path to which the file should be written. * @param options.compression Compression method *defaults to "uncompressed"* - * + * @category IO */ writeAvro(options?: WriteAvroOptions): Buffer; writeAvro(destination: string | Writable, options?: WriteAvroOptions): void; } /** + * A DataFrame is a two-dimensional data structure that represents data as a table + * with rows and columns. + * + * @param data - Object, Array, or Series + * Two-dimensional data in various forms. object must contain Arrays. + * Array may contain Series or other Arrays. + * @param columns - Array of str, default undefined + * Column labels to use for resulting DataFrame. If specified, overrides any + * labels already present in the data. Must match data dimensions. + * @param orient - 'col' | 'row' default undefined + * Whether to interpret two-dimensional data as columns or as rows. If None, + * the orientation is inferred by matching the columns and data dimensions. If + * this does not yield conclusive results, column orientation is used. + * @example + * Constructing a DataFrame from an object : + * ``` + * > data = {'a': [1n, 2n], 'b': [3, 4]} + * > df = pl.DataFrame(data) + * > df + * shape: (2, 2) + * ╭─────┬─────╮ + * │ a ┆ b │ + * │ --- ┆ --- │ + * │ u64 ┆ i64 │ + * ╞═════╪═════╡ + * │ 1 ┆ 3 │ + * ├╌╌╌╌╌┼╌╌╌╌╌┤ + * │ 2 ┆ 4 │ + * ╰─────┴─────╯ + * ``` + * Notice that the dtype is automatically inferred as a polars Int64: + * ``` + * > df.dtypes + * ['UInt64', `Int64'] + * ``` + * In order to specify dtypes for your columns, initialize the DataFrame with a list + * of Series instead: + * ``` + * > data = [pl.Series('col1', [1, 2], pl.Float32), + * ... pl.Series('col2', [3, 4], pl.Int64)] + * > df2 = pl.DataFrame(series) + * > df2 + * shape: (2, 2) + * ╭──────┬──────╮ + * │ col1 ┆ col2 │ + * │ --- ┆ --- │ + * │ f32 ┆ i64 │ + * ╞══════╪══════╡ + * │ 1 ┆ 3 │ + * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2 ┆ 4 │ + * ╰──────┴──────╯ + * ``` * - A DataFrame is a two-dimensional data structure that represents data as a table - with rows and columns. - - Parameters - ---------- - @param data - Object, Array, or Series - Two-dimensional data in various forms. object must contain Arrays. - Array may contain Series or other Arrays. - @param columns - Array of str, default undefined - Column labels to use for resulting DataFrame. If specified, overrides any - labels already present in the data. Must match data dimensions. - @param orient - 'col' | 'row' default undefined - Whether to interpret two-dimensional data as columns or as rows. If None, - the orientation is inferred by matching the columns and data dimensions. If - this does not yield conclusive results, column orientation is used. - Examples - -------- - Constructing a DataFrame from an object : - ``` - data = {'a': [1n, 2n], 'b': [3, 4]} - df = pl.DataFrame(data) - df - shape: (2, 2) - ╭─────┬─────╮ - │ a ┆ b │ - │ --- ┆ --- │ - │ u64 ┆ i64 │ - ╞═════╪═════╡ - │ 1 ┆ 3 │ - ├╌╌╌╌╌┼╌╌╌╌╌┤ - │ 2 ┆ 4 │ - ╰─────┴─────╯ - ``` - Notice that the dtype is automatically inferred as a polars Int64: - ``` - df.dtypes - ['UInt64', `Int64'] - ``` - In order to specify dtypes for your columns, initialize the DataFrame with a list - of Series instead: - ``` - data = [pl.Series('col1', [1, 2], pl.Float32), - ... pl.Series('col2', [3, 4], pl.Int64)] - df2 = pl.DataFrame(series) - df2 - shape: (2, 2) - ╭──────┬──────╮ - │ col1 ┆ col2 │ - │ --- ┆ --- │ - │ f32 ┆ i64 │ - ╞══════╪══════╡ - │ 1 ┆ 3 │ - ├╌╌╌╌╌╌┼╌╌╌╌╌╌┤ - │ 2 ┆ 4 │ - ╰──────┴──────╯ - ``` - - Constructing a DataFrame from a list of lists, row orientation inferred: - ``` - data = [[1, 2, 3], [4, 5, 6]] - df4 = pl.DataFrame(data, ['a', 'b', 'c']) - df4 - shape: (2, 3) - ╭─────┬─────┬─────╮ - │ a ┆ b ┆ c │ - │ --- ┆ --- ┆ --- │ - │ i64 ┆ i64 ┆ i64 │ - ╞═════╪═════╪═════╡ - │ 1 ┆ 2 ┆ 3 │ - ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤ - │ 4 ┆ 5 ┆ 6 │ - ╰─────┴─────┴─────╯ - ``` + * Constructing a DataFrame from a list of lists, row orientation inferred: + * ``` + * > data = [[1, 2, 3], [4, 5, 6]] + * > df4 = pl.DataFrame(data, ['a', 'b', 'c']) + * > df4 + * shape: (2, 3) + * ╭─────┬─────┬─────╮ + * │ a ┆ b ┆ c │ + * │ --- ┆ --- ┆ --- │ + * │ i64 ┆ i64 ┆ i64 │ + * ╞═════╪═════╪═════╡ + * │ 1 ┆ 2 ┆ 3 │ + * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤ + * │ 4 ┆ 5 ┆ 6 │ + * ╰─────┴─────┴─────╯ + * ``` */ export interface DataFrame extends Arithmetic, - Sample, - WriteMethods, - Serialize, - GroupByOps { + Sample, + Arithmetic, + WriteMethods, + Serialize, + GroupByOps { /** @ignore */ _df: any; dtypes: DataType[]; height: number; - shape: {height: number; width: number}; + shape: { height: number; width: number }; width: number; get columns(): string[]; set columns(cols: string[]); @@ -265,12 +248,12 @@ export interface DataFrame * ___ * Example * ``` - * > df = pl.DataFrame({ - * > 'a': [1.0, 2.8, 3.0], - * > 'b': [4, 5, 6], - * > "c": [True, False, True] - * > }) - * > df.describe() + * > df = pl.DataFrame({ + * ... 'a': [1.0, 2.8, 3.0], + * ... 'b': [4, 5, 6], + * ... "c": [True, False, True] + * ... }) + * ... df.describe() * shape: (5, 4) * ╭──────────┬───────┬─────┬──────╮ * │ describe ┆ a ┆ b ┆ c │ @@ -298,13 +281,13 @@ export interface DataFrame * @param name * @example * ``` - * > df = pl.DataFrame({ - * > "foo": [1, 2, 3], - * > "bar": [6.0, 7.0, 8.0], - * > "ham": ['a', 'b', 'c'], - * > "apple": ['a', 'b', 'c'] - * > }) - * > df.drop(['ham', 'apple']) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6.0, 7.0, 8.0], + * ... "ham": ['a', 'b', 'c'], + * ... "apple": ['a', 'b', 'c'] + * ... }) + * > df.drop(['ham', 'apple']) * shape: (3, 2) * ╭─────┬─────╮ * │ foo ┆ bar │ @@ -317,9 +300,7 @@ export interface DataFrame * ├╌╌╌╌╌┼╌╌╌╌╌┤ * │ 3 ┆ 8 │ * ╰─────┴─────╯ - * * ``` - * */ drop(name: string): DataFrame; drop(names: string[]): DataFrame; @@ -331,12 +312,12 @@ export interface DataFrame * ___ * @example * ``` - * > df = pl.DataFrame({ - * > "foo": [1, 2, 3], - * > "bar": [6, null, 8], - * > "ham": ['a', 'b', 'c'] - * > }) - * > df.dropNulls() + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, null, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.dropNulls() * shape: (2, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -358,11 +339,11 @@ export interface DataFrame * @param columns - column or columns to explode * @example * ``` - * > df = pl.DataFrame({ - * > "letters": ["c", "c", "a", "c", "a", "b"], - * > "nrs": [[1, 2], [1, 3], [4, 3], [5, 5, 5], [6], [2, 1, 2]] - * > }) - * > console.log(df) + * > df = pl.DataFrame({ + * ... "letters": ["c", "c", "a", "c", "a", "b"], + * ... "nrs": [[1, 2], [1, 3], [4, 3], [5, 5, 5], [6], [2, 1, 2]] + * ... }) + * > df * shape: (6, 2) * ╭─────────┬────────────╮ * │ letters ┆ nrs │ @@ -381,7 +362,7 @@ export interface DataFrame * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ * │ "b" ┆ [2, 1, 2] │ * ╰─────────┴────────────╯ - * > df.explode("nrs") + * > df.explode("nrs") * shape: (13, 2) * ╭─────────┬─────╮ * │ letters ┆ nrs │ @@ -455,13 +436,13 @@ export interface DataFrame * @param predicate - Expression that evaluates to a boolean Series. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> // Filter on one condition - * >>> df.filter(pl.col("foo").lt(3)) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * // Filter on one condition + * > df.filter(pl.col("foo").lt(3)) * shape: (2, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -472,11 +453,11 @@ export interface DataFrame * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤ * │ 2 ┆ 7 ┆ b │ * └─────┴─────┴─────┘ - * >>> // Filter on multiple conditions - * >>> df.filter( - * pl.col("foo").lt(3) - * .and(pl.col("ham").eq("a")) - * ) + * // Filter on multiple conditions + * > df.filter( + * ... pl.col("foo").lt(3) + * ... .and(pl.col("ham").eq("a")) + * ... ) * shape: (1, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -494,12 +475,12 @@ export interface DataFrame * @param name -Name of the column to find. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.findIdxByName("ham")) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.findIdxByName("ham")) * 2 * ``` */ @@ -519,39 +500,39 @@ export interface DataFrame * @returns Series * @example * ``` - * >>> // A horizontal sum operation - * >>> df = pl.DataFrame({ - * >>> "a": [2, 1, 3], - * >>> "b": [1, 2, 3], - * >>> "c": [1.0, 2.0, 3.0] - * >>> }) - * >>> df.fold((s1, s2) => s1.plus(s2)) + * > // A horizontal sum operation + * > df = pl.DataFrame({ + * ... "a": [2, 1, 3], + * ... "b": [1, 2, 3], + * ... "c": [1.0, 2.0, 3.0] + * ... }) + * > df.fold((s1, s2) => s1.plus(s2)) * Series: 'a' [f64] * [ * 4 * 5 * 9 * ] - * >>> // A horizontal minimum operation - * >>> df = pl.DataFrame({ - * >>> "a": [2, 1, 3], - * >>> "b": [1, 2, 3], - * >>> "c": [1.0, 2.0, 3.0] - * >>> }) - * >>> df.fold((s1, s2) => s1.zipWith(s1.lt(s2), s2)) + * > // A horizontal minimum operation + * > df = pl.DataFrame({ + * ... "a": [2, 1, 3], + * ... "b": [1, 2, 3], + * ... "c": [1.0, 2.0, 3.0] + * ... }) + * > df.fold((s1, s2) => s1.zipWith(s1.lt(s2), s2)) * Series: 'a' [f64] * [ * 1 * 1 * 3 * ] - * >>> // A horizontal string concatenation - * >>> df = pl.DataFrame({ - * >>> "a": ["foo", "bar", 2], - * >>> "b": [1, 2, 3], - * >>> "c": [1.0, 2.0, 3.0] - * >>> }) - * >>> df.fold((s1, s2) => s.plus(s2)) + * > // A horizontal string concatenation + * > df = pl.DataFrame({ + * ... "a": ["foo", "bar", 2], + * ... "b": [1, 2, 3], + * ... "c": [1.0, 2.0, 3.0] + * ... }) + * > df.fold((s1, s2) => s.plus(s2)) * Series: '' [f64] * [ * "foo11" @@ -569,19 +550,19 @@ export interface DataFrame * @param options.nullEqual Consider null values as equal. * @example * ``` - * >>> df1 = pl.DataFrame({ - * >> "foo": [1, 2, 3], - * >> "bar": [6.0, 7.0, 8.0], - * >> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df2 = pl.DataFrame({ - * >>> "foo": [3, 2, 1], - * >>> "bar": [8.0, 7.0, 6.0], - * >>> "ham": ['c', 'b', 'a'] - * >>> }) - * >>> df1.frameEqual(df1) + * > df1 = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6.0, 7.0, 8.0], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df2 = pl.DataFrame({ + * ... "foo": [3, 2, 1], + * ... "bar": [8.0, 7.0, 6.0], + * ... "ham": ['c', 'b', 'a'] + * ... }) + * > df1.frameEqual(df1) * true - * >>> df1.frameEqual(df2) + * > df1.frameEqual(df2) * false * ``` */ @@ -621,12 +602,12 @@ export interface DataFrame * @param length - Length of the head. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3, 4, 5], - * >>> "bar": [6, 7, 8, 9, 10], - * >>> "ham": ['a', 'b', 'c', 'd','e'] - * >>> }) - * >>> df.head(3) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3, 4, 5], + * ... "bar": [6, 7, 8, 9, 10], + * ... "ham": ['a', 'b', 'c', 'd','e'] + * ... }) + * > df.head(3) * shape: (3, 3) * ╭─────┬─────┬─────╮ * │ foo ┆ bar ┆ ham │ @@ -648,13 +629,13 @@ export interface DataFrame * @param inPlace - Modify in place * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> x = pl.Series("apple", [10, 20, 30]) - * >>> df.hStack([x]) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > x = pl.Series("apple", [10, 20, 30]) + * > df.hStack([x]) * shape: (3, 4) * ╭─────┬─────┬─────┬───────╮ * │ foo ┆ bar ┆ ham ┆ apple │ @@ -705,16 +686,16 @@ export interface DataFrame * @see {@link JoinOptions} * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6.0, 7.0, 8.0], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> otherDF = pl.DataFrame({ - * >>> "apple": ['x', 'y', 'z'], - * >>> "ham": ['a', 'b', 'd'] - * >>> }) - * >>> df.join(otherDF, {on: 'ham'}) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6.0, 7.0, 8.0], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > otherDF = pl.DataFrame({ + * ... "apple": ['x', 'y', 'z'], + * ... "ham": ['a', 'b', 'd'] + * ... }) + * > df.join(otherDF, {on: 'ham'}) * shape: (2, 4) * ╭─────┬─────┬─────┬───────╮ * │ foo ┆ bar ┆ ham ┆ apple │ @@ -729,106 +710,105 @@ export interface DataFrame */ join( other: DataFrame, - options: {on: ValueOrArray} & JoinBaseOptions + options: { on: ValueOrArray } & Omit< + JoinOptions, + "leftOn" | "rightOn" + >, ): DataFrame; join( other: DataFrame, options: { leftOn: ValueOrArray; rightOn: ValueOrArray; - } & JoinBaseOptions + } & Omit, ): DataFrame; - join(other: DataFrame, options: {how: "cross"; suffix?: string}): DataFrame; - - /** - * Perform an asof join. This is similar to a left-join except that we - * match on nearest key rather than equal keys. - * - * Both DataFrames must be sorted by the asof_join key. - * - For each row in the left DataFrame: - - - A "backward" search selects the last row in the right DataFrame whose - 'on' key is less than or equal to the left's key. - - - A "forward" search selects the first row in the right DataFrame whose - 'on' key is greater than or equal to the left's key. - - The default is "backward". - - Parameters - ---------- - @param other DataFrame to join with. - @param options.leftOn Join column of the left DataFrame. - @param options.rightOn Join column of the right DataFrame. - @param options.on Join column of both DataFrames. If set, `leftOn` and `rightOn` should be undefined. - @param options.byLeft join on these columns before doing asof join - @param options.byRight join on these columns before doing asof join - @param options.strategy One of {'forward', 'backward'} - @param options.suffix Suffix to append to columns with a duplicate name. - @param options.tolerance - Numeric tolerance. By setting this the join will only be done if the near keys are within this distance. - If an asof join is done on columns of dtype "Date", "Datetime" you - use the following string language: - - - 1ns *(1 nanosecond)* - - 1us *(1 microsecond)* - - 1ms *(1 millisecond)* - - 1s *(1 second)* - - 1m *(1 minute)* - - 1h *(1 hour)* - - 1d *(1 day)* - - 1w *(1 week)* - - 1mo *(1 calendar month)* - - 1y *(1 calendar year)* - - 1i *(1 index count)* - - Or combine them: - - "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds - @param options.allowParallel Allow the physical plan to optionally evaluate the computation of both DataFrames up to the join in parallel. - @param options.forceParallel Force the physical plan to evaluate the computation of both DataFrames up to the join in parallel. + join(other: DataFrame, options: { how: "cross"; suffix?: string }): DataFrame; - - @example - ``` - >>> const gdp = pl.DataFrame({ - ... date: [ - ... new Date('2016-01-01'), - ... new Date('2017-01-01'), - ... new Date('2018-01-01'), - ... new Date('2019-01-01'), - ... ], // note record date: Jan 1st (sorted!) - ... gdp: [4164, 4411, 4566, 4696], - ... }) - >>> const population = pl.DataFrame({ - ... date: [ - ... new Date('2016-05-12'), - ... new Date('2017-05-12'), - ... new Date('2018-05-12'), - ... new Date('2019-05-12'), - ... ], // note record date: May 12th (sorted!) - ... "population": [82.19, 82.66, 83.12, 83.52], - ... }) - >>> population.joinAsof( - ... gdp, - ... {leftOn:"date", rightOn:"date", strategy:"backward"} - ... ) - shape: (4, 3) - ┌─────────────────────┬────────────┬──────┐ - │ date ┆ population ┆ gdp │ - │ --- ┆ --- ┆ --- │ - │ datetime[μs] ┆ f64 ┆ i64 │ - ╞═════════════════════╪════════════╪══════╡ - │ 2016-05-12 00:00:00 ┆ 82.19 ┆ 4164 │ - ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤ - │ 2017-05-12 00:00:00 ┆ 82.66 ┆ 4411 │ - ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤ - │ 2018-05-12 00:00:00 ┆ 83.12 ┆ 4566 │ - ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤ - │ 2019-05-12 00:00:00 ┆ 83.52 ┆ 4696 │ - └─────────────────────┴────────────┴──────┘ - ``` - */ + /** + * Perform an asof join. This is similar to a left-join except that we + * match on nearest key rather than equal keys. + * + * Both DataFrames must be sorted by the asofJoin key. + * + * For each row in the left DataFrame: + * - A "backward" search selects the last row in the right DataFrame whose + * 'on' key is less than or equal to the left's key. + * + * - A "forward" search selects the first row in the right DataFrame whose + * 'on' key is greater than or equal to the left's key. + * + * The default is "backward". + * + * @param other DataFrame to join with. + * @param options.leftOn Join column of the left DataFrame. + * @param options.rightOn Join column of the right DataFrame. + * @param options.on Join column of both DataFrames. If set, `leftOn` and `rightOn` should be undefined. + * @param options.byLeft join on these columns before doing asof join + * @param options.byRight join on these columns before doing asof join + * @param options.strategy One of 'forward', 'backward' + * @param options.suffix Suffix to append to columns with a duplicate name. + * @param options.tolerance + * Numeric tolerance. By setting this the join will only be done if the near keys are within this distance. + * If an asof join is done on columns of dtype "Date", "Datetime" you + * use the following string language: + * + * - 1ns *(1 nanosecond)* + * - 1us *(1 microsecond)* + * - 1ms *(1 millisecond)* + * - 1s *(1 second)* + * - 1m *(1 minute)* + * - 1h *(1 hour)* + * - 1d *(1 day)* + * - 1w *(1 week)* + * - 1mo *(1 calendar month)* + * - 1y *(1 calendar year)* + * - 1i *(1 index count)* + * + * Or combine them: + * - "3d12h4m25s" # 3 days, 12 hours, 4 minutes, and 25 seconds + * @param options.allowParallel Allow the physical plan to optionally evaluate the computation of both DataFrames up to the join in parallel. + * @param options.forceParallel Force the physical plan to evaluate the computation of both DataFrames up to the join in parallel. + * + * @example + * ``` + * > const gdp = pl.DataFrame({ + * ... date: [ + * ... new Date('2016-01-01'), + * ... new Date('2017-01-01'), + * ... new Date('2018-01-01'), + * ... new Date('2019-01-01'), + * ... ], // note record date: Jan 1st (sorted!) + * ... gdp: [4164, 4411, 4566, 4696], + * ... }) + * > const population = pl.DataFrame({ + * ... date: [ + * ... new Date('2016-05-12'), + * ... new Date('2017-05-12'), + * ... new Date('2018-05-12'), + * ... new Date('2019-05-12'), + * ... ], // note record date: May 12th (sorted!) + * ... "population": [82.19, 82.66, 83.12, 83.52], + * ... }) + * > population.joinAsof( + * ... gdp, + * ... {leftOn:"date", rightOn:"date", strategy:"backward"} + * ... ) + * shape: (4, 3) + * ┌─────────────────────┬────────────┬──────┐ + * │ date ┆ population ┆ gdp │ + * │ --- ┆ --- ┆ --- │ + * │ datetime[μs] ┆ f64 ┆ i64 │ + * ╞═════════════════════╪════════════╪══════╡ + * │ 2016-05-12 00:00:00 ┆ 82.19 ┆ 4164 │ + * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2017-05-12 00:00:00 ┆ 82.66 ┆ 4411 │ + * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2018-05-12 00:00:00 ┆ 83.12 ┆ 4566 │ + * ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2019-05-12 00:00:00 ┆ 83.52 ┆ 4696 │ + * └─────────────────────┴────────────┴──────┘ + * ``` + */ joinAsof( other: DataFrame, options: { @@ -843,7 +823,7 @@ export interface DataFrame tolerance?: number | string; allowParallel?: boolean; forceParallel?: boolean; - } + }, ): DataFrame; lazy(): LazyDataFrame; /** @@ -859,12 +839,12 @@ export interface DataFrame * @param axis - either 0 or 1 * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.max() + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.max() * shape: (1, 3) * ╭─────┬─────┬──────╮ * │ foo ┆ bar ┆ ham │ @@ -894,12 +874,12 @@ export interface DataFrame * ___ * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.median() + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.median() * shape: (1, 3) * ╭─────┬─────┬──────╮ * │ foo ┆ bar ┆ ham │ @@ -919,13 +899,13 @@ export interface DataFrame * @param valueVars - Values to use as value variables. * @example * ``` - * >>> df1 = pl.DataFrame({ - * >>> 'id': [1], - * >>> 'asset_key_1': ['123'], - * >>> 'asset_key_2': ['456'], - * >>> 'asset_key_3': ['abc'], - * >>> }) - * >>> df1.melt('id', ['asset_key_1', 'asset_key_2', 'asset_key_3']) + * > df1 = pl.DataFrame({ + * ... 'id': [1], + * ... 'asset_key_1': ['123'], + * ... 'asset_key_2': ['456'], + * ... 'asset_key_3': ['abc'], + * ... }) + * > df1.melt('id', ['asset_key_1', 'asset_key_2', 'asset_key_3']) * shape: (3, 3) * ┌─────┬─────────────┬───────┐ * │ id ┆ variable ┆ value │ @@ -947,12 +927,12 @@ export interface DataFrame * @param axis - either 0 or 1 * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.min() + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.min() * shape: (1, 3) * ╭─────┬─────┬──────╮ * │ foo ┆ bar ┆ ham │ @@ -975,12 +955,12 @@ export interface DataFrame * ___ * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, null, 3], - * >>> "bar": [6, 7, null], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.nullCount() + * > df = pl.DataFrame({ + * ... "foo": [1, null, 3], + * ... "bar": [6, 7, null], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.nullCount() * shape: (1, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -996,53 +976,49 @@ export interface DataFrame partitionBy( cols: string | string[], stable: boolean, - mapFn: (df: DataFrame) => T + mapFn: (df: DataFrame) => T, ): T[]; /** * - Create a spreadsheet-style pivot table as a DataFrame. - - Parameters - ---------- - @param values Column values to aggregate. Can be multiple columns if the *columns* arguments contains multiple columns as well - @param options.index One or multiple keys to group by - @param options.columns Columns whose values will be used as the header of the output DataFrame - @param options.aggregateFunc - Any of: - - - "sum" - - "max" - - "min" - - "mean" - - "median" - - "first" - - "last" - - "count" - Defaults to "first" - @param options.maintainOrder Sort the grouped keys so that the output order is predictable. - @param options.sortColumns Sort the transposed columns by name. Default is by order of discovery. - @example - -``` - >>> df = pl.DataFrame( - ... { - ... "foo": ["one", "one", "one", "two", "two", "two"], - ... "bar": ["A", "B", "C", "A", "B", "C"], - ... "baz": [1, 2, 3, 4, 5, 6], - ... } - ... ) - >>> df.pivot({values:"baz", index:"foo", columns:"bar"}) - shape: (2, 4) - ┌─────┬─────┬─────┬─────┐ - │ foo ┆ A ┆ B ┆ C │ - │ --- ┆ --- ┆ --- ┆ --- │ - │ str ┆ i64 ┆ i64 ┆ i64 │ - ╞═════╪═════╪═════╪═════╡ - │ one ┆ 1 ┆ 2 ┆ 3 │ - ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤ - │ two ┆ 4 ┆ 5 ┆ 6 │ - └─────┴─────┴─────┴─────┘ - ``` + * Create a spreadsheet-style pivot table as a DataFrame. + * + * @param values Column values to aggregate. Can be multiple columns if the *columns* arguments contains multiple columns as well + * @param options.index One or multiple keys to group by + * @param options.columns Columns whose values will be used as the header of the output DataFrame + * @param options.aggregateFunc + * Any of: + * - "sum" + * - "max" + * - "min" + * - "mean" + * - "median" + * - "first" + * - "last" + * - "count" + * Defaults to "first" + * @param options.maintainOrder Sort the grouped keys so that the output order is predictable. + * @param options.sortColumns Sort the transposed columns by name. Default is by order of discovery. + * @example + * ``` + * > df = pl.DataFrame( + * ... { + * ... "foo": ["one", "one", "one", "two", "two", "two"], + * ... "bar": ["A", "B", "C", "A", "B", "C"], + * ... "baz": [1, 2, 3, 4, 5, 6], + * ... } + * ... ) + * > df.pivot({values:"baz", index:"foo", columns:"bar"}) + * shape: (2, 4) + * ┌─────┬─────┬─────┬─────┐ + * │ foo ┆ A ┆ B ┆ C │ + * │ --- ┆ --- ┆ --- ┆ --- │ + * │ str ┆ i64 ┆ i64 ┆ i64 │ + * ╞═════╪═════╪═════╪═════╡ + * │ one ┆ 1 ┆ 2 ┆ 3 │ + * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤ + * │ two ┆ 4 ┆ 5 ┆ 6 │ + * └─────┴─────┴─────┴─────┘ + * ``` */ pivot( values: string | string[], @@ -1050,6 +1026,24 @@ export interface DataFrame index: string | string[]; columns: string | string[]; aggregateFunc?: + | "sum" + | "max" + | "min" + | "mean" + | "median" + | "first" + | "last" + | "count" + | Expr; + maintainOrder?: boolean; + sortColumns?: boolean; + }, + ): DataFrame; + pivot(options: { + values: string | string[]; + index: string | string[]; + columns: string | string[]; + aggregateFunc?: | "sum" | "max" | "min" @@ -1059,24 +1053,6 @@ export interface DataFrame | "last" | "count" | Expr; - maintainOrder?: boolean; - sortColumns?: boolean; - } - ): DataFrame; - pivot(options: { - values: string | string[]; - index: string | string[]; - columns: string | string[]; - aggregateFunc?: - | "sum" - | "max" - | "min" - | "mean" - | "median" - | "first" - | "last" - | "count" - | Expr; maintainOrder?: boolean; sortColumns?: boolean; }): DataFrame; @@ -1089,12 +1065,12 @@ export interface DataFrame * Aggregate the columns of this DataFrame to their quantile value. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.quantile(0.5) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.quantile(0.5) * shape: (1, 3) * ╭─────┬─────┬──────╮ * │ foo ┆ bar ┆ ham │ @@ -1119,12 +1095,12 @@ export interface DataFrame * @param mapping - Key value pairs that map from old name to new name. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.rename({"foo": "apple"}) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.rename({"foo": "apple"}) * ╭───────┬─────┬─────╮ * │ apple ┆ bar ┆ ham │ * │ --- ┆ --- ┆ --- │ @@ -1146,13 +1122,13 @@ export interface DataFrame * @param newColumn - New column to insert * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> x = pl.Series("apple", [10, 20, 30]) - * >>> df.replaceAtIdx(0, x) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > x = pl.Series("apple", [10, 20, 30]) + * > df.replaceAtIdx(0, x) * shape: (3, 3) * ╭───────┬─────┬─────╮ * │ apple ┆ bar ┆ ham │ @@ -1173,12 +1149,12 @@ export interface DataFrame * @param index - row index * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.row(2) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.row(2) * [3, 8, 'c'] * ``` */ @@ -1194,12 +1170,12 @@ export interface DataFrame * @param columns - Column or columns to select. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.select('foo') + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.select('foo') * shape: (3, 1) * ┌─────┐ * │ foo │ @@ -1222,12 +1198,12 @@ export interface DataFrame * @param periods - Number of places to shift (may be negative). * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.shift(1) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.shift(1) * shape: (3, 3) * ┌──────┬──────┬──────┐ * │ foo ┆ bar ┆ ham │ @@ -1240,7 +1216,7 @@ export interface DataFrame * ├╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ * │ 2 ┆ 7 ┆ "b" │ * └──────┴──────┴──────┘ - * >>> df.shift(-1) + * > df.shift(-1) * shape: (3, 3) * ┌──────┬──────┬──────┐ * │ foo ┆ bar ┆ ham │ @@ -1256,7 +1232,7 @@ export interface DataFrame * ``` */ shift(periods: number): DataFrame; - shift({periods}: {periods: number}): DataFrame; + shift({ periods }: { periods: number }): DataFrame; /** * Shift the values by a given period and fill the parts that will be empty due to this operation * with the result of the `fill_value` expression. @@ -1266,12 +1242,12 @@ export interface DataFrame * @param opts.fillValue - fill null values with this value. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.shiftAndFill({periods:1, fill_value:0}) + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.shiftAndFill({periods:1, fill_value:0}) * shape: (3, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -1299,7 +1275,7 @@ export interface DataFrame */ shrinkToFit(): DataFrame; shrinkToFit(inPlace: true): void; - shrinkToFit({inPlace}: {inPlace: true}): void; + shrinkToFit({ inPlace }: { inPlace: true }): void; /** * Slice this DataFrame over the rows direction. * ___ @@ -1308,12 +1284,12 @@ export interface DataFrame * @param opts.length - Length of the slice * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6.0, 7.0, 8.0], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.slice(1, 2) // Alternatively `df.slice({offset:1, length:2})` + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6.0, 7.0, 8.0], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.slice(1, 2) // Alternatively `df.slice({offset:1, length:2})` * shape: (2, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -1326,7 +1302,7 @@ export interface DataFrame * └─────┴─────┴─────┘ * ``` */ - slice({offset, length}: {offset: number; length: number}): DataFrame; + slice({ offset, length }: { offset: number; length: number }): DataFrame; slice(offset: number, length: number): DataFrame; /** * Sort the DataFrame by column. @@ -1335,18 +1311,18 @@ export interface DataFrame * @param reverse - Reverse/descending sort. */ sort(by: ColumnsOrExpr, reverse?: boolean): DataFrame; - sort({by, reverse}: {by: ColumnsOrExpr; reverse?: boolean}): DataFrame; + sort({ by, reverse }: { by: ColumnsOrExpr; reverse?: boolean }): DataFrame; /** * Aggregate the columns of this DataFrame to their standard deviation value. * ___ * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.std() + * > df = pl.DataFrame({ + * ... "foo": [1, 2, 3], + * ... "bar": [6, 7, 8], + * ... "ham": ['a', 'b', 'c'] + * ... }) + * > df.std() * shape: (1, 3) * ╭─────┬─────┬──────╮ * │ foo ┆ bar ┆ ham │ @@ -1373,11 +1349,11 @@ export interface DataFrame * * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "letters": ["c", "c", "a", "c", "a", "b"], - * >>> "nrs": [1, 2, 3, 4, 5, 6] - * >>> }) - * >>> df + * > df = pl.DataFrame({ + * ... "letters": ["c", "c", "a", "c", "a", "b"], + * ... "nrs": [1, 2, 3, 4, 5, 6] + * ... }) + * > df * shape: (6, 2) * ╭─────────┬─────╮ * │ letters ┆ nrs │ @@ -1396,10 +1372,9 @@ export interface DataFrame * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤ * │ "b" ┆ 6 │ * ╰─────────┴─────╯ - * >>> df.groupby("letters") - * >>> .tail(2) - * >>> .sort("letters") - * >>> + * > df.groupby("letters") + * ... .tail(2) + * ... .sort("letters") * shape: (5, 2) * ╭─────────┬─────╮ * │ letters ┆ nrs │ @@ -1419,78 +1394,92 @@ export interface DataFrame * ``` */ tail(length?: number): DataFrame; - /** @deprecated *since 0.4.0* use {@link writeCSV} */ + /** + * @deprecated *since 0.4.0* use {@link writeCSV} + * @category Deprecated + */ toCSV(destOrOptions?, options?); /** * Converts dataframe object into row oriented javascript objects * @example * ``` - * >>> df.toRecords() + * > df.toRecords() * [ * {"foo":1.0,"bar":"a"}, * {"foo":2.0,"bar":"b"}, * {"foo":3.0,"bar":"c"} * ] * ``` + * @category IO */ toRecords(): Record[]; - /** compat with `JSON.stringify` */ + /** + * compat with `JSON.stringify` + * @category IO + */ toJSON(): string; /** * Converts dataframe object into column oriented javascript objects * @example * ``` - * >>> df.toObject() + * > df.toObject() * { * "foo": [1,2,3], * "bar": ["a", "b", "c"] * } * ``` + * @category IO */ toObject(): Record; - /** @deprecated *since 0.4.0* use {@link writeIPC} */ + /** + * @deprecated *since 0.4.0* use {@link writeIPC} + * @category IO Deprecated + */ toIPC(destination?, options?); - /** @deprecated *since 0.4.0* use {@link writeParquet} */ + /** + * @deprecated *since 0.4.0* use {@link writeParquet} + * @category IO Deprecated + */ toParquet(destination?, options?); toSeries(index?: number): Series; toString(): string; /** - Convert a ``DataFrame`` to a ``Series`` of type ``Struct`` - @param name Name for the struct Series - @example - ``` - >>> df = pl.DataFrame({ - ... "a": [1, 2, 3, 4, 5], - ... "b": ["one", "two", "three", "four", "five"], - ... }) - >>> df.toStruct("nums") - shape: (5,) - Series: 'nums' [struct[2]{'a': i64, 'b': str}] - [ - {1,"one"} - {2,"two"} - {3,"three"} - {4,"four"} - {5,"five"} - ] - ``` - */ + * Convert a ``DataFrame`` to a ``Series`` of type ``Struct`` + * @param name Name for the struct Series + * @example + * ``` + * > df = pl.DataFrame({ + * ... "a": [1, 2, 3, 4, 5], + * ... "b": ["one", "two", "three", "four", "five"], + * ... }) + * > df.toStruct("nums") + * shape: (5,) + * Series: 'nums' [struct[2]{'a': i64, 'b': str}] + * [ + * {1,"one"} + * {2,"two"} + * {3,"three"} + * {4,"four"} + * {5,"five"} + * ] + * ``` + */ toStruct(name: string): Series; /** * Transpose a DataFrame over the diagonal. * - * @note This is a very expensive operation. Perhaps you can do it differently. + * @remarks This is a very expensive operation. Perhaps you can do it differently. * @param options * @param options.includeHeader If set, the column names will be added as first column. * @param options.headerName If `includeHeader` is set, this determines the name of the column that will be inserted * @param options.columnNames Optional generator/iterator that yields column names. Will be used to replace the columns in the DataFrame. * * @example - * >>> df = pl.DataFrame({"a": [1, 2, 3], "b": [1, 2, 3]}) - * >>> df.transpose({includeHeader:true}) + * > df = pl.DataFrame({"a": [1, 2, 3], "b": [1, 2, 3]}) + * > df.transpose({includeHeader:true}) * shape: (2, 4) * ┌────────┬──────────┬──────────┬──────────┐ * │ column ┆ column_0 ┆ column_1 ┆ column_2 │ @@ -1502,7 +1491,7 @@ export interface DataFrame * │ b ┆ 1 ┆ 2 ┆ 3 │ * └────────┴──────────┴──────────┴──────────┘ * // replace the auto generated column names with a list - * >>> df.transpose({includeHeader:false, columnNames:["a", "b", "c"]}) + * > df.transpose({includeHeader:false, columnNames:["a", "b", "c"]}) * shape: (2, 3) * ┌─────┬─────┬─────┐ * │ a ┆ b ┆ c │ @@ -1515,7 +1504,7 @@ export interface DataFrame * └─────┴─────┴─────┘ * * // Include the header as a separate column - * >>> df.transpose({ + * > df.transpose({ * ... includeHeader:true, * ... headerName:"foo", * ... columnNames:["a", "b", "c"] @@ -1532,14 +1521,14 @@ export interface DataFrame * └─────┴─────┴─────┴─────┘ * * // Replace the auto generated column with column names from a generator function - * >>> function *namesGenerator() { + * > function *namesGenerator() { * ... const baseName = "my_column_"; * ... let count = 0; * ... let name = `${baseName}_${count}`; * ... count++; * ... yield name; * ... } - * >>> df.transpose({includeHeader:false, columnNames:namesGenerator}) + * > df.transpose({includeHeader:false, columnNames:namesGenerator}) * shape: (2, 3) * ┌─────────────┬─────────────┬─────────────┐ * │ my_column_0 ┆ my_column_1 ┆ my_column_2 │ @@ -1566,7 +1555,7 @@ export interface DataFrame unique( maintainOrder?: boolean, subset?: ColumnSelection, - keep?: "first" | "last" + keep?: "first" | "last", ): DataFrame; unique(opts: { maintainOrder?: boolean; @@ -1579,7 +1568,7 @@ export interface DataFrame @param names Names of the struct columns that will be decomposed by its fields @example ``` - >>> df = pl.DataFrame({ + > df = pl.DataFrame({ ... "int": [1, 2], ... "str": ["a", "b"], ... "bool": [true, null], @@ -1587,7 +1576,7 @@ export interface DataFrame ... }) ... .toStruct("my_struct") ... .toFrame() - >>> df + > df shape: (2, 1) ┌─────────────────────────────┐ │ my_struct │ @@ -1598,7 +1587,7 @@ export interface DataFrame ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ {2,"b",null,[3]} │ └─────────────────────────────┘ - >>> df.unnest("my_struct") + > df.unnest("my_struct") shape: (2, 4) ┌─────┬─────┬──────┬────────────┐ │ int ┆ str ┆ bool ┆ list │ @@ -1616,12 +1605,12 @@ export interface DataFrame * Aggregate the columns of this DataFrame to their variance value. * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.var() + * > df = pl.DataFrame({ + * > "foo": [1, 2, 3], + * > "bar": [6, 7, 8], + * > "ham": ['a', 'b', 'c'] + * > }) + * > df.var() * shape: (1, 3) * ╭─────┬─────┬──────╮ * │ foo ┆ bar ┆ ham │ @@ -1638,17 +1627,17 @@ export interface DataFrame * @param df - DataFrame to stack. * @example * ``` - * >>> df1 = pl.DataFrame({ - * >>> "foo": [1, 2], - * >>> "bar": [6, 7], - * >>> "ham": ['a', 'b'] - * >>> }) - * >>> df2 = pl.DataFrame({ - * >>> "foo": [3, 4], - * >>> "bar": [8 , 9], - * >>> "ham": ['c', 'd'] - * >>> }) - * >>> df1.vstack(df2) + * > df1 = pl.DataFrame({ + * ... "foo": [1, 2], + * ... "bar": [6, 7], + * ... "ham": ['a', 'b'] + * ... }) + * > df2 = pl.DataFrame({ + * ... "foo": [3, 4], + * ... "bar": [8 , 9], + * ... "ham": ['c', 'd'] + * ... }) + * > df1.vstack(df2) * shape: (4, 3) * ╭─────┬─────┬─────╮ * │ foo ┆ bar ┆ ham │ @@ -1679,7 +1668,7 @@ export interface DataFrame * @param newName */ withColumnRenamed(existing: string, replacement: string): DataFrame; - withColumnRenamed(opts: {existing: string; replacement: string}): DataFrame; + withColumnRenamed(opts: { existing: string; replacement: string }): DataFrame; /** * Add a column at index 0 that counts the rows. * @param name - name of the column to add @@ -1768,7 +1757,7 @@ export const _DataFrame = (_df: any): DataFrame => { } else { return s; } - }) + }), ); }; const summary = concat([ @@ -1780,7 +1769,7 @@ export const _DataFrame = (_df: any): DataFrame => { ]); summary.insertAtIdx( 0, - Series("describe", ["mean", "std", "min", "max", "median"]) + Series("describe", ["mean", "std", "min", "max", "median"]), ); return summary; @@ -1824,7 +1813,7 @@ export const _DataFrame = (_df: any): DataFrame => { if (opts.subset) { opts.subset = [opts.subset].flat(3); } - const o = {...defaultOptions, ...opts}; + const o = { ...defaultOptions, ...opts }; return wrap("unique", o.maintainOrder, o.subset, o.keep); }, @@ -1832,14 +1821,13 @@ export const _DataFrame = (_df: any): DataFrame => { return _DataFrame(_df) .lazy() .explode(columns) - .collectSync({noOptimization: true}); + .collectSync({ noOptimization: true }); }, extend(other) { return wrap("extend", (other as any).inner()); }, filter(predicate) { - return this.lazy().filter(predicate) - .collectSync(); + return this.lazy().filter(predicate).collectSync(); }, fillNull(strategy) { return wrap("fillNull", strategy); @@ -1864,7 +1852,7 @@ export const _DataFrame = (_df: any): DataFrame => { return _df.getColumns().map(_Series) as any; }, groupBy(...by) { - return GroupBy(_df as any, columnOrColumnsStrict(by)); + return _GroupBy(_df as any, columnOrColumnsStrict(by)); }, groupByRolling(opts) { return RollingGroupBy( @@ -1873,7 +1861,7 @@ export const _DataFrame = (_df: any): DataFrame => { opts.period, opts.offset, opts.closed, - opts.by + opts.by, ); }, groupByDynamic({ @@ -1895,19 +1883,19 @@ export const _DataFrame = (_df: any): DataFrame => { truncate, includeBoundaries, closed, - by + by, ); }, hashRows(obj: any = 0n, k1 = 1n, k2 = 2n, k3 = 3n) { if (typeof obj === "number" || typeof obj === "bigint") { return _Series( - _df.hashRows(BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3)) + _df.hashRows(BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3)), ); } - const o = {k0: obj, k1: k1, k2: k2, k3: k3, ...obj}; + const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj }; return _Series( - _df.hashRows(BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), BigInt(o.k3)) + _df.hashRows(BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), BigInt(o.k3)), ) as any; }, head(length = 5) { @@ -1921,7 +1909,7 @@ export const _DataFrame = (_df: any): DataFrame => { return wrap( method, - columns.map((col) => col.inner()) + columns.map((col) => col.inner()), ); }, insertAtIdx(idx, series) { @@ -1934,7 +1922,7 @@ export const _DataFrame = (_df: any): DataFrame => { isEmpty: () => _df.height === 0, isUnique: () => _Series(_df.isUnique()) as any, join(other: DataFrame, options): DataFrame { - options = {how: "inner", suffix: "right", ...options}; + options = { how: "inner", suffix: "right", ...options }; const on = columnOrColumns(options.on); const how = options.how; const suffix = options.suffix; @@ -1950,7 +1938,7 @@ export const _DataFrame = (_df: any): DataFrame => { } if ((leftOn && !rightOn) || (rightOn && !leftOn)) { throw new TypeError( - "You should pass the column to join on as an argument." + "You should pass the column to join on as an argument.", ); } @@ -2019,30 +2007,25 @@ export const _DataFrame = (_df: any): DataFrame => { if (Expr.isExpr(aggregateFunc)) { fn = aggregateFunc; } else { - fn = { - first: element().first(), - sum: element().sum(), - max: element().max(), - min: element().min(), - mean: element().mean(), - median: element().median(), - last: element().last(), - count: element().count() - }[aggregateFunc] ?? new Error(`Unknown aggregate function ${aggregateFunc}`); + fn = + { + first: element().first(), + sum: element().sum(), + max: element().max(), + min: element().min(), + mean: element().mean(), + median: element().median(), + last: element().last(), + count: element().count(), + }[aggregateFunc] ?? + new Error(`Unknown aggregate function ${aggregateFunc}`); if (fn instanceof Error) { throw fn; } } return _DataFrame( - _df.pivotExpr( - values, - index, - columns, - fn, - maintainOrder, - sortColumns - ) + _df.pivotExpr(values, index, columns, fn, maintainOrder, sortColumns), ); }, quantile(quantile, interpolation = "nearest") { @@ -2072,6 +2055,7 @@ export const _DataFrame = (_df: any): DataFrame => { return _df.toRows(); }, sample(opts?, frac?, withReplacement = false, seed?) { + // rome-ignore lint/style/noArguments: if (arguments.length === 0) { return wrap("sampleN", 1, withReplacement, false, seed); } @@ -2091,9 +2075,7 @@ export const _DataFrame = (_df: any): DataFrame => { select(...selection) { const hasExpr = selection.flat().some((s) => Expr.isExpr(s)); if (hasExpr) { - return _DataFrame(_df).lazy() - .select(selection) - .collectSync(); + return _DataFrame(_df).lazy().select(selection).collectSync(); } else { return wrap("select", columnOrColumnsStrict(selection as any)); } @@ -2130,7 +2112,7 @@ export const _DataFrame = (_df: any): DataFrame => { return _DataFrame(_df) .lazy() .sort(arg, reverse) - .collectSync({noOptimization: true, stringCache: false}); + .collectSync({ noOptimization: true, stringCache: false }); } return wrap("sort", arg, reverse, true); @@ -2186,7 +2168,7 @@ export const _DataFrame = (_df: any): DataFrame => { return acc; }, {}); }, - writeJSON(dest?, options = {format: "lines"}) { + writeJSON(dest?, options = { format: "lines" }) { if (dest instanceof Writable || typeof dest === "string") { return _df.writeJson(dest, options) as any; } @@ -2198,7 +2180,7 @@ export const _DataFrame = (_df: any): DataFrame => { }, }); - _df.writeJson(writeStream, {...options, ...dest}); + _df.writeJson(writeStream, { ...options, ...dest }); writeStream.end(""); return Buffer.concat(buffers); @@ -2206,7 +2188,7 @@ export const _DataFrame = (_df: any): DataFrame => { toParquet(dest?, options?) { return this.writeParquet(dest, options); }, - writeParquet(dest?, options = {compression: "uncompressed"}) { + writeParquet(dest?, options = { compression: "uncompressed" }) { if (dest instanceof Writable || typeof dest === "string") { return _df.writeParquet(dest, options.compression) as any; } @@ -2223,7 +2205,7 @@ export const _DataFrame = (_df: any): DataFrame => { return Buffer.concat(buffers); }, - writeAvro(dest?, options = {compression: "uncompressed"}) { + writeAvro(dest?, options = { compression: "uncompressed" }) { if (dest instanceof Writable || typeof dest === "string") { return _df.writeAvro(dest, options.compression) as any; } @@ -2243,7 +2225,7 @@ export const _DataFrame = (_df: any): DataFrame => { toIPC(dest?, options?) { return this.writeIPC(dest, options); }, - writeIPC(dest?, options = {compression: "uncompressed"}) { + writeIPC(dest?, options = { compression: "uncompressed" }) { if (dest instanceof Writable || typeof dest === "string") { return _df.writeIpc(dest, options.compression) as any; } @@ -2271,7 +2253,7 @@ export const _DataFrame = (_df: any): DataFrame => { let df = wrap( "transpose", options?.includeHeader ?? false, - options?.headerName + options?.headerName, ); if (options?.columnNames) { function* namesIter() { @@ -2287,11 +2269,11 @@ export const _DataFrame = (_df: any): DataFrame => { } const newColumns = Array.from( - {length: df.width}, + { length: df.width }, ( (i) => () => i.next().value - )(namesIter()) + )(namesIter()), ); df.columns = newColumns; @@ -2325,19 +2307,19 @@ export const _DataFrame = (_df: any): DataFrame => { if (isSeriesArray(columns)) { return columns.reduce( (acc, curr) => acc.withColumn(curr), - _DataFrame(_df) + _DataFrame(_df), ); } else { return this.lazy() .withColumns(columns) - .collectSync({noOptimization: true, stringCache: false}); + .collectSync({ noOptimization: true, stringCache: false }); } }, withColumnRenamed(opt, replacement?) { if (typeof opt === "string") { - return this.rename({[opt]: replacement}); + return this.rename({ [opt]: replacement }); } else { - return this.rename({[opt.existing]: opt.replacement}); + return this.rename({ [opt.existing]: opt.replacement }); } }, withRowCount(name = "row_nr") { @@ -2400,8 +2382,33 @@ export const _DataFrame = (_df: any): DataFrame => { }); }; +/** + * DataFrame constructor + */ export interface DataFrameConstructor extends Deserialize { + /** + * Create an empty DataFrame + */ (): DataFrame; + /** + * Create a DataFrame from a JavaScript object + * @example + * ``` + * data = {'a': [1n, 2n], 'b': [3, 4]} + * df = pl.DataFrame(data) + * df + * shape: (2, 2) + * ╭─────┬─────╮ + * │ a ┆ b │ + * │ --- ┆ --- │ + * │ u64 ┆ i64 │ + * ╞═════╪═════╡ + * │ 1 ┆ 3 │ + * ├╌╌╌╌╌┼╌╌╌╌╌┤ + * │ 2 ┆ 4 │ + * ╰─────┴─────╯ + * ``` + */ ( data: any, options?: { @@ -2409,7 +2416,7 @@ export interface DataFrameConstructor extends Deserialize { orient?: "row" | "col"; schema?: Record; inferSchemaLength?: number; - } + }, ): DataFrame; isDataFrame(arg: any): arg is DataFrame; } @@ -2445,5 +2452,5 @@ export const DataFrame: DataFrameConstructor = Object.assign( isDataFrame, deserialize: (buf, fmt) => _DataFrame(pli.JsDataFrame.deserialize(buf, fmt)), - } + }, ); diff --git a/polars/datatypes/datatype.ts b/polars/datatypes/datatype.ts index de9ec7541..77663f6e3 100644 --- a/polars/datatypes/datatype.ts +++ b/polars/datatypes/datatype.ts @@ -1,4 +1,4 @@ -import {Field} from "./field"; +import { Field } from "./field"; export abstract class DataType { get variant() { @@ -90,7 +90,10 @@ export abstract class DataType { */ public static Datetime(timeUnit: TimeUnit, timeZone?): DataType; public static Datetime(timeUnit: "ms" | "ns" | "us", timeZone?): DataType; - public static Datetime(timeUnit, timeZone: string | null | undefined = null): DataType { + public static Datetime( + timeUnit, + timeZone: string | null | undefined = null, + ): DataType { return new _Datetime(timeUnit, timeZone as any); } /** @@ -102,10 +105,13 @@ export abstract class DataType { public static List(inner: DataType): DataType { return new _List(inner); } + /** + * Struct type + */ public static Struct(fields: Field[]): DataType; - public static Struct(fields: {[key: string]: DataType}): DataType; + public static Struct(fields: { [key: string]: DataType }): DataType; public static Struct( - fields: Field[] | {[key: string]: DataType} + fields: Field[] | { [key: string]: DataType }, ): DataType { return new _Struct(fields); } @@ -115,11 +121,10 @@ export abstract class DataType { } toString() { - if(this.inner) { + if (this.inner) { return `${this.identity}(${this.variant}(${this.inner}))`; } else { return `${this.identity}(${this.variant})`; - } } toJSON() { @@ -141,38 +146,37 @@ export abstract class DataType { return this.toJSON(); } static from(obj): DataType { - return null as any; } } -class _Null extends DataType { } -class _Bool extends DataType { } -class _Int8 extends DataType { } -class _Int16 extends DataType { } -class _Int32 extends DataType { } -class _Int64 extends DataType { } -class _UInt8 extends DataType { } -class _UInt16 extends DataType { } -class _UInt32 extends DataType { } -class _UInt64 extends DataType { } -class _Float32 extends DataType { } -class _Float64 extends DataType { } -class _Date extends DataType { } -class _Time extends DataType { } -class _Object extends DataType { } -class _Utf8 extends DataType { } +class _Null extends DataType {} +class _Bool extends DataType {} +class _Int8 extends DataType {} +class _Int16 extends DataType {} +class _Int32 extends DataType {} +class _Int64 extends DataType {} +class _UInt8 extends DataType {} +class _UInt16 extends DataType {} +class _UInt32 extends DataType {} +class _UInt64 extends DataType {} +class _Float32 extends DataType {} +class _Float64 extends DataType {} +class _Date extends DataType {} +class _Time extends DataType {} +class _Object extends DataType {} +class _Utf8 extends DataType {} + +class _Categorical extends DataType {} -class _Categorical extends DataType { } +/** + * Datetime type + */ class _Datetime extends DataType { - constructor( - private timeUnit: TimeUnit, - private timeZone?: string - ) { + constructor(private timeUnit: TimeUnit, private timeZone?: string) { super(); } override get inner() { - return [this.timeUnit, this.timeZone]; } @@ -210,9 +214,9 @@ class _Struct extends DataType { constructor( inner: | { - [name: string]: DataType; - } - | Field[] + [name: string]: DataType; + } + | Field[], ) { super(); if (Array.isArray(inner)) { @@ -240,44 +244,72 @@ class _Struct extends DataType { override toJSON() { return { [this.identity]: { - [this.variant]: this.fields - } + [this.variant]: this.fields, + }, } as any; } } +/** + * Datetime time unit + */ export enum TimeUnit { Nanoseconds = "ns", Microseconds = "us", Milliseconds = "ms", } +/** + * @ignore + * Timeunit namespace + */ export namespace TimeUnit { export function from(s: "ms" | "ns" | "us"): TimeUnit { return TimeUnit[s]; } } -import util from "util"; + +/** + * Datatype namespace + */ export namespace DataType { + /** Null */ export type Null = _Null; - + /** Boolean */ export type Bool = _Bool; + /** Int8 */ export type Int8 = _Int8; + /** Int16 */ export type Int16 = _Int16; + /** Int32 */ export type Int32 = _Int32; + /** Int64 */ export type Int64 = _Int64; + /** UInt8 */ export type UInt8 = _UInt8; + /** UInt16 */ export type UInt16 = _UInt16; + /** UInt32 */ export type UInt32 = _UInt32; + /** UInt64 */ export type UInt64 = _UInt64; + /** Float32 */ export type Float32 = _Float32; + /** Float64 */ export type Float64 = _Float64; + /** Date dtype */ export type Date = _Date; + /** Datetime */ export type Datetime = _Datetime; + /** Utf8 */ export type Utf8 = _Utf8; + /** Categorical */ export type Categorical = _Categorical; + /** List */ export type List = _List; + /** Struct */ export type Struct = _Struct; + /** * deserializes a datatype from the serde output of rust polars `DataType` * @param dtype dtype object @@ -287,15 +319,16 @@ export namespace DataType { return DataType[dtype]; } - let {variant, inner} = dtype; - if(variant === "Struct") { - inner = [inner[0].map(fld => Field.from(fld.name, deserialize(fld.dtype)))]; + let { variant, inner } = dtype; + if (variant === "Struct") { + inner = [ + inner[0].map((fld) => Field.from(fld.name, deserialize(fld.dtype))), + ]; } - if(variant === "List") { + if (variant === "List") { inner = [deserialize(inner[0])]; } return DataType[variant](...inner); - } } diff --git a/polars/datatypes/field.ts b/polars/datatypes/field.ts index 0e9b04162..05d43321f 100644 --- a/polars/datatypes/field.ts +++ b/polars/datatypes/field.ts @@ -1,12 +1,15 @@ import { DataType } from "./datatype"; +/** + * A field is a name and a datatype. + */ export interface Field { - name: string, - dtype: DataType + name: string; + dtype: DataType; } -export class Field { - constructor(public name: string, public dtype: DataType) { } +export class Field implements Field { + constructor(public name: string, public dtype: DataType) {} toString() { return `Field("${this.name}", ${this.dtype})`; } @@ -24,7 +27,7 @@ export class Field { export namespace Field { export function from(name: string, dtype: DataType): Field; export function from([string, DataType]): Field; - export function from(obj: {name: string; dtype: DataType}): Field; + export function from(obj: { name: string; dtype: DataType }): Field; export function from(nameOrObj, dtype?: DataType): Field { if (typeof nameOrObj === "string") { return new Field(nameOrObj, dtype!); @@ -32,7 +35,6 @@ export namespace Field { return new Field(nameOrObj[0], nameOrObj[1]); } else { return new Field(nameOrObj.name, nameOrObj.dtype); - } } } diff --git a/polars/datatypes/index.ts b/polars/datatypes/index.ts index a476af932..6a8e0c773 100644 --- a/polars/datatypes/index.ts +++ b/polars/datatypes/index.ts @@ -1,53 +1,36 @@ -import {DataType} from "./datatype"; -export {DataType}; +import { DataType, TimeUnit } from "./datatype"; +export { DataType, TimeUnit }; +export { Field } from "./field"; import pli from "../internals/polars_internal"; +/** @ignore */ +export type TypedArray = + | Int8Array + | Int16Array + | Int32Array + | BigInt64Array + | Uint8Array + | Uint16Array + | Uint32Array + | BigInt64Array + | Float32Array + | Float64Array; -export type TypedArray = Int8Array | Int16Array | Int32Array | BigInt64Array | Uint8Array | Uint16Array | Uint32Array | BigInt64Array | Float32Array | Float64Array; - - +/** + * @ignore + */ export type Optional = T | undefined | null; -export enum _DataType { - Int8, - Int16, - Int32, - Int64, - UInt8, - UInt16, - UInt32, - UInt64, - Float32, - Float64, - Bool, - Utf8, - List, - Date, - Datetime, - Time, - Object, - Categorical, - Struct -} - +/** + * @ignore + */ export type JsDataFrame = any; export type NullValues = string | Array | Record; -export type JoinBaseOptions = { - how?: "left" | "inner" | "outer" | "semi" | "anti" | "cross" - suffix?: string; -} - -export type JoinOptions = { - leftOn?: string | Array; - rightOn?: string | Array; - on?: string | Array; - how?: "left" | "inner" | "outer" | "semi" | "anti" | "cross" - suffix?: string; -}; - - +/** + * @ignore + */ export const DTYPE_TO_FFINAME = { Int8: "I8", Int16: "I16", @@ -121,12 +104,12 @@ const POLARS_TYPE_TO_CONSTRUCTOR: Record = { }, }; +/** @ignore */ export const polarsTypeToConstructor = (dtype: DataType): CallableFunction => { - const constructor = POLARS_TYPE_TO_CONSTRUCTOR[dtype.variant]; - if (!constructor) { + const ctor = POLARS_TYPE_TO_CONSTRUCTOR[dtype.variant]; + if (!ctor) { throw new Error(`Cannot construct Series for type ${dtype.variant}.`); } - - return constructor; + return ctor; }; diff --git a/polars/error.ts b/polars/error.ts index 68640932f..ba8fbf02f 100644 --- a/polars/error.ts +++ b/polars/error.ts @@ -1,12 +1,10 @@ export class InvalidOperationError extends RangeError { - constructor(method, dtype) { super(`Invalid operation: ${method} is not supported for ${dtype}`); } } export class NotImplemented extends Error { - constructor(method, dtype) { super(`Invalid operation: ${method} is not supported for ${dtype}`); } diff --git a/polars/functions.ts b/polars/functions.ts index 80bfed7fd..815b571f2 100644 --- a/polars/functions.ts +++ b/polars/functions.ts @@ -1,11 +1,10 @@ /* eslint-disable no-redeclare */ -import {jsTypeToPolarsType} from "./internals/construction"; -import {Series, _Series} from "./series/series"; -import {DataFrame, _DataFrame} from "./dataframe"; +import { jsTypeToPolarsType } from "./internals/construction"; +import { Series, _Series } from "./series"; +import { DataFrame, _DataFrame } from "./dataframe"; import pli from "./internals/polars_internal"; -import {isDataFrameArray, isSeriesArray} from "./utils"; - -type ConcatOptions = {rechunk?: boolean, how?: "vertical" | "horizontal"} +import { isDataFrameArray, isSeriesArray } from "./utils"; +import { ConcatOptions } from "./types"; /** * _Repeat a single value n times and collect into a Series._ @@ -16,13 +15,13 @@ type ConcatOptions = {rechunk?: boolean, how?: "vertical" | "horizontal"} * * ``` * - * > const s = pl.repeat("a", 5) - * > s.toArray() + * > const s = pl.repeat("a", 5) + * > s.toArray() * ["a", "a", "a", "a", "a"] * * ``` */ -export function repeat(value: V, n: number, name= ""): Series { +export function repeat(value: V, n: number, name = ""): Series { const dtype = jsTypeToPolarsType(value); const s = pli.JsSeries.repeat(name, value, n, dtype); @@ -38,9 +37,9 @@ export function repeat(value: V, n: number, name= ""): Series { * - Horizontal: Stacks Series horizontally and fills with nulls if the lengths don't match. * * @example - * >>> const df1 = pl.DataFrame({"a": [1], "b": [3]}) - * >>> const df2 = pl.DataFrame({"a": [2], "b": [4]}) - * >>> pl.concat([df1, df2]) + * > const df1 = pl.DataFrame({"a": [1], "b": [3]}) + * > const df2 = pl.DataFrame({"a": [2], "b": [4]}) + * > pl.concat([df1, df2]) * shape: (2, 2) * ┌─────┬─────┐ * │ a ┆ b │ @@ -52,20 +51,28 @@ export function repeat(value: V, n: number, name= ""): Series { * │ 2 ┆ 4 │ * └─────┴─────┘ */ -export function concat(items: Array, options?: ConcatOptions): DataFrame; -export function concat(items: Array, options?: {rechunk: boolean}): Series; -export function concat(items, options: ConcatOptions = {rechunk: true, how: "vertical"}) { - const {rechunk, how} = options; +export function concat( + items: Array, + options?: ConcatOptions, +): DataFrame; +export function concat( + items: Array, + options?: { rechunk: boolean }, +): Series; +export function concat( + items, + options: ConcatOptions = { rechunk: true, how: "vertical" }, +) { + const { rechunk, how } = options; - if(!items.length) { + if (!items.length) { throw new RangeError("cannot concat empty list"); } - if(isDataFrameArray(items)) { + if (isDataFrameArray(items)) { let df; - if(how === "vertical") { - df = items.reduce((acc, curr) => acc.vstack(curr)); - + if (how === "vertical") { + df = items.reduce((acc, curr) => acc.vstack(curr)); } else { df = _DataFrame(pli.horizontalConcat(items.map((i: any) => i.inner()))); } @@ -73,8 +80,8 @@ export function concat(items, options: ConcatOptions = {rechunk: true, how: return rechunk ? df.rechunk() : df; } - if(isSeriesArray(items)) { - const s = items.reduce((acc, curr) => acc.concat(curr)); + if (isSeriesArray(items)) { + const s = items.reduce((acc, curr) => acc.concat(curr)); return rechunk ? s.rechunk() : s; } diff --git a/polars/groupby.ts b/polars/groupby.ts index ed69ee11b..a3a2f034e 100644 --- a/polars/groupby.ts +++ b/polars/groupby.ts @@ -1,24 +1,22 @@ -import {DataFrame, _DataFrame} from "./dataframe"; +import { DataFrame, _DataFrame } from "./dataframe"; import * as utils from "./utils"; import util from "util"; -import {Expr} from "./lazy/expr"; -import {col, exclude} from "./lazy/functions"; -import pli from "./internals/polars_internal"; -import {ColumnsOrExpr, selectionToExprList} from "./utils"; - +import { Expr } from "./lazy/expr"; +import { col, exclude } from "./lazy/functions"; +import { ColumnsOrExpr } from "./utils"; const inspect = Symbol.for("nodejs.util.inspect.custom"); -const inspectOpts = {colors:true, depth:null}; +const inspectOpts = { colors: true, depth: null }; /** * Starts a new GroupBy operation. */ export interface GroupBy { - [inspect](): string, + [inspect](): string; /** * Aggregate the groups into Series. */ - aggList(): DataFrame + aggList(): DataFrame; /** * __Use multiple aggregations on columns.__ * This can be combined with complete lazy API and is considered idiomatic polars. @@ -31,46 +29,46 @@ export interface GroupBy { * @example * ``` * // use lazy api rest parameter style - * >>> df.groupBy('foo', 'bar') - * >>> .agg(pl.sum('ham'), col('spam').tail(4).sum()) + * > df.groupBy('foo', 'bar') + * > .agg(pl.sum('ham'), col('spam').tail(4).sum()) * * // use lazy api array style - * >>> df.groupBy('foo', 'bar') - * >>> .agg([pl.sum('ham'), col('spam').tail(4).sum()]) + * > df.groupBy('foo', 'bar') + * > .agg([pl.sum('ham'), col('spam').tail(4).sum()]) * * // use a mapping - * >>> df.groupBy('foo', 'bar') - * >>> .agg({'spam': ['sum', 'min']}) + * > df.groupBy('foo', 'bar') + * > .agg({'spam': ['sum', 'min']}) * * ``` */ - agg(...columns: Expr[]): DataFrame - agg(columns: Record): DataFrame + agg(...columns: Expr[]): DataFrame; + agg(columns: Record): DataFrame; /** * Count the number of values in each group. */ - count(): DataFrame + count(): DataFrame; /** * Aggregate the first values in the group. */ - first(): DataFrame + first(): DataFrame; /** * Return a `DataFrame` with: * - the groupby keys * - the group indexes aggregated as lists */ - groups(): DataFrame + groups(): DataFrame; /** * Return first n rows of each group. * @param n -Number of values of the group to select * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "letters": ["c", "c", "a", "c", "a", "b"], - * >>> "nrs": [1, 2, 3, 4, 5, 6] - * >>> }) - * >>> df + * > df = pl.DataFrame({ + * > "letters": ["c", "c", "a", "c", "a", "b"], + * > "nrs": [1, 2, 3, 4, 5, 6] + * > }) + * > df * shape: (6, 2) * ╭─────────┬─────╮ * │ letters ┆ nrs │ @@ -89,10 +87,10 @@ export interface GroupBy { * ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤ * │ "b" ┆ 6 │ * ╰─────────┴─────╯ - * >>> df.groupby("letters") - * >>> .head(2) - * >>> .sort("letters"); - * >>> + * > df.groupby("letters") + * > .head(2) + * > .sort("letters"); + * > >> * shape: (5, 2) * ╭─────────┬─────╮ * │ letters ┆ nrs │ @@ -111,75 +109,71 @@ export interface GroupBy { * ╰─────────┴─────╯ * ``` */ - head(n?: number): DataFrame + head(n?: number): DataFrame; /** * Aggregate the last values in the group. */ - last(): DataFrame + last(): DataFrame; /** * Reduce the groups to the maximal value. */ - max(): DataFrame + max(): DataFrame; /** * Reduce the groups to the mean values. */ - mean(): DataFrame + mean(): DataFrame; /** * Return the median per group. */ - median(): DataFrame + median(): DataFrame; /** * Reduce the groups to the minimal value. */ - min(): DataFrame + min(): DataFrame; /** * Count the unique values per group. */ - nUnique(): DataFrame + nUnique(): DataFrame; /** * Do a pivot operation based on the group key, a pivot column and an aggregation function on the values column. * @param pivotCol - Column to pivot. * @param valuesCol - Column that will be aggregated. * */ - pivot({pivotCol, valuesCol}: {pivotCol: string, valuesCol: string}): PivotOps - pivot(pivotCol: string, valuesCol: string): PivotOps + pivot({ + pivotCol, + valuesCol, + }: { pivotCol: string; valuesCol: string }): PivotOps; + pivot(pivotCol: string, valuesCol: string): PivotOps; /** * Compute the quantile per group. */ - quantile(quantile: number): DataFrame + quantile(quantile: number): DataFrame; /** * Reduce the groups to the sum. */ - sum(): DataFrame - tail(n?: number): DataFrame - toString(): string - - + sum(): DataFrame; + tail(n?: number): DataFrame; + toString(): string; } +export type PivotOps = Pick< + GroupBy, + "count" | "first" | "max" | "mean" | "median" | "min" | "sum" +> & { [inspect](): string }; -export type PivotOps = Pick & {[inspect](): string} +/** @ignore */ +export function _GroupBy(df: any, by: string[], maintainOrder = false) { + const customInspect = () => + util.formatWithOptions(inspectOpts, "GroupBy {by: %O}", by); -export function GroupBy( - df: any, - by: string[], - maintainOrder = false -) { - const customInspect = () => util.formatWithOptions(inspectOpts, "GroupBy {by: %O}", by); - - const pivot = (opts: {pivotCol: string, valuesCol: string} | string, valuesCol?: string): PivotOps => { - if(typeof opts === "string") { - if(valuesCol) { - return pivot({pivotCol: opts, valuesCol}); + const pivot = ( + opts: { pivotCol: string; valuesCol: string } | string, + valuesCol?: string, + ): PivotOps => { + if (typeof opts === "string") { + if (valuesCol) { + return pivot({ pivotCol: opts, valuesCol }); } else { throw new Error("must specify both pivotCol and valuesCol"); } @@ -189,29 +183,27 @@ export function GroupBy( }; const agg = (...aggs): DataFrame => { - if(utils.isExprArray(aggs)) { + if (utils.isExprArray(aggs)) { aggs = [aggs].flat(2); return _DataFrame(df) .lazy() .groupBy(by, maintainOrder) .agg(...aggs) - .collectSync({noOptimization:true}); + .collectSync({ noOptimization: true }); } else { - let pairs = Object.entries(aggs[0]) - .flatMap(([key, values]) => { - return [values].flat(2).map(v => col(key)[v as any]()); - }); + let pairs = Object.entries(aggs[0]).flatMap(([key, values]) => { + return [values].flat(2).map((v) => col(key)[v as any]()); + }); return _DataFrame(df) .lazy() .groupBy(by, maintainOrder) .agg(...pairs) - .collectSync({noOptimization:true}); + .collectSync({ noOptimization: true }); } }; - return Object.seal({ [inspect]: customInspect, agg, @@ -224,16 +216,16 @@ export function GroupBy( groups() { return _DataFrame(df.groupby([by].flat(), null, "groups")); }, - head: (n=5) => agg(exclude(by as any).head(n)), + head: (n = 5) => agg(exclude(by as any).head(n)), last: () => agg(exclude(by as any).last()), max: () => agg(exclude(by as any).max()), mean: () => agg(exclude(by as any).mean()), median: () => agg(exclude(by as any).median()), min: () => agg(exclude(by as any).min()), nUnique: () => agg(exclude(by as any).nUnique()), - quantile: (q: number) => agg(exclude(by as any).quantile(q)), + quantile: (q: number) => agg(exclude(by as any).quantile(q)), sum: () => agg(exclude(by as any).sum()), - tail: (n=5) => agg(exclude(by as any).tail(n)), + tail: (n = 5) => agg(exclude(by as any).tail(n)), toString: () => "GroupBy", }) as GroupBy; } @@ -242,11 +234,12 @@ function PivotOps( df: any, by: string | string[], pivotCol: string, - valueCol: string + valueCol: string, ): PivotOps { - - const pivot = (agg) => () => _DataFrame(df.pivot([by].flat(), [pivotCol], [valueCol], agg)); - const customInspect = () => util.formatWithOptions(inspectOpts, "PivotOps {by: %O}", by); + const pivot = (agg) => () => + _DataFrame(df.pivot([by].flat(), [pivotCol], [valueCol], agg)); + const customInspect = () => + util.formatWithOptions(inspectOpts, "PivotOps {by: %O}", by); return { [inspect]: customInspect, @@ -260,37 +253,40 @@ function PivotOps( }; } - +/** + * intermediate state of a rolling groupby + */ export interface RollingGroupBy { - agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]): DataFrame + agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]): DataFrame; } +/** @ignore */ export function RollingGroupBy( df: any, indexColumn: string, period: string, offset?: string, closed?, - by?: ColumnsOrExpr + by?: ColumnsOrExpr, ): RollingGroupBy { - return { agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]) { - - return df .lazy() - .groupByRolling({indexColumn, period, offset, closed, by} as any) + .groupByRolling({ indexColumn, period, offset, closed, by } as any) .agg(column as any, ...columns) .collectSync(); - } + }, }; } - +/** + * intermediate state of a dynamic groupby + */ export interface DynamicGroupBy { - agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]): DataFrame + agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]): DataFrame; } +/** @ignore */ export function DynamicGroupBy( df: any, indexColumn: string, @@ -300,18 +296,24 @@ export function DynamicGroupBy( truncate?: boolean, includeBoundaries?: boolean, closed?: string, - by?: ColumnsOrExpr + by?: ColumnsOrExpr, ): DynamicGroupBy { - return { agg(column: ColumnsOrExpr, ...columns: ColumnsOrExpr[]) { - - return df .lazy() - .groupByDynamic({indexColumn, every, period, offset, truncate, includeBoundaries, closed, by} as any) + .groupByDynamic({ + indexColumn, + every, + period, + offset, + truncate, + includeBoundaries, + closed, + by, + } as any) .agg(column as any, ...columns) - .collectSync({noOptimizations: true}); - } + .collectSync({ noOptimizations: true }); + }, }; } diff --git a/polars/index.ts b/polars/index.ts index a1c912e7a..66d3f40d2 100644 --- a/polars/index.ts +++ b/polars/index.ts @@ -1,31 +1,35 @@ -import * as series from "./series/series"; +import * as series from "./series"; import * as df from "./dataframe"; -import {DataType} from "./datatypes"; +import { DataType, Field as _field } from "./datatypes"; import * as func from "./functions"; import * as io from "./io"; import * as cfg from "./cfg"; import * as ldf from "./lazy/dataframe"; import pli from "./internals/polars_internal"; -import { - funcs as lazy, - Expr as lazyExpr, - GroupBy as lazyGroupBy, - when as _when -} from "./lazy"; - - -namespace pl { - export import Expr = lazyExpr.Expr - export import DataFrame = df.DataFrame - export import LazyDataFrame = ldf.LazyDataFrame +export { DataType, Field, TimeUnit } from "./datatypes"; +export * from "./series"; +export { Expr } from "./lazy/expr"; +export * from "./dataframe"; +export * from "./functions"; +export * from "./io"; +export * from "./cfg"; +export * from "./lazy/dataframe"; +export * from "./lazy"; +import * as lazy from "./lazy"; +export * from "./types"; +export type { GroupBy } from "./groupby"; +export namespace pl { + export import Expr = lazy.Expr; + export import DataFrame = df.DataFrame; + export import LazyDataFrame = ldf.LazyDataFrame; export import Series = series.Series; - export type LazyGroupBy = lazyGroupBy; - export type When = _when.When; - export type WhenThen = _when.WhenThen; - export type WhenThenThen = _when.WhenThenThen; + export type LazyGroupBy = lazy.LazyGroupBy; + export type When = lazy.When; + export type WhenThen = lazy.WhenThen; + export type WhenThenThen = lazy.WhenThenThen; export import Config = cfg.Config; - export import Int8 = DataType.Int8 - export import Int16 = DataType.Int16 + export import Int8 = DataType.Int8; + export import Int16 = DataType.Int16; export import Int32 = DataType.Int32; export import Int64 = DataType.Int64; export import UInt8 = DataType.UInt8; @@ -37,13 +41,16 @@ namespace pl { export import Bool = DataType.Bool; export import Utf8 = DataType.Utf8; export import List = DataType.List; + // rome-ignore lint/suspicious/noShadowRestrictedNames: pl.Date export import Date = DataType.Date; export import Datetime = DataType.Datetime; export import Time = DataType.Time; + // rome-ignore lint/suspicious/noShadowRestrictedNames: pl.Object export import Object = DataType.Object; export import Null = DataType.Null; export import Struct = DataType.Struct; export import Categorical = DataType.Categorical; + export import Field = _field; export import repeat = func.repeat; export import concat = func.concat; @@ -64,39 +71,34 @@ namespace pl { export import readJSONStream = io.readJSONStream; // lazy - export import col = lazy.col - export import cols = lazy.cols - export import lit = lazy.lit - export import arange = lazy.arange - export import argSortBy = lazy.argSortBy - export import avg = lazy.avg - export import concatList = lazy.concatList - export import concatString = lazy.concatString - export import count = lazy.count - export import cov = lazy.cov - export import exclude = lazy.exclude - export import element = lazy.element - export import first = lazy.first - export import format = lazy.format - export import groups = lazy.groups - export import head = lazy.head - export import last = lazy.last - export import mean = lazy.mean - export import median = lazy.median - export import nUnique = lazy.nUnique - export import pearsonCorr = lazy.pearsonCorr - export import quantile = lazy.quantile - export import select = lazy.select - export import struct = lazy.struct - export import spearmanRankCorr = lazy.spearmanRankCorr - export import tail = lazy.tail - export import list = lazy.list - export import when = _when.when; + export import col = lazy.col; + export import cols = lazy.cols; + export import lit = lazy.lit; + export import arange = lazy.arange; + export import argSortBy = lazy.argSortBy; + export import avg = lazy.avg; + export import concatList = lazy.concatList; + export import concatString = lazy.concatString; + export import count = lazy.count; + export import cov = lazy.cov; + export import exclude = lazy.exclude; + export import element = lazy.element; + export import first = lazy.first; + export import format = lazy.format; + export import groups = lazy.groups; + export import head = lazy.head; + export import last = lazy.last; + export import mean = lazy.mean; + export import median = lazy.median; + export import nUnique = lazy.nUnique; + export import pearsonCorr = lazy.pearsonCorr; + export import quantile = lazy.quantile; + export import select = lazy.select; + export import struct = lazy.struct; + export import spearmanRankCorr = lazy.spearmanRankCorr; + export import tail = lazy.tail; + export import list = lazy.list; export const version = pli.version(); } - -// add this globally so packages can reuse it. -// eslint-disable-next-line no-undef -global[Symbol.for("__pl__")] = pl; // eslint-disable-next-line no-undef -export = pl; +export default pl; diff --git a/polars/internals/construction.ts b/polars/internals/construction.ts index 1e364702d..44955f4a2 100644 --- a/polars/internals/construction.ts +++ b/polars/internals/construction.ts @@ -1,51 +1,49 @@ import pli from "./polars_internal"; import { DataType, polarsTypeToConstructor } from "../datatypes"; import { isTypedArray } from "util/types"; -import {Series} from "../series/series"; -import {_DataFrame} from "../dataframe"; -import {TimeUnit} from "../datatypes/datatype"; -import {Field} from "../datatypes/field"; - +import { Series } from "../series"; +import { _DataFrame } from "../dataframe"; +import { TimeUnit } from "../datatypes/datatype"; +import { Field } from "../datatypes/field"; export const jsTypeToPolarsType = (value: unknown): DataType => { - if(value === null) { + if (value === null) { return DataType.Float64; } if (Array.isArray(value)) { return jsTypeToPolarsType(firstNonNull(value)); } - if(isTypedArray(value)) { + if (isTypedArray(value)) { switch (value.constructor.name) { - case Int8Array.name: - return DataType.Int8; - case Int16Array.name: - return DataType.Int16; - case Int32Array.name: - return DataType.Int32; - case BigInt64Array.name: - return DataType.Int64; - case Uint8Array.name: - return DataType.UInt8; - case Uint16Array.name: - return DataType.UInt16; - case Uint32Array.name: - return DataType.UInt32; - case BigUint64Array.name: - return DataType.UInt64; - case Float32Array.name: - return DataType.Float32; - case Float64Array.name: - return DataType.Float64; - default: - throw new Error(`unknown typed array type: ${value.constructor.name}`); + case Int8Array.name: + return DataType.Int8; + case Int16Array.name: + return DataType.Int16; + case Int32Array.name: + return DataType.Int32; + case BigInt64Array.name: + return DataType.Int64; + case Uint8Array.name: + return DataType.UInt8; + case Uint16Array.name: + return DataType.UInt16; + case Uint32Array.name: + return DataType.UInt32; + case BigUint64Array.name: + return DataType.UInt64; + case Float32Array.name: + return DataType.Float32; + case Float64Array.name: + return DataType.Float64; + default: + throw new Error(`unknown typed array type: ${value.constructor.name}`); } } if (value instanceof Date) { - return DataType.Datetime(TimeUnit.Milliseconds); } - if(typeof value === "object" && (value as any).constructor === Object) { + if (typeof value === "object" && (value as any).constructor === Object) { const flds = Object.entries(value as any).map(([name, value]) => { let dtype = jsTypeToPolarsType(value); @@ -56,16 +54,16 @@ export const jsTypeToPolarsType = (value: unknown): DataType => { } switch (typeof value) { - case "bigint": - return DataType.UInt64; - case "number": - return DataType.Float64; - case "string": - return DataType.Utf8; - case "boolean": - return DataType.Bool; - default: - return DataType.Float64; + case "bigint": + return DataType.UInt64; + case "number": + return DataType.Float64; + case "string": + return DataType.Utf8; + case "boolean": + return DataType.Bool; + default: + return DataType.Float64; } }; @@ -77,17 +75,17 @@ export const jsTypeToPolarsType = (value: unknown): DataType => { * * @example * ``` - * >>> const input = [null, [], [null, "a", "b"]] - * >>> firstNonNull(input) + * > const input = [null, [], [null, "a", "b"]] + * > firstNonNull(input) * ["a"] - * >>> const ints = [null, 1] - * >>> firstNonNull(ints) + * > const ints = [null, 1] + * > firstNonNull(ints) * 1 * ``` */ const firstNonNull = (arr: any[]): any => { - const first = arr.find(x => x !== null && x !== undefined); - if(Array.isArray(first)) { + const first = arr.find((x) => x !== null && x !== undefined); + if (Array.isArray(first)) { return [firstNonNull(arr.flat())]; } @@ -96,78 +94,84 @@ const firstNonNull = (arr: any[]): any => { const fromTypedArray = (name, value) => { switch (value.constructor.name) { - case Int8Array.name: - return pli.JsSeries.newInt8Array(name, value); - case Int16Array.name: - return pli.JsSeries.newInt16Array(name, value); - case Int32Array.name: - return pli.JsSeries.newInt32Array(name, value); - case BigInt64Array.name: - return pli.JsSeries.newBigint64Array(name, value); - case Uint8Array.name: - return pli.JsSeries.newUint8Array(name, value); - case Uint8ClampedArray.name: - return pli.JsSeries.newUint8ClampedArray(name, value); - case Uint16Array.name: - return pli.JsSeries.newUint16Array(name, value); - case Uint32Array.name: - return pli.JsSeries.newUint32Array(name, value); - case BigUint64Array.name: - return pli.JsSeries.newBiguint64Array(name, value); - case Float32Array.name: - return pli.JsSeries.newFloat32Array(name, value); - case Float64Array.name: - return pli.JsSeries.newFloat64Array(name, value); - default: - throw new Error(`unknown typed array type: ${value.constructor.name}`); + case Int8Array.name: + return pli.JsSeries.newInt8Array(name, value); + case Int16Array.name: + return pli.JsSeries.newInt16Array(name, value); + case Int32Array.name: + return pli.JsSeries.newInt32Array(name, value); + case BigInt64Array.name: + return pli.JsSeries.newBigint64Array(name, value); + case Uint8Array.name: + return pli.JsSeries.newUint8Array(name, value); + case Uint8ClampedArray.name: + return pli.JsSeries.newUint8ClampedArray(name, value); + case Uint16Array.name: + return pli.JsSeries.newUint16Array(name, value); + case Uint32Array.name: + return pli.JsSeries.newUint32Array(name, value); + case BigUint64Array.name: + return pli.JsSeries.newBiguint64Array(name, value); + case Float32Array.name: + return pli.JsSeries.newFloat32Array(name, value); + case Float64Array.name: + return pli.JsSeries.newFloat64Array(name, value); + default: + throw new Error(`unknown typed array type: ${value.constructor.name}`); } }; /** * Construct an internal `JsSeries` from an array */ -export function arrayToJsSeries(name: string = "", values: any[] = [], dtype?: any, strict = false): any { +export function arrayToJsSeries( + name: string = "", + values: any[] = [], + dtype?: any, + strict = false, +): any { if (isTypedArray(values)) { return fromTypedArray(name, values); } //Empty sequence defaults to Float64 type - if (!values?.length && !dtype) { + if (!(values?.length || dtype)) { dtype = DataType.Float64; } const firstValue = firstNonNull(values); - if(Array.isArray(firstValue) || isTypedArray(firstValue)) { + if (Array.isArray(firstValue) || isTypedArray(firstValue)) { const listDtype = jsTypeToPolarsType(firstValue); - const constructor = polarsTypeToConstructor(DataType.List(listDtype)); + const ctor = polarsTypeToConstructor(DataType.List(listDtype)); - return constructor(name, values, strict, listDtype); + return ctor(name, values, strict, listDtype); } dtype = dtype ?? jsTypeToPolarsType(firstValue); let series: any; - if(dtype?.variant === "Struct") { + if (dtype?.variant === "Struct") { const df = pli.fromRows(values, null, 1); return df.toStruct(name); } - if(firstValue instanceof Date) { - + if (firstValue instanceof Date) { series = pli.JsSeries.newOptDate(name, values, strict); } else { - const constructor = polarsTypeToConstructor(dtype); - series = constructor(name, values, strict); - } - if ([ - "Datetime", - "Date", - "Categorical", - "Int8", - "Int16", - "UInt8", - "UInt16", - "Float32", - ].includes(dtype.variant)) { + const ctor = polarsTypeToConstructor(dtype); + series = ctor(name, values, strict); + } + if ( + [ + "Datetime", + "Date", + "Categorical", + "Int8", + "Int16", + "UInt8", + "UInt16", + "Float32", + ].includes(dtype.variant) + ) { series = series.cast(dtype, strict); } @@ -178,50 +182,41 @@ export function arrayToJsDataFrame(data: any[], options?): any { let columns = options?.columns; let orient = options?.orient; - let dataSeries: any[]; - if(!data.length) { + if (!data.length) { dataSeries = []; - } - else if (data[0]?._s) { + } else if (data[0]?._s) { dataSeries = []; data.forEach((series: any, idx) => { - if(!series.name) { + if (!series.name) { series.rename(`column_${idx}`, true); } dataSeries.push(series._s); }); - } - else if(data[0].constructor.name === "Object") { - - const df = pli.fromRows( data, options); + } else if (data[0].constructor.name === "Object") { + const df = pli.fromRows(data, options); - if(columns) { + if (columns) { df.columns = columns; } return df; - } - else if (Array.isArray(data[0])) { - if(!orient && columns) { + } else if (Array.isArray(data[0])) { + if (!orient && columns) { orient = columns.length === data.length ? "col" : "row"; } - if(orient === "row") { + if (orient === "row") { const df = pli.fromRows(data); columns && (df.columns = columns); return df; } else { - dataSeries = data.map((s, idx) => (Series(`column_${idx}`, s) as any)._s); - } - - } - else { + } else { dataSeries = [(Series("column_0", data) as any)._s]; } dataSeries = handleColumnsArg(dataSeries, columns); @@ -230,12 +225,12 @@ export function arrayToJsDataFrame(data: any[], options?): any { } function handleColumnsArg(data: any[], columns?: string[]) { - if(!columns) { + if (!columns) { return data; } else { - if(!data) { - return columns.map(c => (Series.from(c, []) as any)._s); - } else if(data.length === columns.length) { + 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); }); diff --git a/polars/io.ts b/polars/io.ts index 7e3912c5b..2be3aa3a5 100644 --- a/polars/io.ts +++ b/polars/io.ts @@ -80,7 +80,7 @@ class LineBatcher extends Stream.Transform { if (chunk[i] === 10) { // '\n' this.#accumulatedLines++; - if (this.#accumulatedLines == this.#batchSize) { + if (this.#accumulatedLines === this.#batchSize) { this.#lines.push(chunk.subarray(begin, i + 1)); this.push(Buffer.concat(this.#lines)); this.#lines = []; @@ -106,27 +106,27 @@ class LineBatcher extends Stream.Transform { function readCSVBuffer(buff, options) { return _DataFrame( - pli.readCsv(buff, { ...readCsvDefaultOptions, ...options }) + pli.readCsv(buff, { ...readCsvDefaultOptions, ...options }), ); } export function readRecords( records: Record[], - options?: { schema: Record } + options?: { schema: Record }, ): DataFrame; export function readRecords( records: Record[], - options?: { inferSchemaLength?: number } + options?: { inferSchemaLength?: number }, ): DataFrame; export function readRecords( records: Record[], - options + options, ): DataFrame { if (options?.schema) { return _DataFrame(pli.fromRows(records, options.schema)); } else { return _DataFrame( - pli.fromRows(records, undefined, options?.inferSchemaLength) + pli.fromRows(records, undefined, options?.inferSchemaLength), ); } } @@ -170,7 +170,7 @@ export function readRecords( */ export function readCSV( pathOrBody: string | Buffer, - options?: Partial + options?: Partial, ): DataFrame; export function readCSV(pathOrBody, options?) { options = { ...readCsvDefaultOptions, ...options }; @@ -257,7 +257,7 @@ const scanCsvDefaultOptions: Partial = { */ export function scanCSV( path: string, - options?: Partial + options?: Partial, ): LazyDataFrame; export function scanCSV(path, options?) { options = { ...scanCsvDefaultOptions, ...options }; @@ -298,11 +298,11 @@ export function scanCSV(path, options?) { */ export function readJSON( pathOrBody: string | Buffer, - options?: Partial + options?: Partial, ): DataFrame; export function readJSON( pathOrBody, - options: Partial = readJsonDefaultOptions + options: Partial = readJsonDefaultOptions, ) { options = { ...readJsonDefaultOptions, ...options }; let method = options.format === "lines" ? pli.readJsonLines : pli.readJson; @@ -366,7 +366,7 @@ interface ScanJsonOptions { */ export function scanJson( path: string, - options?: Partial + options?: Partial, ): LazyDataFrame; export function scanJson(path: string, options?: Partial) { options = { ...readJsonDefaultOptions, ...options }; @@ -396,7 +396,7 @@ interface ReadParquetOptions { */ export function readParquet( pathOrBody: string | Buffer, - options?: Partial + options?: Partial, ): DataFrame { const pliOptions: any = {}; @@ -418,7 +418,7 @@ export function readParquet( const inline = !isPath(pathOrBody, [".parquet"]); if (inline) { return _DataFrame( - pli.readParquet(Buffer.from(pathOrBody), pliOptions, parallel) + pli.readParquet(Buffer.from(pathOrBody), pliOptions, parallel), ); } else { return _DataFrame(pli.readParquet(pathOrBody, pliOptions, parallel)); @@ -445,7 +445,7 @@ export interface ReadAvroOptions { */ export function readAvro( pathOrBody: string | Buffer, - options?: Partial + options?: Partial, ): DataFrame; export function readAvro(pathOrBody, options = {}) { if (Buffer.isBuffer(pathOrBody)) { @@ -515,7 +515,7 @@ export interface ReadIPCOptions { */ export function readIPC( pathOrBody: string | Buffer, - options?: Partial + options?: Partial, ): DataFrame; export function readIPC(pathOrBody, options = {}) { if (Buffer.isBuffer(pathOrBody)) { @@ -550,7 +550,7 @@ export interface ScanIPCOptions { */ export function scanIPC( path: string, - options?: Partial + options?: Partial, ): LazyDataFrame; export function scanIPC(path, options = {}) { return _LazyDataFrame(pli.scanIpc(path, options)); @@ -623,7 +623,7 @@ export function scanIPC(path, options = {}) { */ export function readCSVStream( stream: Readable, - options?: Partial + options?: Partial, ): Promise; export function readCSVStream(stream, options?) { let batchSize = options?.batchSize ?? 10000; @@ -690,7 +690,7 @@ export function readCSVStream(stream, options?) { */ export function readJSONStream( stream: Readable, - options?: Partial + options?: Partial, ): Promise; export function readJSONStream(stream, options = readJsonDefaultOptions) { options = { ...readJsonDefaultOptions, ...options }; diff --git a/polars/lazy/dataframe.ts b/polars/lazy/dataframe.ts index 8efb7576e..de57b2012 100644 --- a/polars/lazy/dataframe.ts +++ b/polars/lazy/dataframe.ts @@ -1,5 +1,5 @@ -import {DataFrame, _DataFrame} from "../dataframe"; -import {Expr, exprToLitOrExpr} from "./expr"; +import { DataFrame, _DataFrame } from "../dataframe"; +import { Expr, exprToLitOrExpr } from "./expr"; import pli from "../internals/polars_internal"; import { columnOrColumnsStrict, @@ -9,27 +9,12 @@ import { selectionToExprList, ValueOrArray, } from "../utils"; -import {LazyGroupBy} from "./groupby"; -import {Deserialize, GroupByOps, Serialize} from "../shared_traits"; +import { _LazyGroupBy, LazyGroupBy } from "./groupby"; +import { Deserialize, GroupByOps, Serialize } from "../shared_traits"; +import { LazyOptions, LazyJoinOptions } from "../types"; const inspect = Symbol.for("nodejs.util.inspect.custom"); -type LazyJoinOptions = { - how?: "left" | "inner" | "outer" | "semi" | "anti" | "cross"; - suffix?: string; - allowParallel?: boolean; - forceParallel?: boolean; -}; - -type LazyOptions = { - typeCoercion?: boolean; - predicatePushdown?: boolean; - projectionPushdown?: boolean; - simplifyExpression?: boolean; - stringCache?: boolean; - noOptimization?: boolean; -}; - /** * Representation of a Lazy computation graph / query. */ @@ -89,7 +74,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { distinct( maintainOrder?: boolean, subset?: ColumnSelection, - keep?: "first" | "last" + keep?: "first" | "last", ): LazyDataFrame; distinct(opts: { maintainOrder?: boolean; @@ -138,13 +123,13 @@ export interface LazyDataFrame extends Serialize, GroupByOps { * @param predicate - Expression that evaluates to a boolean Series. * @example * ``` - * >>> lf = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }).lazy() - * >>> // Filter on one condition - * >>> lf.filter(pl.col("foo").lt(3)).collect() + * > lf = pl.DataFrame({ + * > "foo": [1, 2, 3], + * > "bar": [6, 7, 8], + * > "ham": ['a', 'b', 'c'] + * > }).lazy() + * > // Filter on one condition + * > lf.filter(pl.col("foo").lt(3)).collect() * shape: (2, 3) * ┌─────┬─────┬─────┐ * │ foo ┆ bar ┆ ham │ @@ -166,7 +151,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { * Start a groupby operation. */ groupBy(by: ColumnsOrExpr, maintainOrder?: boolean): LazyGroupBy; - groupBy(by: ColumnsOrExpr, opts: {maintainOrder: boolean}): LazyGroupBy; + groupBy(by: ColumnsOrExpr, opts: { maintainOrder: boolean }): LazyGroupBy; /** * Gets the first `n` rows of the DataFrame. You probably don't want to use this! @@ -214,22 +199,24 @@ export interface LazyDataFrame extends Serialize, GroupByOps { */ join( other: LazyDataFrame, - joinOptions: {on: ValueOrArray} & LazyJoinOptions + joinOptions: { on: ValueOrArray } & LazyJoinOptions, ): LazyDataFrame; join( other: LazyDataFrame, joinOptions: { leftOn: ValueOrArray; rightOn: ValueOrArray; - } & LazyJoinOptions + } & LazyJoinOptions, + ): LazyDataFrame; + join( + other: LazyDataFrame, + options: { + how: "cross"; + suffix?: string; + allowParallel?: boolean; + forceParallel?: boolean; + }, ): LazyDataFrame; - join(other: LazyDataFrame, options: { - how: "cross", - suffix?: string, - allowParallel?: boolean, - forceParallel?: boolean - }): LazyDataFrame - /** * Perform an asof join. This is similar to a left-join except that we @@ -282,7 +269,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { @example ``` - >>> const gdp = pl.DataFrame({ + >const gdp = pl.DataFrame({ ... date: [ ... new Date('2016-01-01'), ... new Date('2017-01-01'), @@ -291,7 +278,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { ... ], // note record date: Jan 1st (sorted!) ... gdp: [4164, 4411, 4566, 4696], ... }) - >>> const population = pl.DataFrame({ + >const population = pl.DataFrame({ ... date: [ ... new Date('2016-05-12'), ... new Date('2017-05-12'), @@ -300,7 +287,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { ... ], // note record date: May 12th (sorted!) ... "population": [82.19, 82.66, 83.12, 83.52], ... }) - >>> population.joinAsof( + >population.joinAsof( ... gdp, ... {leftOn:"date", rightOn:"date", strategy:"backward"} ... ) @@ -334,7 +321,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { tolerance?: number | string; allowParallel?: boolean; forceParallel?: boolean; - } + }, ): LazyDataFrame; /** * Get the last row of the DataFrame. @@ -386,13 +373,13 @@ export interface LazyDataFrame extends Serialize, GroupByOps { * @see {@link DataFrame.shift} */ shift(periods: number): LazyDataFrame; - shift(opts: {periods: number}): LazyDataFrame; + shift(opts: { periods: number }): LazyDataFrame; /** * @see {@link DataFrame.shiftAndFill} */ shiftAndFill( periods: number, - fillValue: number | string | Expr + fillValue: number | string | Expr, ): LazyDataFrame; shiftAndFill(opts: { periods: number; @@ -402,7 +389,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { * @see {@link DataFrame.slice} */ slice(offset: number, length: number): LazyDataFrame; - slice(opts: {offset: number; length: number}): LazyDataFrame; + slice(opts: { offset: number; length: number }): LazyDataFrame; /** * @see {@link DataFrame.sort} */ @@ -438,7 +425,7 @@ export interface LazyDataFrame extends Serialize, GroupByOps { unique( maintainOrder?: boolean, subset?: ColumnSelection, - keep?: "first" | "last" + keep?: "first" | "last", ): LazyDataFrame; unique(opts: { maintainOrder?: boolean; @@ -489,6 +476,7 @@ const prepareGroupbyInputs = (by) => { } }; +/** @ignore */ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { const unwrap = (method: string, ...args: any[]) => { return _ldf[method as any](...args); @@ -537,17 +525,17 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { }; if (typeof opts === "boolean") { - const o = {...defaultOptions, maintainOrder: opts, subset, keep}; + const o = { ...defaultOptions, maintainOrder: opts, subset, keep }; return _LazyDataFrame( - _ldf.unique(o.maintainOrder, o?.subset?.flat(2), o.keep) + _ldf.unique(o.maintainOrder, o?.subset?.flat(2), o.keep), ); } if (opts.subset) { opts.subset = [opts.subset].flat(3); } - const o = {...defaultOptions, ...opts}; + const o = { ...defaultOptions, ...opts }; return _LazyDataFrame(_ldf.unique(o.maintainOrder, o.subset, o.keep)); }, @@ -580,7 +568,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { opts.projectionPushdown, opts.simplifyExpr, opts.stringCache, - opts.slicePushdown + opts.slicePushdown, ); } @@ -598,7 +586,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { opts.projectionPushdown, opts.simplifyExpr, opts.stringCache, - opts.slicePushdown + opts.slicePushdown, ); } @@ -617,23 +605,23 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { return _LazyDataFrame(_ldf.filter(predicate)); }, - groupBy(opt, maintainOrder: any = true) { + groupBy(opt, maintainOrder: any = true): LazyGroupBy { if (opt?.by !== undefined) { const by = selectionToExprList([opt.by], false); - return LazyGroupBy(_ldf.groupby(by, opt.maintainOrder)); + return _LazyGroupBy(_ldf.groupby(by, opt.maintainOrder)); } const by = selectionToExprList([opt], false); - return LazyGroupBy(_ldf.groupby(by, maintainOrder)); + return _LazyGroupBy(_ldf.groupby(by, maintainOrder)); }, - groupByRolling({indexColumn, by, period, offset, closed}) { + groupByRolling({ indexColumn, by, period, offset, closed }) { offset = offset ?? `-${period}`; closed = closed ?? "right"; by = prepareGroupbyInputs(by); const lgb = _ldf.groupbyRolling(indexColumn, period, offset, closed, by); - return LazyGroupBy(lgb); + return _LazyGroupBy(lgb); }, groupByDynamic({ indexColumn, @@ -660,10 +648,10 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { truncate, includeBoundaries, closed, - by + by, ); - return LazyGroupBy(lgb); + return _LazyGroupBy(lgb); }, head(len = 5) { return _LazyDataFrame(_ldf.slice(0, len)); @@ -676,10 +664,21 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { forceParallel: false, ...options, }; - const {how, suffix, allowParallel, forceParallel} = options; + const { how, suffix, allowParallel, forceParallel } = options; if (how === "cross") { - - return _LazyDataFrame(_ldf.join(df._ldf, [], [], allowParallel, forceParallel, how, suffix, [], [])); + return _LazyDataFrame( + _ldf.join( + df._ldf, + [], + [], + allowParallel, + forceParallel, + how, + suffix, + [], + [], + ), + ); } let leftOn; let rightOn; @@ -692,7 +691,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { (options.rightOn && !options.leftOn) ) { throw new TypeError( - "You should pass the column to join on as an argument." + "You should pass the column to join on as an argument.", ); } else { leftOn = selectionToExprList(options.leftOn, false); @@ -708,7 +707,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { how, suffix, [], - [] + [], ); return _LazyDataFrame(ldf); @@ -721,10 +720,10 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { strategy: "backward", ...options, }; - const {suffix, strategy, allowParallel, forceParallel} = options; + const { suffix, strategy, allowParallel, forceParallel } = options; let leftOn; let rightOn; - if (!(other?._ldf)) { + if (!other?._ldf) { throw new TypeError("Expected a 'lazyFrame' as join table"); } if (options.on) { @@ -734,7 +733,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { (options.rightOn && !options.leftOn) ) { throw new TypeError( - "You should pass the column to join on as an argument." + "You should pass the column to join on as an argument.", ); } else { leftOn = options.leftOn; @@ -755,11 +754,11 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { if (typeof options.by === "string") { byLeft = byRight = [options.by]; - } else if (Array.isArray(options.by)) { byLeft = byRight = options.by; } - let toleranceStr, toleranceNum; + let toleranceStr; + let toleranceNum; if (typeof options.tolerance === "string") { toleranceStr = options.tolerance; } else { @@ -777,7 +776,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { suffix, strategy, toleranceNum, - toleranceStr + toleranceStr, ); return _LazyDataFrame(ldf); @@ -799,7 +798,7 @@ export const _LazyDataFrame = (_ldf: any): LazyDataFrame => { }, melt(ids, values) { return _LazyDataFrame( - _ldf.melt(columnOrColumnsStrict(ids), columnOrColumnsStrict(values)) + _ldf.melt(columnOrColumnsStrict(ids), columnOrColumnsStrict(values)), ); }, min() { @@ -901,6 +900,7 @@ export interface LazyDataFrameConstructor extends Deserialize { fromExternal(external: any): LazyDataFrame; } +/** @ignore */ export const LazyDataFrame: LazyDataFrameConstructor = Object.assign( _LazyDataFrame, { @@ -909,5 +909,5 @@ export const LazyDataFrame: LazyDataFrameConstructor = Object.assign( fromExternal(external) { return _LazyDataFrame(pli.JsLazyFrame.cloneExternal(external)); }, - } + }, ); diff --git a/polars/lazy/expr.ts b/polars/lazy/expr.ts deleted file mode 100644 index de6595365..000000000 --- a/polars/lazy/expr.ts +++ /dev/null @@ -1,1093 +0,0 @@ -import {DataType} from "../datatypes"; -import pli from "../internals/polars_internal"; -import { - ExprOrString, - FillNullStrategy, - RankMethod, - selectionToExprList, - INSPECT_SYMBOL -} from "../utils"; -import {Series} from "../series/series"; - -import * as expr from "./expr/"; -import {Arithmetic, Comparison, Cumulative, Deserialize, Rolling, Round, Sample, Serialize} from "../shared_traits"; -export type InterpolationMethod = "nearest" | "higher" | "lower" | "midpoint" | "linear"; - - -export interface Expr extends - Rolling, - Arithmetic, - Comparison, - Cumulative, - Sample, - Round, - Serialize { - /** @ignore */ - _expr: any; - get date(): expr.Datetime; - get str(): expr.String; - get lst(): expr.List; - get struct(): expr.Struct; - [Symbol.toStringTag](): string; - [INSPECT_SYMBOL](): string; - toString(): string; - /** compat with `JSON.stringify` */ - toJSON(): string; - /** Take absolute values */ - abs(): Expr - aggGroups(): Expr - /** - * Rename the output of an expression. - * @param name new name - * @see {@link Expr.as} - * @example - * ``` - * >>> df = pl.DataFrame({ - * ... "a": [1, 2, 3], - * ... "b": ["a", "b", None], - * ... }) - * >>> df - * shape: (3, 2) - * ╭─────┬──────╮ - * │ a ┆ b │ - * │ --- ┆ --- │ - * │ i64 ┆ str │ - * ╞═════╪══════╡ - * │ 1 ┆ "a" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 2 ┆ "b" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 3 ┆ null │ - * ╰─────┴──────╯ - * >>> df.select([ - * ... pl.col("a").alias("bar"), - * ... pl.col("b").alias("foo"), - * ... ]) - * shape: (3, 2) - * ╭─────┬──────╮ - * │ bar ┆ foo │ - * │ --- ┆ --- │ - * │ i64 ┆ str │ - * ╞═════╪══════╡ - * │ 1 ┆ "a" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 2 ┆ "b" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 3 ┆ null │ - * ╰─────┴──────╯ - *``` - */ - alias(name: string): Expr - and(other: any): Expr - /** Get the index of the maximal value. */ - argMax(): Expr - /** Get the index of the minimal value. */ - argMin(): Expr - /** - * Get the index values that would sort this column. - * @param reverse - * - false -> order from small to large. - * - true -> order from large to small. - * @returns UInt32 Series - */ - argSort(reverse?: boolean): Expr - argSort({reverse}: {reverse: boolean}): Expr - /** Get index of first unique value. */ - argUnique(): Expr - /** @see {@link Expr.alias} */ - as(name: string): Expr - /** Fill missing values with the next to be seen values */ - backwardFill(): Expr - /** Cast between data types. */ - cast(dtype: DataType, strict?: boolean): Expr - /** Count the number of values in this expression */ - count(): Expr - /** Calculate the n-th discrete difference. - * - * @param n number of slots to shift - * @param nullBehavior ignore or drop - */ - diff(n: number, nullBehavior: "ignore" | "drop"): Expr - diff(o: {n: number, nullBehavior: "ignore" | "drop"}): Expr - /** - * Compute the dot/inner product between two Expressions - * @param other Expression to compute dot product with - */ - dot(other: any): Expr - /** - * Exclude certain columns from a wildcard/regex selection. - * - * You may also use regexes in the exclude list. They must start with `^` and end with `$`. - * - * @param columns Column(s) to exclude from selection - * @example - * ``` - * >>> df = pl.DataFrame({ - * ... "a": [1, 2, 3], - * ... "b": ["a", "b", None], - * ... "c": [None, 2, 1], - * ...}) - * >>> df - * shape: (3, 3) - * ╭─────┬──────┬──────╮ - * │ a ┆ b ┆ c │ - * │ --- ┆ --- ┆ --- │ - * │ i64 ┆ str ┆ i64 │ - * ╞═════╪══════╪══════╡ - * │ 1 ┆ "a" ┆ null │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 2 ┆ "b" ┆ 2 │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 3 ┆ null ┆ 1 │ - * ╰─────┴──────┴──────╯ - * >>> df.select( - * ... pl.col("*").exclude("b"), - * ... ) - * shape: (3, 2) - * ╭─────┬──────╮ - * │ a ┆ c │ - * │ --- ┆ --- │ - * │ i64 ┆ i64 │ - * ╞═════╪══════╡ - * │ 1 ┆ null │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 2 ┆ 2 │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ - * │ 3 ┆ 1 │ - * ╰─────┴──────╯ - * ``` - */ - exclude(column: string, ...columns: string[]): Expr - /** - * Explode a list or utf8 Series. - * - * This means that every item is expanded to a new row. - */ - explode(): Expr - /** - * Extend the Series with given number of values. - * @param value The value to extend the Series with. This value may be null to fill with nulls. - * @param n The number of values to extend. - * @deprecated - * @see {@link extendConstant} - */ - extend(value: any, n: number): Expr - extend(opt: {value: any, n: number}): Expr - /** - * Extend the Series with given number of values. - * @param value The value to extend the Series with. This value may be null to fill with nulls. - * @param n The number of values to extend. - */ - extendConstant(value: any, n: number): Expr - extendConstant(opt: {value: any, n: number}): Expr - /** Fill nan value with a fill value */ - fillNan(other: any): Expr - /** Fill null value with a fill value or strategy */ - fillNull(other: any | FillNullStrategy): Expr - /** - * Filter a single column. - * - * Mostly useful in in aggregation context. - * If you want to filter on a DataFrame level, use `LazyFrame.filter`. - * @param predicate Boolean expression. - */ - filter(predicate: Expr): Expr - /** Get the first value. */ - first(): Expr - /** @see {@link Expr.explode} */ - flatten(): Expr - /** Fill missing values with the latest seen values */ - forwardFill(): Expr - /** Hash the Series. */ - hash(k0?: number, k1?: number, k2?: number, k3?: number): Expr - hash({k0, k1, k2, k3}: {k0?: number, k1?: number, k2?: number, k3?: number}): Expr - /** Take the first n values. */ - head(length?: number): Expr - head({length}: {length: number}): Expr - inner(): any - /** Interpolate intermediate values. The interpolation method is linear. */ - interpolate(): Expr - /** Get mask of duplicated values. */ - isDuplicated(): Expr - /** Create a boolean expression returning `true` where the expression values are finite. */ - isFinite(): Expr - /** Get a mask of the first unique value. */ - isFirst(): Expr - /** - * Check if elements of this Series are in the right Series, or List values of the right Series. - * - * @param other Series of primitive type or List type. - * @returns Expr that evaluates to a Boolean Series. - * @example - * ``` - * >>> df = pl.DataFrame({ - * ... "sets": [[1, 2, 3], [1, 2], [9, 10]], - * ... "optional_members": [1, 2, 3] - * ... }) - * >>> df.select( - * ... pl.col("optional_members").isIn("sets").alias("contains") - * ... ) - * shape: (3, 1) - * ┌──────────┐ - * │ contains │ - * │ --- │ - * │ bool │ - * ╞══════════╡ - * │ true │ - * ├╌╌╌╌╌╌╌╌╌╌┤ - * │ true │ - * ├╌╌╌╌╌╌╌╌╌╌┤ - * │ false │ - * └──────────┘ - * ``` - */ - isIn(other): Expr - /** Create a boolean expression returning `true` where the expression values are infinite. */ - isInfinite(): Expr - /** Create a boolean expression returning `true` where the expression values are NaN (Not A Number). */ - isNan(): Expr - /** Create a boolean expression returning `true` where the expression values are not NaN (Not A Number). */ - isNotNan(): Expr - /** Create a boolean expression returning `true` where the expression does not contain null values. */ - isNotNull(): Expr - /** Create a boolean expression returning `True` where the expression contains null values. */ - isNull(): Expr - /** Get mask of unique values. */ - isUnique(): Expr - /** - * Keep the original root name of the expression. - * - * A groupby aggregation often changes the name of a column. - * With `keepName` we can keep the original name of the column - * @example - * ``` - * >>> df = pl.DataFrame({ - * ... "a": [1, 2, 3], - * ... "b": ["a", "b", None], - * ... }) - * - * >>> df - * ... .groupBy("a") - * ... .agg(pl.col("b").list()) - * ... .sort({by:"a"}) - * - * shape: (3, 2) - * ╭─────┬────────────╮ - * │ a ┆ b_agg_list │ - * │ --- ┆ --- │ - * │ i64 ┆ list [str] │ - * ╞═════╪════════════╡ - * │ 1 ┆ [a] │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ [b] │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ [null] │ - * ╰─────┴────────────╯ - * - * Keep the original column name: - * - * >>> df - * ... .groupby("a") - * ... .agg(col("b").list().keepName()) - * ... .sort({by:"a"}) - * - * shape: (3, 2) - * ╭─────┬────────────╮ - * │ a ┆ b │ - * │ --- ┆ --- │ - * │ i64 ┆ list [str] │ - * ╞═════╪════════════╡ - * │ 1 ┆ [a] │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ [b] │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ [null] │ - * ╰─────┴────────────╯ - * ``` - */ - keepName(): Expr - kurtosis(): Expr - kurtosis(fisher: boolean, bias?: boolean): Expr - kurtosis({fisher, bias}: {fisher?: boolean, bias?: boolean}): Expr - /** Get the last value. */ - last(): Expr - /** Aggregate to list. */ - list(): Expr - /** Returns a unit Series with the lowest value possible for the dtype of this expression. */ - lowerBound(): Expr - /** Compute the max value of the arrays in the list */ - max(): Expr - /** Compute the mean value of the arrays in the list */ - mean(): Expr - /** Get median value. */ - median(): Expr - /** Get minimum value. */ - min(): Expr - /** Compute the most occurring value(s). Can return multiple Values */ - mode(): Expr - /** Negate a boolean expression. */ - not(): Expr - /** Count unique values. */ - nUnique(): Expr - or(other: any): Expr - /** - * Apply window function over a subgroup. - * - * This is similar to a groupby + aggregation + self join. - * Or similar to [window functions in Postgres](https://www.postgresql.org/docs/9.1/tutorial-window.html) - * @param partitionBy Column(s) to partition by. - * - * @example - * ``` - * >>> df = pl.DataFrame({ - * ... "groups": [1, 1, 2, 2, 1, 2, 3, 3, 1], - * ... "values": [1, 2, 3, 4, 5, 6, 7, 8, 8], - * ... }) - * >>> df.select( - * ... pl.col("groups").sum().over("groups") - * ... ) - * ╭────────┬────────╮ - * │ groups ┆ values │ - * │ --- ┆ --- │ - * │ i32 ┆ i32 │ - * ╞════════╪════════╡ - * │ 1 ┆ 16 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 1 ┆ 16 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ 13 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ 13 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ ... ┆ ... │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 1 ┆ 16 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ 13 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ 15 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ 15 │ - * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 1 ┆ 16 │ - * ╰────────┴────────╯ - * ``` - */ - over(by: ExprOrString, ...partitionBy: ExprOrString[]): Expr - /** Raise expression to the power of exponent. */ - pow(exponent: number): Expr - pow({exponent}: {exponent: number}): Expr - /** - * Add a prefix the to root column name of the expression. - * @example - * ``` - * >>> df = pl.DataFrame({ - * ... "A": [1, 2, 3, 4, 5], - * ... "fruits": ["banana", "banana", "apple", "apple", "banana"], - * ... "B": [5, 4, 3, 2, 1], - * ... "cars": ["beetle", "audi", "beetle", "beetle", "beetle"], - * ... }) - * shape: (5, 4) - * ╭─────┬──────────┬─────┬──────────╮ - * │ A ┆ fruits ┆ B ┆ cars │ - * │ --- ┆ --- ┆ --- ┆ --- │ - * │ i64 ┆ str ┆ i64 ┆ str │ - * ╞═════╪══════════╪═════╪══════════╡ - * │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ "banana" ┆ 4 ┆ "audi" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ - * │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ - * │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │ - * ╰─────┴──────────┴─────┴──────────╯ - * >>> df.select( - * ... pl.all().reverse().prefix("reverse_"), - * ... ) - * shape: (5, 8) - * ╭───────────┬────────────────┬───────────┬──────────────╮ - * │ reverse_A ┆ reverse_fruits ┆ reverse_B ┆ reverse_cars │ - * │ --- ┆ --- ┆ --- ┆ --- │ - * │ i64 ┆ str ┆ i64 ┆ str │ - * ╞═══════════╪════════════════╪═══════════╪══════════════╡ - * │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │ - * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │ - * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │ - * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 2 ┆ "banana" ┆ 4 ┆ "audi" │ - * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ - * │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │ - * ╰───────────┴────────────────┴───────────┴──────────────╯ - * ``` - */ - prefix(prefix: string): Expr - /** Get quantile value. */ - quantile(quantile: number | Expr): Expr - /** Assign ranks to data, dealing with ties appropriately. */ - rank(method?: RankMethod): Expr - rank({method}: {method: string}): Expr - reinterpret(signed?: boolean): Expr - reinterpret({signed}: {signed: boolean}): Expr - /** - * Repeat the elements in this Series `n` times by dictated by the number given by `by`. - * The elements are expanded into a `List` - * @param by Numeric column that determines how often the values will be repeated. - * - * The column will be coerced to UInt32. Give this dtype to make the coercion a no-op. - */ - repeatBy(by: Expr | string): Expr - /** Reverse the arrays in the list */ - reverse(): Expr - /** - * Shift the values by a given period and fill the parts that will be empty due to this operation - * @param periods number of places to shift (may be negative). - */ - shift(periods?: number): Expr - shift({periods}: {periods: number}): Expr - /** - * Shift the values by a given period and fill the parts that will be empty due to this operation - * @param periods Number of places to shift (may be negative). - * @param fillValue Fill null values with the result of this expression. - */ - shiftAndFill(periods: number, fillValue: Expr): Expr - shiftAndFill({periods, fillValue}: {periods: number, fillValue: Expr}): Expr - /** - * Compute the sample skewness of a data set. - * For normally distributed data, the skewness should be about zero. For - * unimodal continuous distributions, a skewness value greater than zero means - * that there is more weight in the right tail of the distribution. - * ___ - * @param bias If False, then the calculations are corrected for statistical bias. - */ - skew(bias?: boolean): Expr - skew({bias}: {bias: boolean}): Expr - /** Slice the Series. */ - slice(offset: number | Expr, length: number | Expr): Expr - slice({offset, length}: {offset: number | Expr, length: number | Expr}): Expr - /** - * Sort this column. In projection/ selection context the whole column is sorted. - * @param reverse - * * false -> order from small to large. - * * true -> order from large to small. - * @param nullsLast If true nulls are considered to be larger than any valid value - */ - sort(reverse?: boolean, nullsLast?: boolean): Expr - sort({reverse, nullsLast}: {reverse?: boolean, nullsLast?: boolean}): Expr - /** - * Sort this column by the ordering of another column, or multiple other columns. - In projection/ selection context the whole column is sorted. - If used in a groupby context, the groups are sorted. - - Parameters - ---------- - @param by - The column(s) used for sorting. - @param reverse - false -> order from small to large. - true -> order from large to small. - */ - sortBy(by: ExprOrString[] | ExprOrString, reverse?: boolean | boolean[]): Expr - sortBy(options: {by: ExprOrString[] | ExprOrString, reverse?: boolean | boolean[]}): Expr - /** Get standard deviation. */ - std(): Expr - /** Add a suffix the to root column name of the expression. */ - suffix(suffix: string): Expr - /** - * Get sum value. - * @note - * Dtypes in {Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues. - */ - sum(): Expr - /** Take the last n values. */ - tail(length?: number): Expr - tail({length}: {length: number}): Expr - /** - * Take values by index. - * @param index An expression that leads to a UInt32 dtyped Series. - */ - take(index: Expr | number[] | Series): Expr - take({index}: {index: Expr | number[] | Series}): Expr - /** Take every nth value in the Series and return as a new Series. */ - takeEvery(n: number): Expr - /** - * Get the unique values of this expression; - * @param maintainOrder Maintain order of data. This requires more work. - */ - unique(maintainOrder?: boolean | {maintainOrder: boolean}): Expr - /** Returns a unit Series with the highest value possible for the dtype of this expression. */ - upperBound(): Expr - /** Get variance. */ - var(): Expr - /** Alias for filter: @see {@link filter} */ - where(predicate: Expr): Expr -} - - -export const _Expr = (_expr: any): Expr => { - - const unwrap = (method: string, ...args: any[]) => { - return _expr[method as any](...args); - }; - const wrap = (method, ...args): Expr => { - return _Expr(unwrap(method, ...args)); - }; - - const wrapExprArg = (method: string, lit=false) => (other: any) => { - - const expr = exprToLitOrExpr(other, lit).inner(); - - return wrap(method, expr); - }; - - const rolling = (method: string) => (opts, weights?, minPeriods?, center?): Expr => { - const windowSize = opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null); - if(windowSize === null) { - throw new Error("window size is required"); - } - const callOpts = { - windowSize: `${windowSize}i`, - weights: opts?.["weights"] ?? weights, - minPeriods: opts?.["minPeriods"] ?? minPeriods ?? windowSize, - center : opts?.["center"] ?? center ?? false, - }; - - return wrap(method, callOpts); - }; - - return { - _expr, - [Symbol.toStringTag]() { - return "Expr"; - }, - [INSPECT_SYMBOL]() { - return _expr.toString(); - }, - serialize(format) { - return _expr.serialize(format); - }, - toString() { - return _expr.toString(); - }, - toJSON(...args: any[]) { - // this is passed by `JSON.stringify` when calling `toJSON()` - if(args[0] === "") { - return _expr.toJs(); - } - - return _expr.serialize("json").toString(); - }, - get str() { - return expr.StringFunctions(_expr); - }, - get lst() { - return expr.ListFunctions(_expr); - }, - get date() { - return expr.DateTimeFunctions(_expr); - }, - get struct() { - return expr.StructFunctions(_expr); - }, - abs() { - return _Expr(_expr.abs()); - }, - aggGroups() { - return _Expr(_expr.aggGroups()); - }, - alias(name) { - return _Expr(_expr.alias(name)); - }, - inner() { - return _expr; - }, - and(other) { - const expr = (exprToLitOrExpr(other, false) as any).inner(); - - return _Expr(_expr.and(expr)); - }, - argMax() { - return _Expr(_expr.argMax()); - }, - argMin() { - return _Expr(_expr.argMin()); - }, - argSort(reverse: any = false) { - reverse = reverse?.reverse ?? reverse; - - return _Expr(_expr.argSort(reverse)); - }, - argUnique() { - return _Expr(_expr.argUnique()); - }, - as(name) { - return _Expr(_expr.alias(name)); - }, - backwardFill() { - return _Expr(_expr.backwardFill()); - }, - cast(dtype, strict=false) { - return _Expr(_expr.cast(dtype, strict)); - }, - ceil() { - return _Expr(_expr.ceil()); - }, - clip(arg, max?){ - if(typeof arg === "number") { - return _Expr(_expr.clip(arg, max)); - } else { - return _Expr(_expr.clip(arg.min, arg.max)); - } - }, - count() { - return _Expr(_expr.count()); - }, - cumCount(reverse: any = false) { - reverse = reverse?.reverse ?? reverse; - - return _Expr(_expr.cumcount(reverse?.reverse ?? reverse)); - }, - cumMax(reverse: any = false) { - reverse = reverse?.reverse ?? reverse; - - return _Expr(_expr.cummax(reverse)); - }, - cumMin(reverse: any = false) { - reverse = reverse?.reverse ?? reverse; - - return _Expr(_expr.cummin(reverse)); - }, - cumProd(reverse: any = false) { - reverse = reverse?.reverse ?? reverse; - - return _Expr(_expr.cumprod(reverse)); - }, - cumSum(reverse: any = false) { - reverse = reverse?.reverse ?? reverse; - - return _Expr(_expr.cumsum(reverse)); - }, - diff(n, nullBehavior = "ignore") { - - if(typeof n === "number") { - - return _Expr(_expr.diff(n, nullBehavior)); - } - else { - return _Expr(_expr.diff(n.n, n.nullBehavior)); - } - }, - dot(other) { - const expr = (exprToLitOrExpr(other, false) as any).inner(); - - return _Expr(_expr.dot(expr)); - }, - exclude(...columns) { - return _Expr(_expr.exclude(columns.flat(2))); - }, - explode() { - return _Expr(_expr.explode()); - }, - extend(o, n?) { - if(n !== null && typeof n === "number") { - return _Expr(_expr.extendConstant(o, n)); - } - - return _Expr(_expr.extendConstant(o.value, o.n)); - - }, - extendConstant(o, n?) { - if(n !== null && typeof n === "number") { - return _Expr(_expr.extendConstant(o, n)); - } - - return _Expr(_expr.extendConstant(o.value, o.n)); - }, - fillNan(other) { - const expr = (exprToLitOrExpr(other, true) as any).inner(); - - return _Expr(_expr.fillNan(expr)); - }, - fillNull(fillValue) { - if(["backward", "forward", "mean", "min", "max", "zero", "one"].includes(fillValue)) { - return _Expr(_expr.fillNullWithStrategy(fillValue)); - } - - const expr = exprToLitOrExpr(fillValue).inner(); - - return _Expr(_expr.fillNull(expr)); - }, - filter(predicate) { - const expr = exprToLitOrExpr(predicate).inner(); - - return _Expr(_expr.filter(expr)); - }, - first() { - return _Expr(_expr.first()); - }, - flatten() { - return _Expr(_expr.explode()); - }, - floor() { - return _Expr(_expr.floor()); - }, - forwardFill() { - return _Expr(_expr.forwardFill()); - }, - hash(obj: any=0, k1=1, k2=2, k3=3) { - if (typeof obj === "number" || typeof obj === "bigint") { - return wrap("hash", BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3)); - } - const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj}; - - return wrap( - "hash", - BigInt(o.k0), - BigInt(o.k1), - BigInt(o.k2), - BigInt(o.k3) - ); - }, - head(length) { - if(typeof length === "number") { - return wrap("head", length); - } - - return wrap("head", length.length); - }, - interpolate(method: InterpolationMethod = "linear") { - return _Expr(_expr.interpolate(method)); - }, - isDuplicated() { - return _Expr(_expr.isDuplicated()); - }, - isFinite() { - return _Expr(_expr.isFinite()); - }, - isInfinite() { - return _Expr(_expr.isInfinite()); - }, - isFirst() { - return _Expr(_expr.isFirst()); - }, - isNan() { - return _Expr(_expr.isNan()); - }, - isNotNan() { - return _Expr(_expr.isNotNan()); - }, - isNotNull() { - return _Expr(_expr.isNotNull()); - }, - isNull() { - return _Expr(_expr.isNull()); - }, - isUnique() { - return _Expr(_expr.isUnique()); - }, - isIn(other) { - if(Array.isArray(other)) { - other = pli.lit(Series(other).inner()); - } else { - other = exprToLitOrExpr(other, false).inner(); - } - - return wrap("isIn", other); - }, - keepName() { - return _Expr(_expr.keepName()); - }, - kurtosis(obj?, bias=true) { - const fisher = obj?.["fisher"] ?? (typeof obj === "boolean" ? obj : true); - bias = obj?.["bias"] ?? bias; - - return _Expr(_expr.kurtosis(fisher, bias)); - - }, - last() { - return _Expr(_expr.last()); - }, - list() { - return _Expr(_expr.list()); - }, - lowerBound() { - return _Expr(_expr.lowerBound()); - }, - max() { - return _Expr(_expr.max()); - }, - mean() { - return _Expr(_expr.mean()); - }, - median() { - return _Expr(_expr.median()); - }, - min() { - return _Expr(_expr.min()); - }, - mode() { - return _Expr(_expr.mode()); - }, - not() { - return _Expr(_expr.not()); - }, - nUnique() { - return _Expr(_expr.nUnique()); - }, - or(other) { - const expr = exprToLitOrExpr(other).inner(); - - return _Expr(_expr.or(expr)); - }, - over(...exprs) { - const partitionBy = selectionToExprList(exprs, false); - - return wrap("over", partitionBy); - }, - pow(exponent) { - return _Expr(_expr.pow(exponent?.exponent ?? exponent)); - }, - prefix(prefix) { - - return _Expr(_expr.prefix(prefix)); - }, - quantile(quantile, interpolation: InterpolationMethod = "nearest") { - if (Expr.isExpr(quantile)) { - quantile = quantile._expr; - } else { - quantile = pli.lit(quantile); - } - - return _Expr(_expr.quantile(quantile, interpolation)); - }, - rank(method: any = "average", reverse=false) { - return _Expr(_expr.rank(method?.method ?? method, method?.reverse ?? reverse)); - }, - reinterpret(signed: any = true) { - signed = signed?.signed ?? signed; - - return _Expr(_expr.reinterpret(signed)); - }, - repeatBy(expr) { - const e = exprToLitOrExpr(expr, false)._expr; - - return _Expr(_expr.repeatBy(e)); - }, - reverse() { - return _Expr(_expr.reverse()); - }, - rollingMax: rolling("rollingMax"), - rollingMean: rolling("rollingMean"), - rollingMin: rolling("rollingMin"), - rollingSum: rolling("rollingSum"), - rollingStd: rolling("rollingStd"), - rollingVar: rolling("rollingVar"), - rollingMedian: rolling("rollingMedian"), - rollingQuantile(val, interpolation?, windowSize?, weights?, minPeriods?, center?) { - if(typeof val === "number") { - - return wrap("rollingQuantile", - val, - interpolation ?? "nearest", - { - windowSize: `${windowSize}i`, - weights, - minPeriods, - center - }); - } - windowSize = val?.["windowSize"] ?? (typeof val === "number" ? val : null); - if(windowSize === null) { - throw new Error("window size is required"); - } - const options = { - windowSize: `${windowSize}i`, - weights: val?.["weights"] ?? weights, - minPeriods: val?.["minPeriods"] ?? minPeriods ?? windowSize, - center : val?.["center"] ?? center ?? false, - }; - - return wrap("rollingQuantile", - val.quantile, - val.interpolation ?? "nearest", - options - ); - }, - rollingSkew(val, bias=true) { - if(typeof val === "number") { - return wrap("rollingSkew", val, bias); - } - - return wrap("rollingSkew", val.windowSize, val.bias ?? bias); - }, - round(decimals) { - return _Expr(_expr.round(decimals?.decimals ?? decimals)); - }, - sample(opts?, frac?, withReplacement = false, seed?) { - if(opts?.n !== undefined || opts?.frac !== undefined) { - - return this.sample(opts.n, opts.frac, opts.withReplacement, seed); - } - if (typeof opts === "number") { - throw new Error("sample_n is not yet supported for expr"); - } - if(typeof frac === "number") { - return wrap("sampleFrac", - frac, - withReplacement, - false, - seed - ); - } - else { - throw new TypeError("must specify either 'frac' or 'n'"); - } - }, - shift(periods) { - return _Expr(_expr.shift(periods)); - }, - shiftAndFill(optOrPeriods, fillValue?) { - if(typeof optOrPeriods === "number") { - fillValue = exprToLitOrExpr(fillValue).inner(); - - return wrap("shiftAndFill", optOrPeriods, fillValue); - - } - else { - fillValue = exprToLitOrExpr(optOrPeriods.fillValue).inner(); - const periods = optOrPeriods.periods; - - return wrap("shiftAndFill", periods, fillValue); - } - }, - skew(bias) { - return wrap("skew", bias?.bias ?? bias ?? true); - }, - slice(arg, len?) { - if(typeof arg === "number") { - return wrap("slice", pli.lit(arg), pli.lit(len)); - } - - return wrap("slice", pli.lit(arg.offset), pli.lit(arg.length)); - }, - sort(reverse: any = false, nullsLast=false) { - if(typeof reverse === "boolean") { - return wrap("sortWith", reverse, nullsLast); - } - - return wrap("sortWith", reverse?.reverse ?? false, reverse?.nullsLast ?? nullsLast); - }, - sortBy(arg, reverse=false) { - if(arg?.by !== undefined) { - return this.sortBy(arg.by, arg.reverse); - } - - reverse = Array.isArray(reverse) ? reverse.flat() : [reverse] as any; - const by = selectionToExprList(arg, false); - - return wrap("sortBy", by, reverse); - }, - std() { - return _Expr(_expr.std()); - }, - suffix(suffix) { - - return _Expr(_expr.suffix(suffix)); - }, - sum() { - return _Expr(_expr.sum()); - }, - tail(length) { - return _Expr(_expr.tail(length)); - }, - - take(indices) { - if(Array.isArray(indices)) { - indices = pli.lit(Series(indices).inner()); - } else { - indices = indices.inner(); - } - - return wrap("take", indices); - }, - takeEvery(n) { - return _Expr(_expr.takeEvery(n)); - }, - unique(opt?) { - if(opt) { - return wrap("unique_stable"); - } - - return wrap("unique"); - }, - upperBound() { - return _Expr(_expr.upperBound()); - }, - where(expr) { - - return this.filter(expr); - }, - var() { - return _Expr(_expr.var()); - }, - add: wrapExprArg("add"), - sub: wrapExprArg("sub"), - div: wrapExprArg("div"), - mul: wrapExprArg("mul"), - rem: wrapExprArg("rem"), - - plus: wrapExprArg("add"), - minus: wrapExprArg("sub"), - divideBy: wrapExprArg("div"), - multiplyBy: wrapExprArg("mul"), - modulo: wrapExprArg("rem"), - - eq: wrapExprArg("eq"), - equals: wrapExprArg("eq"), - gtEq: wrapExprArg("gtEq"), - greaterThanEquals: wrapExprArg("gtEq"), - gt: wrapExprArg("gt"), - greaterThan: wrapExprArg("gt"), - ltEq: wrapExprArg("ltEq"), - lessThanEquals: wrapExprArg("ltEq"), - lt: wrapExprArg("lt"), - lessThan: wrapExprArg("lt"), - neq: wrapExprArg("neq"), - notEquals: wrapExprArg("neq"), - }; -}; - -export interface ExprConstructor extends Deserialize { - isExpr(arg: any): arg is Expr; -} - -const isExpr = (anyVal: any): anyVal is Expr => { - try { - return anyVal?.[Symbol.toStringTag]?.() === "Expr"; - } catch (err) { - return false; - } -}; - - -const deserialize = (buf, format) => { - return _Expr(pli.JsExpr.deserialize(buf, format)); -}; - -export const Expr: ExprConstructor = Object.assign(_Expr, {isExpr, deserialize}); - -/** @ignore */ -export const exprToLitOrExpr = (expr: any, stringToLit = true): Expr => { - if(typeof expr === "string" && !stringToLit) { - return _Expr(pli.col(expr)); - } else if (Expr.isExpr(expr)) { - return expr; - } else if (Series.isSeries(expr)) { - return _Expr(pli.lit((expr as any)._s)); - } else { - return _Expr(pli.lit(expr)); - } -}; diff --git a/polars/lazy/expr/datetime.ts b/polars/lazy/expr/datetime.ts index d2c3f41fd..a58eb2675 100644 --- a/polars/lazy/expr/datetime.ts +++ b/polars/lazy/expr/datetime.ts @@ -1,102 +1,13 @@ -import {Expr, _Expr} from "../expr"; +import { DateFunctions } from "../../shared_traits"; +import { Expr, _Expr } from "../expr"; -export interface ExprDateTime { - /** - * Extract day from underlying Date representation. - * Can be performed on Date and Datetime. - * - * Returns the day of month starting from 1. - * The return value ranges from 1 to 31. (The last day of month differs by months.) - * @returns day as pl.UInt32 - */ - day(): Expr; - /** - * Extract hour from underlying DateTime representation. - * Can be performed on Datetime. - * - * Returns the hour number from 0 to 23. - * @returns Hour as UInt32 - */ - hour(): Expr; - /** - * Extract minutes from underlying DateTime representation. - * Can be performed on Datetime. - * - * Returns the minute number from 0 to 59. - * @returns minute as UInt32 - */ - minute(): Expr; - /** - * Extract month from underlying Date representation. - * Can be performed on Date and Datetime. - * - * Returns the month number starting from 1. - * The return value ranges from 1 to 12. - * @returns Month as UInt32 - */ - month(): Expr; - /** - * Extract seconds from underlying DateTime representation. - * Can be performed on Datetime. - * - * Returns the number of nanoseconds since the whole non-leap second. - * The range from 1,000,000,000 to 1,999,999,999 represents the leap second. - * @returns Nanosecond as UInt32 - */ - nanosecond(): Expr; - /** - * Extract ordinal day from underlying Date representation. - * Can be performed on Date and Datetime. - * - * Returns the day of year starting from 1. - * The return value ranges from 1 to 366. (The last day of year differs by years.) - * @returns Day as UInt32 - */ - ordinalDay(): Expr; - /** - * Extract seconds from underlying DateTime representation. - * Can be performed on Datetime. - * - * Returns the second number from 0 to 59. - * @returns Second as UInt32 - */ - second(): Expr; - /** - * Format Date/datetime with a formatting rule: See [chrono strftime/strptime](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html). - */ - strftime(fmt: string): Expr; - /** Return timestamp in ms as Int64 type. */ - timestamp(): Expr; - /** - * Extract the week from the underlying Date representation. - * Can be performed on Date and Datetime - * - * Returns the ISO week number starting from 1. - * The return value ranges from 1 to 53. (The last week of year differs by years.) - * @returns Week number as UInt32 - */ - week(): Expr; - /** - * Extract the week day from the underlying Date representation. - * Can be performed on Date and Datetime. - * - * Returns the weekday number where monday = 0 and sunday = 6 - * @returns Week day as UInt32 - */ - weekday(): Expr; - /** - * Extract year from underlying Date representation. - * Can be performed on Date and Datetime. - * - * Returns the year number in the calendar date. - * @returns Year as Int32 - */ - year(): Expr; -} +/** + * DateTime functions + */ +export interface ExprDateTime extends DateFunctions {} export const ExprDateTimeFunctions = (_expr: any): ExprDateTime => { const wrap = (method, ...args: any[]): Expr => { - return _Expr(_expr[method](...args)); }; diff --git a/polars/lazy/expr/index.ts b/polars/lazy/expr/index.ts index a0289830c..58d32c2a1 100644 --- a/polars/lazy/expr/index.ts +++ b/polars/lazy/expr/index.ts @@ -2,19 +2,1140 @@ import * as dt from "./datetime"; import * as lst from "./list"; import * as str from "./string"; import * as struct from "./struct"; +export type { StringNamespace } from "./string"; +export type { ExprList as ListNamespace } from "./list"; +export type { ExprDateTime as DatetimeNamespace } from "./datetime"; +export type { ExprStruct as StructNamespace } from "./struct"; -namespace expr { +import { DataType } from "../../datatypes"; +import pli from "../../internals/polars_internal"; +import { ExprOrString, selectionToExprList, INSPECT_SYMBOL } from "../../utils"; +import { Series } from "../../series"; +import { + Arithmetic, + Comparison, + Cumulative, + Deserialize, + Rolling, + Round, + Sample, + Serialize, +} from "../../shared_traits"; +import { InterpolationMethod, FillNullStrategy, RankMethod } from "../../types"; +/** + * Expressions that can be used in various contexts. + */ +export interface Expr + extends Rolling, + Arithmetic, + Comparison, + Cumulative, + Sample, + Round, + Serialize { + /** @ignore */ + _expr: any; + /** + * Datetime namespace + */ + get date(): dt.ExprDateTime; + /** + * String namespace + */ + get str(): str.StringNamespace; + /** + * List namespace + */ + get lst(): lst.ExprList; + /** + * Struct namespace + */ + get struct(): struct.ExprStruct; + [Symbol.toStringTag](): string; + [INSPECT_SYMBOL](): string; + toString(): string; + /** compat with `JSON.stringify` */ + toJSON(): string; + /** Take absolute values */ + abs(): Expr; + aggGroups(): Expr; + /** + * Rename the output of an expression. + * @param name new name + * @see {@link Expr.as} + * @example + * ``` + * > df = pl.DataFrame({ + * ... "a": [1, 2, 3], + * ... "b": ["a", "b", None], + * ... }) + * > df + * shape: (3, 2) + * ╭─────┬──────╮ + * │ a ┆ b │ + * │ --- ┆ --- │ + * │ i64 ┆ str │ + * ╞═════╪══════╡ + * │ 1 ┆ "a" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2 ┆ "b" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 3 ┆ null │ + * ╰─────┴──────╯ + * > df.select([ + * ... pl.col("a").alias("bar"), + * ... pl.col("b").alias("foo"), + * ... ]) + * shape: (3, 2) + * ╭─────┬──────╮ + * │ bar ┆ foo │ + * │ --- ┆ --- │ + * │ i64 ┆ str │ + * ╞═════╪══════╡ + * │ 1 ┆ "a" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2 ┆ "b" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 3 ┆ null │ + * ╰─────┴──────╯ + *``` + */ + alias(name: string): Expr; + and(other: any): Expr; + /** Get the index of the maximal value. */ + argMax(): Expr; + /** Get the index of the minimal value. */ + argMin(): Expr; + /** + * Get the index values that would sort this column. + * @param reverse + * - false -> order from small to large. + * - true -> order from large to small. + * @returns UInt32 Series + */ + argSort(reverse?: boolean): Expr; + argSort({ reverse }: { reverse: boolean }): Expr; + /** Get index of first unique value. */ + argUnique(): Expr; + /** @see {@link Expr.alias} */ + as(name: string): Expr; + /** Fill missing values with the next to be seen values */ + backwardFill(): Expr; + /** Cast between data types. */ + cast(dtype: DataType, strict?: boolean): Expr; + /** Count the number of values in this expression */ + count(): Expr; + /** Calculate the n-th discrete difference. + * + * @param n number of slots to shift + * @param nullBehavior ignore or drop + */ + diff(n: number, nullBehavior: "ignore" | "drop"): Expr; + diff(o: { n: number; nullBehavior: "ignore" | "drop" }): Expr; + /** + * Compute the dot/inner product between two Expressions + * @param other Expression to compute dot product with + */ + dot(other: any): Expr; + /** + * Exclude certain columns from a wildcard/regex selection. + * + * You may also use regexes in the exclude list. They must start with `^` and end with `$`. + * + * @param columns Column(s) to exclude from selection + * @example + * ``` + * >df = pl.DataFrame({ + * ... "a": [1, 2, 3], + * ... "b": ["a", "b", None], + * ... "c": [None, 2, 1], + * ...}) + * >df + * shape: (3, 3) + * ╭─────┬──────┬──────╮ + * │ a ┆ b ┆ c │ + * │ --- ┆ --- ┆ --- │ + * │ i64 ┆ str ┆ i64 │ + * ╞═════╪══════╪══════╡ + * │ 1 ┆ "a" ┆ null │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2 ┆ "b" ┆ 2 │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 3 ┆ null ┆ 1 │ + * ╰─────┴──────┴──────╯ + * >df.select( + * ... pl.col("*").exclude("b"), + * ... ) + * shape: (3, 2) + * ╭─────┬──────╮ + * │ a ┆ c │ + * │ --- ┆ --- │ + * │ i64 ┆ i64 │ + * ╞═════╪══════╡ + * │ 1 ┆ null │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 2 ┆ 2 │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌┤ + * │ 3 ┆ 1 │ + * ╰─────┴──────╯ + * ``` + */ + exclude(column: string, ...columns: string[]): Expr; + /** + * Explode a list or utf8 Series. + * + * This means that every item is expanded to a new row. + */ + explode(): Expr; + /** + * Extend the Series with given number of values. + * @param value The value to extend the Series with. This value may be null to fill with nulls. + * @param n The number of values to extend. + * @deprecated + * @see {@link extendConstant} + */ + extend(value: any, n: number): Expr; + extend(opt: { value: any; n: number }): Expr; + /** + * Extend the Series with given number of values. + * @param value The value to extend the Series with. This value may be null to fill with nulls. + * @param n The number of values to extend. + */ + extendConstant(value: any, n: number): Expr; + extendConstant(opt: { value: any; n: number }): Expr; + /** Fill nan value with a fill value */ + fillNan(other: any): Expr; + /** Fill null value with a fill value or strategy */ + fillNull(other: any | FillNullStrategy): Expr; + /** + * Filter a single column. + * + * Mostly useful in in aggregation context. + * If you want to filter on a DataFrame level, use `LazyFrame.filter`. + * @param predicate Boolean expression. + */ + filter(predicate: Expr): Expr; + /** Get the first value. */ + first(): Expr; + /** @see {@link Expr.explode} */ + flatten(): Expr; + /** Fill missing values with the latest seen values */ + forwardFill(): Expr; + /** Hash the Series. */ + hash(k0?: number, k1?: number, k2?: number, k3?: number): Expr; + hash({ + k0, + k1, + k2, + k3, + }: { k0?: number; k1?: number; k2?: number; k3?: number }): Expr; + /** Take the first n values. */ + head(length?: number): Expr; + head({ length }: { length: number }): Expr; + inner(): any; + /** Interpolate intermediate values. The interpolation method is linear. */ + interpolate(): Expr; + /** Get mask of duplicated values. */ + isDuplicated(): Expr; + /** Create a boolean expression returning `true` where the expression values are finite. */ + isFinite(): Expr; + /** Get a mask of the first unique value. */ + isFirst(): Expr; + /** + * Check if elements of this Series are in the right Series, or List values of the right Series. + * + * @param other Series of primitive type or List type. + * @returns Expr that evaluates to a Boolean Series. + * @example + * ``` + * > df = pl.DataFrame({ + * ... "sets": [[1, 2, 3], [1, 2], [9, 10]], + * ... "optional_members": [1, 2, 3] + * ... }) + * > df.select( + * ... pl.col("optional_members").isIn("sets").alias("contains") + * ... ) + * shape: (3, 1) + * ┌──────────┐ + * │ contains │ + * │ --- │ + * │ bool │ + * ╞══════════╡ + * │ true │ + * ├╌╌╌╌╌╌╌╌╌╌┤ + * │ true │ + * ├╌╌╌╌╌╌╌╌╌╌┤ + * │ false │ + * └──────────┘ + * ``` + */ + isIn(other): Expr; + /** Create a boolean expression returning `true` where the expression values are infinite. */ + isInfinite(): Expr; + /** Create a boolean expression returning `true` where the expression values are NaN (Not A Number). */ + isNan(): Expr; + /** Create a boolean expression returning `true` where the expression values are not NaN (Not A Number). */ + isNotNan(): Expr; + /** Create a boolean expression returning `true` where the expression does not contain null values. */ + isNotNull(): Expr; + /** Create a boolean expression returning `True` where the expression contains null values. */ + isNull(): Expr; + /** Get mask of unique values. */ + isUnique(): Expr; + /** + * Keep the original root name of the expression. + * + * A groupby aggregation often changes the name of a column. + * With `keepName` we can keep the original name of the column + * @example + * ``` + * > df = pl.DataFrame({ + * ... "a": [1, 2, 3], + * ... "b": ["a", "b", None], + * ... }) + * + * > df + * ... .groupBy("a") + * ... .agg(pl.col("b").list()) + * ... .sort({by:"a"}) + * + * shape: (3, 2) + * ╭─────┬────────────╮ + * │ a ┆ b_agg_list │ + * │ --- ┆ --- │ + * │ i64 ┆ list [str] │ + * ╞═════╪════════════╡ + * │ 1 ┆ [a] │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ [b] │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ [null] │ + * ╰─────┴────────────╯ + * + * Keep the original column name: + * + * > df + * ... .groupby("a") + * ... .agg(col("b").list().keepName()) + * ... .sort({by:"a"}) + * + * shape: (3, 2) + * ╭─────┬────────────╮ + * │ a ┆ b │ + * │ --- ┆ --- │ + * │ i64 ┆ list [str] │ + * ╞═════╪════════════╡ + * │ 1 ┆ [a] │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ [b] │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ [null] │ + * ╰─────┴────────────╯ + * ``` + */ + keepName(): Expr; + kurtosis(): Expr; + kurtosis(fisher: boolean, bias?: boolean): Expr; + kurtosis({ fisher, bias }: { fisher?: boolean; bias?: boolean }): Expr; + /** Get the last value. */ + last(): Expr; + /** Aggregate to list. */ + list(): Expr; + /** Returns a unit Series with the lowest value possible for the dtype of this expression. */ + lowerBound(): Expr; + /** Compute the max value of the arrays in the list */ + max(): Expr; + /** Compute the mean value of the arrays in the list */ + mean(): Expr; + /** Get median value. */ + median(): Expr; + /** Get minimum value. */ + min(): Expr; + /** Compute the most occurring value(s). Can return multiple Values */ + mode(): Expr; + /** Negate a boolean expression. */ + not(): Expr; + /** Count unique values. */ + nUnique(): Expr; + or(other: any): Expr; + /** + * Apply window function over a subgroup. + * + * This is similar to a groupby + aggregation + self join. + * Or similar to [window functions in Postgres](https://www.postgresql.org/docs/9.1/tutorial-window.html) + * @param partitionBy Column(s) to partition by. + * + * @example + * ``` + * > df = pl.DataFrame({ + * ... "groups": [1, 1, 2, 2, 1, 2, 3, 3, 1], + * ... "values": [1, 2, 3, 4, 5, 6, 7, 8, 8], + * ... }) + * > df.select( + * ... pl.col("groups").sum().over("groups") + * ... ) + * ╭────────┬────────╮ + * │ groups ┆ values │ + * │ --- ┆ --- │ + * │ i32 ┆ i32 │ + * ╞════════╪════════╡ + * │ 1 ┆ 16 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 1 ┆ 16 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ 13 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ 13 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ ... ┆ ... │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 1 ┆ 16 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ 13 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ 15 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ 15 │ + * ├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 1 ┆ 16 │ + * ╰────────┴────────╯ + * ``` + */ + over(by: ExprOrString, ...partitionBy: ExprOrString[]): Expr; + /** Raise expression to the power of exponent. */ + pow(exponent: number): Expr; + pow({ exponent }: { exponent: number }): Expr; + /** + * Add a prefix the to root column name of the expression. + * @example + * ``` + * > df = pl.DataFrame({ + * ... "A": [1, 2, 3, 4, 5], + * ... "fruits": ["banana", "banana", "apple", "apple", "banana"], + * ... "B": [5, 4, 3, 2, 1], + * ... "cars": ["beetle", "audi", "beetle", "beetle", "beetle"], + * ... }) + * shape: (5, 4) + * ╭─────┬──────────┬─────┬──────────╮ + * │ A ┆ fruits ┆ B ┆ cars │ + * │ --- ┆ --- ┆ --- ┆ --- │ + * │ i64 ┆ str ┆ i64 ┆ str │ + * ╞═════╪══════════╪═════╪══════════╡ + * │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ "banana" ┆ 4 ┆ "audi" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ + * │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤ + * │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │ + * ╰─────┴──────────┴─────┴──────────╯ + * > df.select( + * ... pl.all().reverse().prefix("reverse_"), + * ... ) + * shape: (5, 8) + * ╭───────────┬────────────────┬───────────┬──────────────╮ + * │ reverse_A ┆ reverse_fruits ┆ reverse_B ┆ reverse_cars │ + * │ --- ┆ --- ┆ --- ┆ --- │ + * │ i64 ┆ str ┆ i64 ┆ str │ + * ╞═══════════╪════════════════╪═══════════╪══════════════╡ + * │ 5 ┆ "banana" ┆ 1 ┆ "beetle" │ + * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 4 ┆ "apple" ┆ 2 ┆ "beetle" │ + * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ "apple" ┆ 3 ┆ "beetle" │ + * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 2 ┆ "banana" ┆ 4 ┆ "audi" │ + * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 1 ┆ "banana" ┆ 5 ┆ "beetle" │ + * ╰───────────┴────────────────┴───────────┴──────────────╯ + * ``` + */ + prefix(prefix: string): Expr; + /** Get quantile value. */ + quantile(quantile: number | Expr): Expr; + /** Assign ranks to data, dealing with ties appropriately. */ + rank(method?: RankMethod): Expr; + rank({ method }: { method: string }): Expr; + reinterpret(signed?: boolean): Expr; + reinterpret({ signed }: { signed: boolean }): Expr; + /** + * Repeat the elements in this Series `n` times by dictated by the number given by `by`. + * The elements are expanded into a `List` + * @param by Numeric column that determines how often the values will be repeated. + * + * The column will be coerced to UInt32. Give this dtype to make the coercion a no-op. + */ + repeatBy(by: Expr | string): Expr; + /** Reverse the arrays in the list */ + reverse(): Expr; + /** + * Shift the values by a given period and fill the parts that will be empty due to this operation + * @param periods number of places to shift (may be negative). + */ + shift(periods?: number): Expr; + shift({ periods }: { periods: number }): Expr; + /** + * Shift the values by a given period and fill the parts that will be empty due to this operation + * @param periods Number of places to shift (may be negative). + * @param fillValue Fill null values with the result of this expression. + */ + shiftAndFill(periods: number, fillValue: Expr): Expr; + shiftAndFill({ + periods, + fillValue, + }: { periods: number; fillValue: Expr }): Expr; + /** + * Compute the sample skewness of a data set. + * For normally distributed data, the skewness should be about zero. For + * unimodal continuous distributions, a skewness value greater than zero means + * that there is more weight in the right tail of the distribution. + * ___ + * @param bias If False, then the calculations are corrected for statistical bias. + */ + skew(bias?: boolean): Expr; + skew({ bias }: { bias: boolean }): Expr; + /** Slice the Series. */ + slice(offset: number | Expr, length: number | Expr): Expr; + slice({ + offset, + length, + }: { offset: number | Expr; length: number | Expr }): Expr; + /** + * Sort this column. In projection/ selection context the whole column is sorted. + * @param reverse + * * false -> order from small to large. + * * true -> order from large to small. + * @param nullsLast If true nulls are considered to be larger than any valid value + */ + sort(reverse?: boolean, nullsLast?: boolean): Expr; + sort({ + reverse, + nullsLast, + }: { reverse?: boolean; nullsLast?: boolean }): Expr; + /** + * Sort this column by the ordering of another column, or multiple other columns. + In projection/ selection context the whole column is sorted. + If used in a groupby context, the groups are sorted. - export import DateTimeFunctions = dt.ExprDateTimeFunctions; - export import ListFunctions = lst.ExprListFunctions; - export import StringFunctions = str.ExprStringFunctions; - export import StructFunctions = struct.ExprStructFunctions; + Parameters + ---------- + @param by + The column(s) used for sorting. + @param reverse + false -> order from small to large. + true -> order from large to small. + */ + sortBy( + by: ExprOrString[] | ExprOrString, + reverse?: boolean | boolean[], + ): Expr; + sortBy(options: { + by: ExprOrString[] | ExprOrString; + reverse?: boolean | boolean[]; + }): Expr; + /** Get standard deviation. */ + std(): Expr; + /** Add a suffix the to root column name of the expression. */ + suffix(suffix: string): Expr; + /** + * Get sum value. + * @note + * Dtypes in {Int8, UInt8, Int16, UInt16} are cast to Int64 before summing to prevent overflow issues. + */ + sum(): Expr; + /** Take the last n values. */ + tail(length?: number): Expr; + tail({ length }: { length: number }): Expr; + /** + * Take values by index. + * @param index An expression that leads to a UInt32 dtyped Series. + */ + take(index: Expr | number[] | Series): Expr; + take({ index }: { index: Expr | number[] | Series }): Expr; + /** Take every nth value in the Series and return as a new Series. */ + takeEvery(n: number): Expr; + /** + * Get the unique values of this expression; + * @param maintainOrder Maintain order of data. This requires more work. + */ + unique(maintainOrder?: boolean | { maintainOrder: boolean }): Expr; + /** Returns a unit Series with the highest value possible for the dtype of this expression. */ + upperBound(): Expr; + /** Get variance. */ + var(): Expr; + /** Alias for filter: @see {@link filter} */ + where(predicate: Expr): Expr; +} + +/** @ignore */ +export const _Expr = (_expr: any): Expr => { + const unwrap = (method: string, ...args: any[]) => { + return _expr[method as any](...args); + }; + const wrap = (method, ...args): Expr => { + return _Expr(unwrap(method, ...args)); + }; + + const wrapExprArg = (method: string, lit = false) => (other: any) => { + const expr = exprToLitOrExpr(other, lit).inner(); + + return wrap(method, expr); + }; + + const rolling = + (method: string) => (opts, weights?, minPeriods?, center?): Expr => { + const windowSize = + opts?.["windowSize"] ?? (typeof opts === "number" ? opts : null); + if (windowSize === null) { + throw new Error("window size is required"); + } + const callOpts = { + windowSize: `${windowSize}i`, + weights: opts?.["weights"] ?? weights, + minPeriods: opts?.["minPeriods"] ?? minPeriods ?? windowSize, + center: opts?.["center"] ?? center ?? false, + }; + + return wrap(method, callOpts); + }; + + return { + _expr, + [Symbol.toStringTag]() { + return "Expr"; + }, + [INSPECT_SYMBOL]() { + return _expr.toString(); + }, + serialize(format): any { + return _expr.serialize(format); + }, + toString() { + return _expr.toString(); + }, + toJSON(...args: any[]) { + // this is passed by `JSON.stringify` when calling `toJSON()` + if (args[0] === "") { + return _expr.toJs(); + } + + return _expr.serialize("json").toString(); + }, + get str() { + return str.ExprStringFunctions(_expr); + }, + get lst() { + return lst.ExprListFunctions(_expr); + }, + get date() { + return dt.ExprDateTimeFunctions(_expr); + }, + get struct() { + return struct.ExprStructFunctions(_expr); + }, + abs() { + return _Expr(_expr.abs()); + }, + aggGroups() { + return _Expr(_expr.aggGroups()); + }, + alias(name) { + return _Expr(_expr.alias(name)); + }, + inner() { + return _expr; + }, + and(other) { + const expr = (exprToLitOrExpr(other, false) as any).inner(); + + return _Expr(_expr.and(expr)); + }, + argMax() { + return _Expr(_expr.argMax()); + }, + argMin() { + return _Expr(_expr.argMin()); + }, + argSort(reverse: any = false) { + reverse = reverse?.reverse ?? reverse; + + return _Expr(_expr.argSort(reverse)); + }, + argUnique() { + return _Expr(_expr.argUnique()); + }, + as(name) { + return _Expr(_expr.alias(name)); + }, + backwardFill() { + return _Expr(_expr.backwardFill()); + }, + cast(dtype, strict = false) { + return _Expr(_expr.cast(dtype, strict)); + }, + ceil() { + return _Expr(_expr.ceil()); + }, + clip(arg, max?) { + if (typeof arg === "number") { + return _Expr(_expr.clip(arg, max)); + } else { + return _Expr(_expr.clip(arg.min, arg.max)); + } + }, + count() { + return _Expr(_expr.count()); + }, + cumCount(reverse: any = false) { + reverse = reverse?.reverse ?? reverse; + + return _Expr(_expr.cumcount(reverse?.reverse ?? reverse)); + }, + cumMax(reverse: any = false) { + reverse = reverse?.reverse ?? reverse; + + return _Expr(_expr.cummax(reverse)); + }, + cumMin(reverse: any = false) { + reverse = reverse?.reverse ?? reverse; + + return _Expr(_expr.cummin(reverse)); + }, + cumProd(reverse: any = false) { + reverse = reverse?.reverse ?? reverse; + + return _Expr(_expr.cumprod(reverse)); + }, + cumSum(reverse: any = false) { + reverse = reverse?.reverse ?? reverse; + + return _Expr(_expr.cumsum(reverse)); + }, + diff(n, nullBehavior = "ignore") { + if (typeof n === "number") { + return _Expr(_expr.diff(n, nullBehavior)); + } else { + return _Expr(_expr.diff(n.n, n.nullBehavior)); + } + }, + dot(other) { + const expr = (exprToLitOrExpr(other, false) as any).inner(); + + return _Expr(_expr.dot(expr)); + }, + exclude(...columns) { + return _Expr(_expr.exclude(columns.flat(2))); + }, + explode() { + return _Expr(_expr.explode()); + }, + extend(o, n?) { + if (n !== null && typeof n === "number") { + return _Expr(_expr.extendConstant(o, n)); + } + + return _Expr(_expr.extendConstant(o.value, o.n)); + }, + extendConstant(o, n?) { + if (n !== null && typeof n === "number") { + return _Expr(_expr.extendConstant(o, n)); + } + + return _Expr(_expr.extendConstant(o.value, o.n)); + }, + fillNan(other) { + const expr = (exprToLitOrExpr(other, true) as any).inner(); + + return _Expr(_expr.fillNan(expr)); + }, + fillNull(fillValue) { + if ( + ["backward", "forward", "mean", "min", "max", "zero", "one"].includes( + fillValue, + ) + ) { + return _Expr(_expr.fillNullWithStrategy(fillValue)); + } + + const expr = exprToLitOrExpr(fillValue).inner(); + + return _Expr(_expr.fillNull(expr)); + }, + filter(predicate) { + const expr = exprToLitOrExpr(predicate).inner(); + + return _Expr(_expr.filter(expr)); + }, + first() { + return _Expr(_expr.first()); + }, + flatten() { + return _Expr(_expr.explode()); + }, + floor() { + return _Expr(_expr.floor()); + }, + forwardFill() { + return _Expr(_expr.forwardFill()); + }, + hash(obj: any = 0, k1 = 1, k2 = 2, k3 = 3) { + if (typeof obj === "number" || typeof obj === "bigint") { + return wrap("hash", BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3)); + } + const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj }; + + return wrap( + "hash", + BigInt(o.k0), + BigInt(o.k1), + BigInt(o.k2), + BigInt(o.k3), + ); + }, + head(length) { + if (typeof length === "number") { + return wrap("head", length); + } + return wrap("head", length.length); + }, + interpolate(method: InterpolationMethod = "linear") { + return _Expr(_expr.interpolate(method)); + }, + isDuplicated() { + return _Expr(_expr.isDuplicated()); + }, + isFinite() { + return _Expr(_expr.isFinite()); + }, + isInfinite() { + return _Expr(_expr.isInfinite()); + }, + isFirst() { + return _Expr(_expr.isFirst()); + }, + isNan() { + return _Expr(_expr.isNan()); + }, + isNotNan() { + return _Expr(_expr.isNotNan()); + }, + isNotNull() { + return _Expr(_expr.isNotNull()); + }, + isNull() { + return _Expr(_expr.isNull()); + }, + isUnique() { + return _Expr(_expr.isUnique()); + }, + isIn(other) { + if (Array.isArray(other)) { + other = pli.lit(Series(other).inner()); + } else { + other = exprToLitOrExpr(other, false).inner(); + } - export import List = lst.ExprList - export import Datetime = dt.ExprDateTime - export import String = str.ExprString - export import Struct = struct.ExprStruct + return wrap("isIn", other); + }, + keepName() { + return _Expr(_expr.keepName()); + }, + kurtosis(obj?, bias = true) { + const fisher = obj?.["fisher"] ?? (typeof obj === "boolean" ? obj : true); + bias = obj?.["bias"] ?? bias; + + return _Expr(_expr.kurtosis(fisher, bias)); + }, + last() { + return _Expr(_expr.last()); + }, + list() { + return _Expr(_expr.list()); + }, + lowerBound() { + return _Expr(_expr.lowerBound()); + }, + max() { + return _Expr(_expr.max()); + }, + mean() { + return _Expr(_expr.mean()); + }, + median() { + return _Expr(_expr.median()); + }, + min() { + return _Expr(_expr.min()); + }, + mode() { + return _Expr(_expr.mode()); + }, + not() { + return _Expr(_expr.not()); + }, + nUnique() { + return _Expr(_expr.nUnique()); + }, + or(other) { + const expr = exprToLitOrExpr(other).inner(); + + return _Expr(_expr.or(expr)); + }, + over(...exprs) { + const partitionBy = selectionToExprList(exprs, false); + + return wrap("over", partitionBy); + }, + pow(exponent) { + return _Expr(_expr.pow(exponent?.exponent ?? exponent)); + }, + prefix(prefix) { + return _Expr(_expr.prefix(prefix)); + }, + quantile(quantile, interpolation: InterpolationMethod = "nearest") { + if (Expr.isExpr(quantile)) { + quantile = quantile._expr; + } else { + quantile = pli.lit(quantile); + } + + return _Expr(_expr.quantile(quantile, interpolation)); + }, + rank(method: any = "average", reverse = false) { + return _Expr( + _expr.rank(method?.method ?? method, method?.reverse ?? reverse), + ); + }, + reinterpret(signed: any = true) { + signed = signed?.signed ?? signed; + + return _Expr(_expr.reinterpret(signed)); + }, + repeatBy(expr) { + const e = exprToLitOrExpr(expr, false)._expr; + + return _Expr(_expr.repeatBy(e)); + }, + reverse() { + return _Expr(_expr.reverse()); + }, + rollingMax: rolling("rollingMax"), + rollingMean: rolling("rollingMean"), + rollingMin: rolling("rollingMin"), + rollingSum: rolling("rollingSum"), + rollingStd: rolling("rollingStd"), + rollingVar: rolling("rollingVar"), + rollingMedian: rolling("rollingMedian"), + rollingQuantile( + val, + interpolation?, + windowSize?, + weights?, + minPeriods?, + center?, + ) { + if (typeof val === "number") { + return wrap("rollingQuantile", val, interpolation ?? "nearest", { + windowSize: `${windowSize}i`, + weights, + minPeriods, + center, + }); + } + windowSize = + val?.["windowSize"] ?? (typeof val === "number" ? val : null); + if (windowSize === null) { + throw new Error("window size is required"); + } + const options = { + windowSize: `${windowSize}i`, + weights: val?.["weights"] ?? weights, + minPeriods: val?.["minPeriods"] ?? minPeriods ?? windowSize, + center: val?.["center"] ?? center ?? false, + }; + + return wrap( + "rollingQuantile", + val.quantile, + val.interpolation ?? "nearest", + options, + ); + }, + rollingSkew(val, bias = true) { + if (typeof val === "number") { + return wrap("rollingSkew", val, bias); + } + + return wrap("rollingSkew", val.windowSize, val.bias ?? bias); + }, + round(decimals) { + return _Expr(_expr.round(decimals?.decimals ?? decimals)); + }, + sample(opts?, frac?, withReplacement = false, seed?) { + if (opts?.n !== undefined || opts?.frac !== undefined) { + return (this as any).sample( + opts.n, + opts.frac, + opts.withReplacement, + seed, + ); + } + if (typeof opts === "number") { + throw new Error("sample_n is not yet supported for expr"); + } + if (typeof frac === "number") { + return wrap("sampleFrac", frac, withReplacement, false, seed); + } else { + throw new TypeError("must specify either 'frac' or 'n'"); + } + }, + shift(periods) { + return _Expr(_expr.shift(periods)); + }, + shiftAndFill(optOrPeriods, fillValue?) { + if (typeof optOrPeriods === "number") { + fillValue = exprToLitOrExpr(fillValue).inner(); + + return wrap("shiftAndFill", optOrPeriods, fillValue); + } else { + fillValue = exprToLitOrExpr(optOrPeriods.fillValue).inner(); + const periods = optOrPeriods.periods; + + return wrap("shiftAndFill", periods, fillValue); + } + }, + skew(bias) { + return wrap("skew", bias?.bias ?? bias ?? true); + }, + slice(arg, len?) { + if (typeof arg === "number") { + return wrap("slice", pli.lit(arg), pli.lit(len)); + } + + return wrap("slice", pli.lit(arg.offset), pli.lit(arg.length)); + }, + sort(reverse: any = false, nullsLast = false) { + if (typeof reverse === "boolean") { + return wrap("sortWith", reverse, nullsLast); + } + + return wrap( + "sortWith", + reverse?.reverse ?? false, + reverse?.nullsLast ?? nullsLast, + ); + }, + sortBy(arg, reverse = false) { + if (arg?.by !== undefined) { + return this.sortBy(arg.by, arg.reverse); + } + + reverse = Array.isArray(reverse) ? reverse.flat() : ([reverse] as any); + const by = selectionToExprList(arg, false); + + return wrap("sortBy", by, reverse); + }, + std() { + return _Expr(_expr.std()); + }, + suffix(suffix) { + return _Expr(_expr.suffix(suffix)); + }, + sum() { + return _Expr(_expr.sum()); + }, + tail(length) { + return _Expr(_expr.tail(length)); + }, + + take(indices) { + if (Array.isArray(indices)) { + indices = pli.lit(Series(indices).inner()); + } else { + indices = indices.inner(); + } + + return wrap("take", indices); + }, + takeEvery(n) { + return _Expr(_expr.takeEvery(n)); + }, + unique(opt?) { + if (opt) { + return wrap("unique_stable"); + } + + return wrap("unique"); + }, + upperBound() { + return _Expr(_expr.upperBound()); + }, + where(expr) { + return this.filter(expr); + }, + var() { + return _Expr(_expr.var()); + }, + add: wrapExprArg("add"), + sub: wrapExprArg("sub"), + div: wrapExprArg("div"), + mul: wrapExprArg("mul"), + rem: wrapExprArg("rem"), + + plus: wrapExprArg("add"), + minus: wrapExprArg("sub"), + divideBy: wrapExprArg("div"), + multiplyBy: wrapExprArg("mul"), + modulo: wrapExprArg("rem"), + + eq: wrapExprArg("eq"), + equals: wrapExprArg("eq"), + gtEq: wrapExprArg("gtEq"), + greaterThanEquals: wrapExprArg("gtEq"), + gt: wrapExprArg("gt"), + greaterThan: wrapExprArg("gt"), + ltEq: wrapExprArg("ltEq"), + lessThanEquals: wrapExprArg("ltEq"), + lt: wrapExprArg("lt"), + lessThan: wrapExprArg("lt"), + neq: wrapExprArg("neq"), + notEquals: wrapExprArg("neq"), + } as Expr; +}; + +export interface ExprConstructor extends Deserialize { + isExpr(arg: any): arg is Expr; } -export = expr +const isExpr = (anyVal: any): anyVal is Expr => { + try { + return anyVal?.[Symbol.toStringTag]?.() === "Expr"; + } catch (err) { + return false; + } +}; + +const deserialize = (buf, format) => { + return _Expr(pli.JsExpr.deserialize(buf, format)); +}; + +export const Expr: ExprConstructor = Object.assign(_Expr, { + isExpr, + deserialize, +}); + +/** @ignore */ +export const exprToLitOrExpr = (expr: any, stringToLit = true): Expr => { + if (typeof expr === "string" && !stringToLit) { + return _Expr(pli.col(expr)); + } else if (Expr.isExpr(expr)) { + return expr; + } else if (Series.isSeries(expr)) { + return _Expr(pli.lit((expr as any)._s)); + } else { + return _Expr(pli.lit(expr)); + } +}; diff --git a/polars/lazy/expr/list.ts b/polars/lazy/expr/list.ts index 75d941dbd..b594f1a89 100644 --- a/polars/lazy/expr/list.ts +++ b/polars/lazy/expr/list.ts @@ -1,13 +1,13 @@ import { Expr, _Expr } from "../expr"; import { ListFunctions } from "../../shared_traits"; -import { Series } from "../../series/series"; +import { Series } from "../../series"; import pli from "../../internals/polars_internal"; -import { concatList, lit } from "../functions"; +import { concatList } from "../functions"; /** * namespace containing expr list functions */ -export type ExprList = ListFunctions; +export interface ExprList extends ListFunctions {} export const ExprListFunctions = (_expr: any): ExprList => { const wrap = (method, ...args: any[]): Expr => { return _Expr(_expr[method](...args)); diff --git a/polars/lazy/expr/string.ts b/polars/lazy/expr/string.ts index 906dc8624..59d9448b2 100644 --- a/polars/lazy/expr/string.ts +++ b/polars/lazy/expr/string.ts @@ -1,11 +1,12 @@ -import {DataType} from "../../datatypes"; +import { StringFunctions } from "../../shared_traits"; +import { DataType } from "../../datatypes"; import { regexToString } from "../../utils"; -import {Expr, _Expr} from "../expr"; +import { Expr, _Expr } from "../expr"; /** * namespace containing expr string functions */ -export interface ExprString { +export interface StringNamespace extends StringFunctions { /** * Vertically concat the values in the Series to a single string value. * @example @@ -272,19 +273,19 @@ export interface ExprString { strptime(datatype: DataType.Datetime, fmt?: string): Expr; } -export const ExprStringFunctions = (_expr: any): ExprString => { +export const ExprStringFunctions = (_expr: any): StringNamespace => { const wrap = (method, ...args: any[]): Expr => { return _Expr(_expr[method](...args)); }; const handleDecode = (encoding, strict) => { switch (encoding) { - case "hex": - return wrap(`strHexDecode`, strict); - case "base64": - return wrap(`strBase64Decode`, strict); - default: - throw new RangeError("supported encodings are 'hex' and 'base64'"); + case "hex": + return wrap("strHexDecode", strict); + case "base64": + return wrap("strBase64Decode", strict); + default: + throw new RangeError("supported encodings are 'hex' and 'base64'"); } }; @@ -295,8 +296,8 @@ export const ExprStringFunctions = (_expr: any): ExprString => { contains(pat: string | RegExp) { return wrap("strContains", regexToString(pat)); }, - decode(arg, strict=false) { - if(typeof arg === "string") { + decode(arg, strict = false) { + if (typeof arg === "string") { return handleDecode(arg, strict); } @@ -304,12 +305,12 @@ export const ExprStringFunctions = (_expr: any): ExprString => { }, encode(encoding) { switch (encoding) { - case "hex": - return wrap(`strHexEncode`); - case "base64": - return wrap(`strBase64Encode`); - default: - throw new RangeError("supported encodings are 'hex' and 'base64'"); + case "hex": + return wrap("strHexEncode"); + case "base64": + return wrap("strBase64Encode"); + default: + throw new RangeError("supported encodings are 'hex' and 'base64'"); } }, extract(pat: string | RegExp, groupIndex: number) { @@ -333,7 +334,7 @@ export const ExprStringFunctions = (_expr: any): ExprString => { rstrip() { return wrap("strRstrip"); }, - padStart(length: number, fillChar: string){ + padStart(length: number, fillChar: string) { return wrap("strPadStart", length, fillChar); }, zFill(length: number) { @@ -346,7 +347,8 @@ export const ExprStringFunctions = (_expr: any): ExprString => { return wrap("strSlice", start, length); }, split(by: string, options?) { - const inclusive = typeof options === "boolean" ? options : options?.inclusive; + const inclusive = + typeof options === "boolean" ? options : options?.inclusive; return wrap("strSplit", by, inclusive); }, @@ -359,7 +361,9 @@ export const ExprStringFunctions = (_expr: any): ExprString => { } else if (dtype.equals(DataType.Datetime("ms"))) { return wrap("strParseDatetime", fmt, false, false); } else { - throw new Error(`only "DataType.Date" and "DataType.Datetime" are supported`); + throw new Error( + `only "DataType.Date" and "DataType.Datetime" are supported`, + ); } }, toLowerCase() { diff --git a/polars/lazy/expr/struct.ts b/polars/lazy/expr/struct.ts index 52f8f2871..ff8603888 100644 --- a/polars/lazy/expr/struct.ts +++ b/polars/lazy/expr/struct.ts @@ -1,12 +1,21 @@ -import pli from "../../internals/polars_internal"; -import {_Expr, Expr} from "../expr"; +import { _Expr, Expr } from "../expr"; +/** + * Struct functions + */ export interface ExprStruct { + /** + * Access a field by name + * @param name - name of the field + */ field(name: string): Expr; - renameFields(names: string[]): Expr + /** + * Rename the fields of a struct + * @param names - new names of the fields + */ + renameFields(names: string[]): Expr; } - export const ExprStructFunctions = (_expr: any): ExprStruct => { return { field(name) { @@ -14,6 +23,6 @@ export const ExprStructFunctions = (_expr: any): ExprStruct => { }, renameFields(names) { return _Expr(_expr.structRenameFields(names)); - } + }, }; }; diff --git a/polars/lazy/functions.ts b/polars/lazy/functions.ts index b0a8df80a..b7d6f8bdc 100644 --- a/polars/lazy/functions.ts +++ b/polars/lazy/functions.ts @@ -1,7 +1,7 @@ -import {Expr, _Expr, exprToLitOrExpr} from "./expr"; -import {Series} from "../series/series"; -import {DataFrame} from "../dataframe"; -import {ExprOrString, range, selectionToExprList} from "../utils"; +import { Expr, _Expr, exprToLitOrExpr } from "./expr"; +import { Series } from "../series"; +import { DataFrame } from "../dataframe"; +import { ExprOrString, range, selectionToExprList } from "../utils"; import pli from "../internals/polars_internal"; /** @@ -13,11 +13,11 @@ import pli from "../internals/polars_internal"; * @param col * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "ham": [1, 2, 3], - * >>> "hamburger": [11, 22, 33], - * >>> "foo": [3, 2, 1]}) - * >>> df.select(col("foo")) + * > df = pl.DataFrame({ + * > "ham": [1, 2, 3], + * > "hamburger": [11, 22, 33], + * > "foo": [3, 2, 1]}) + * > df.select(col("foo")) * shape: (3, 1) * ╭─────╮ * │ foo │ @@ -30,7 +30,7 @@ import pli from "../internals/polars_internal"; * ├╌╌╌╌╌┤ * │ 1 │ * ╰─────╯ - * >>> df.select(col("*")) + * > df.select(col("*")) * shape: (3, 3) * ╭─────┬───────────┬─────╮ * │ ham ┆ hamburger ┆ foo │ @@ -43,7 +43,7 @@ import pli from "../internals/polars_internal"; * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤ * │ 3 ┆ 33 ┆ 1 │ * ╰─────┴───────────┴─────╯ - * >>> df.select(col("^ham.*$")) + * > df.select(col("^ham.*$")) * shape: (3, 2) * ╭─────┬───────────╮ * │ ham ┆ hamburger │ @@ -56,7 +56,7 @@ import pli from "../internals/polars_internal"; * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤ * │ 3 ┆ 33 │ * ╰─────┴───────────╯ - * >>> df.select(col("*").exclude("ham")) + * > df.select(col("*").exclude("ham")) * shape: (3, 2) * ╭───────────┬─────╮ * │ hamburger ┆ foo │ @@ -69,7 +69,7 @@ import pli from "../internals/polars_internal"; * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤ * │ 33 ┆ 1 │ * ╰───────────┴─────╯ - * >>> df.select(col(["hamburger", "foo"]) + * > df.select(col(["hamburger", "foo"]) * shape: (3, 2) * ╭───────────┬─────╮ * │ hamburger ┆ foo │ @@ -82,7 +82,7 @@ import pli from "../internals/polars_internal"; * ├╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤ * │ 33 ┆ 1 │ * ╰───────────┴─────╯ - * >>> df.select(col(pl.Series(["hamburger", "foo"])) + * > df.select(col(pl.Series(["hamburger", "foo"])) * shape: (3, 2) * ╭───────────┬─────╮ * │ hamburger ┆ foo │ @@ -108,10 +108,9 @@ export function col(col: string | string[] | Series): Expr { } } -export function cols(col: string | string[]): Expr -export function cols(col: string, ...cols: string[]): Expr +export function cols(col: string | string[]): Expr; +export function cols(col: string, ...cols: string[]): Expr; export function cols(...cols): Expr { - return col(cols.flat()); } @@ -120,7 +119,6 @@ export function lit(value: any): Expr { value = Series(value); } if (Series.isSeries(value)) { - return _Expr(pli.lit(value.inner())); } @@ -143,14 +141,29 @@ export function lit(value: any): Expr { * @param eager - If eager evaluation is `true`, a Series is returned instead of an Expr * @example * ``` - * >>> df.lazy() - * >>> .filter(pl.col("foo").lt(pl.arange(0, 100))) - * >>> .collect() + * > df.lazy() + * > .filter(pl.col("foo").lt(pl.arange(0, 100))) + * > .collect() * ``` */ -export function arange(opts: {low: any, high: any, step: number, eager: boolean}); -export function arange(low: any, high?: any, step?: number, eager?: true): Series; -export function arange(low: any, high?: any, step?: number, eager?: false): Expr; +export function arange(opts: { + low: any; + high: any; + step: number; + eager: boolean; +}); +export function arange( + low: any, + high?: any, + step?: number, + eager?: true, +): Series; +export function arange( + low: any, + high?: any, + step?: number, + eager?: false, +): Expr; export function arange(opts: any, high?, step?, eager?): Series | Expr { if (typeof opts?.low === "number") { return arange(opts.low, opts.high, opts.step, opts.eager); @@ -158,9 +171,11 @@ export function arange(opts: any, high?, step?, eager?): Series | Expr { const low = exprToLitOrExpr(opts, false); high = exprToLitOrExpr(high, false); if (eager) { - const df = DataFrame({"a": [1]}); + const df = DataFrame({ a: [1] }); - return df.select(arange(low, high, step).alias("arange") as any).getColumn("arange") as any; + return df + .select(arange(low, high, step).alias("arange") as any) + .getColumn("arange") as any; } return _Expr(pli.arange(low, high, step)); @@ -177,9 +192,12 @@ export function all(): Expr { * If there are duplicates in the first column, the second column will be used to determine the ordering * and so on. */ -export function argSortBy(exprs: Expr[] | string[], reverse: boolean | boolean[] = false): Expr { +export function argSortBy( + exprs: Expr[] | string[], + reverse: boolean | boolean[] = false, +): Expr { if (!Array.isArray(reverse)) { - reverse = Array.from({length: exprs.length}, () => reverse) as any; + reverse = Array.from({ length: exprs.length }, () => reverse) as any; } const by = selectionToExprList(exprs); @@ -196,9 +214,13 @@ export function avg(column: Series | string): number | Expr { * Concat the arrays in a Series dtype List in linear time. * @param exprs Columns to concat into a List Series */ -export function concatList(exprs: ExprOrString[]): Expr -export function concatList(expr: ExprOrString, ...exprs: ExprOrString[]): Expr -export function concatList(expr: ExprOrString, expr2: ExprOrString, ...exprs: ExprOrString[]): Expr +export function concatList(exprs: ExprOrString[]): Expr; +export function concatList(expr: ExprOrString, ...exprs: ExprOrString[]): Expr; +export function concatList( + expr: ExprOrString, + expr2: ExprOrString, + ...exprs: ExprOrString[] +): Expr; export function concatList(...exprs): Expr { const items = selectionToExprList(exprs as any, false); @@ -206,7 +228,7 @@ export function concatList(...exprs): Expr { } /** Concat Utf8 Series in linear time. Non utf8 columns are cast to utf8. */ -export function concatString(opts: {exprs: ExprOrString[], sep: string}); +export function concatString(opts: { exprs: ExprOrString[]; sep: string }); export function concatString(exprs: ExprOrString[], sep?: string); export function concatString(opts, sep = ",") { if (opts?.exprs) { @@ -215,12 +237,11 @@ export function concatString(opts, sep = ",") { const items = selectionToExprList(opts as any, false); return (Expr as any)(pli.concatStr(items, sep)); - } /** Count the number of values in this column. */ -export function count(column: string): Expr -export function count(column: Series): number +export function count(column: string): Expr; +export function count(column: Series): number; export function count(column) { if (Series.isSeries(column)) { return column.len(); @@ -241,28 +262,30 @@ export function cov(a: ExprOrString, b: ExprOrString): Expr { * * Syntactic sugar for: * ``` - * >>> pl.col("*").exclude(columns) + * > pl.col("*").exclude(columns) * ``` */ -export function exclude(columns: string[] | string): Expr -export function exclude(col: string, ...cols: string[]): Expr +export function exclude(columns: string[] | string): Expr; +export function exclude(col: string, ...cols: string[]): Expr; export function exclude(...columns): Expr { return col("*").exclude(columns as any); } /** Get the first value. */ -export function first(): Expr -export function first(column: string): Expr -export function first(column: Series): T +export function first(): Expr; +export function first(column: string): Expr; +export function first(column: Series): T; export function first(column?: string | Series): Expr | T { - if(!column) { + if (!column) { return _Expr(pli.first()); } if (Series.isSeries(column)) { if (column.length) { return column.get(0); } else { - throw new RangeError("The series is empty, so no first value can be returned."); + throw new RangeError( + "The series is empty, so no first value can be returned.", + ); } } else { return col(column).first(); @@ -274,11 +297,11 @@ export function first(column?: string | Series): Expr | T { * Note: strings will be interpolated as `col()`. if you want a literal string, use `lit()` * @example * ``` - * >>> df = pl.DataFrame({ + * > df = pl.DataFrame({ * ... "a": ["a", "b", "c"], * ... "b": [1, 2, 3], * ... }) - * >>> df.select( + * > df.select( * ... pl.format("foo_{}_bar_{}", pl.col("a"), "b").alias("fmt"), * ... ) * shape: (3, 1) @@ -295,15 +318,20 @@ export function first(column?: string | Series): Expr | T { * └─────────────┘ * * // You can use format as tag function as well - * >>> pl.format("foo_{}_bar_{}", pl.col("a"), "b") // is the same as - * >>> pl.format`foo_${pl.col("a")}_bar_${"b"}` + * > pl.format("foo_{}_bar_{}", pl.col("a"), "b") // is the same as + * > pl.format`foo_${pl.col("a")}_bar_${"b"}` * ``` */ -export function format(strings: string | TemplateStringsArray, ...expr: ExprOrString[]): Expr { +export function format( + strings: string | TemplateStringsArray, + ...expr: ExprOrString[] +): Expr { if (typeof strings === "string") { const s = strings.split("{}"); if (s.length - 1 !== expr.length) { - throw new RangeError("number of placeholders should equal the number of arguments"); + throw new RangeError( + "number of placeholders should equal the number of arguments", + ); } return format(s as any, ...expr); @@ -333,7 +361,6 @@ export function head(column: Series | ExprOrString, n?): Series | Expr { return column.head(n); } else { return exprToLitOrExpr(column, false).head(n); - } } @@ -343,7 +370,9 @@ export function last(column: ExprOrString | Series): any { if (column.length) { return column.get(-1); } else { - throw new RangeError("The series is empty, so no last value can be returned."); + throw new RangeError( + "The series is empty, so no last value can be returned.", + ); } } else { return exprToLitOrExpr(column, false).last(); @@ -383,7 +412,6 @@ export function nUnique(column: Series | ExprOrString): number | Expr { return exprToLitOrExpr(column, false).nUnique(); } - /** Compute the pearson's correlation between two columns. */ export function pearsonCorr(a: ExprOrString, b: ExprOrString): Expr { a = exprToLitOrExpr(a, false); @@ -420,7 +448,6 @@ export function spearmanRankCorr(a: ExprOrString, b: ExprOrString): Expr { return _Expr(pli.spearmanRankCorr(a, b, null, false)); } - /** Get the last n rows of an Expression. */ export function tail(column: ExprOrString, n?: number): Expr; export function tail(column: Series, n?: number): Series; @@ -437,7 +464,6 @@ export function list(column: ExprOrString): Expr { return exprToLitOrExpr(column, false).list(); } - /** Collect several columns into a Series of dtype Struct Parameters @@ -450,7 +476,7 @@ export function list(column: ExprOrString): Expr { Examples -------- ``` - >>> pl.DataFrame( + >pl.DataFrame( ... { ... "int": [1, 2], ... "str": ["a", "b"], @@ -470,12 +496,12 @@ export function list(column: ExprOrString): Expr { └───────────────────────┘ // Only collect specific columns as a struct: - >>> df = pl.DataFrame({ + >df = pl.DataFrame({ ... "a": [1, 2, 3, 4], ... "b": ["one", "two", "three", "four"], ... "c": [9, 8, 7, 6] ... }) - >>> df.withColumn(pl.struct(pl.col(["a", "b"])).alias("a_and_b")) + >df.withColumn(pl.struct(pl.col(["a", "b"])).alias("a_and_b")) shape: (4, 4) ┌─────┬───────┬─────┬───────────────────────────────┐ │ a ┆ b ┆ c ┆ a_and_b │ @@ -492,20 +518,23 @@ export function list(column: ExprOrString): Expr { └─────┴───────┴─────┴───────────────────────────────┘ ``` */ -export function struct(exprs: Series[]): Series -export function struct(exprs: ExprOrString | ExprOrString[]): Expr -export function struct(exprs: ExprOrString | ExprOrString[] | Series[]): Expr | Series { +export function struct(exprs: Series[]): Series; +export function struct(exprs: ExprOrString | ExprOrString[]): Expr; +export function struct( + exprs: ExprOrString | ExprOrString[] | Series[], +): Expr | Series { exprs = Array.isArray(exprs) ? exprs : [exprs]; if (Series.isSeries(exprs[0])) { - return select(_Expr(pli.asStruct(exprs.map(e => pli.lit(e.inner()))))).toSeries(); + return select( + _Expr(pli.asStruct(exprs.map((e) => pli.lit(e.inner())))), + ).toSeries(); } exprs = selectionToExprList(exprs); return _Expr(pli.asStruct(exprs)); } - /** * Alias for an element in evaluated in an `eval` expression. @@ -513,8 +542,8 @@ export function struct(exprs: ExprOrString | ExprOrString[] | Series[]): Expr | * * A horizontal rank computation by taking the elements of a list * - * >>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) - * >>> df.withColumn( + * >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) + * >df.withColumn( * ... pl.concatList(["a", "b"]).arr.eval(pl.element().rank()).alias("rank") * ... ) * shape: (3, 3) @@ -532,8 +561,8 @@ export function struct(exprs: ExprOrString | ExprOrString[] | Series[]): Expr | * * A mathematical operation on array elements * - * >>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) - * >>> df.withColumn( + * >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) + * >df.withColumn( * ... pl.concatList(["a", "b"]).arr.eval(pl.element().multiplyBy(2)).alias("a_b_doubled") * ... ) * shape: (3, 3) diff --git a/polars/lazy/groupby.ts b/polars/lazy/groupby.ts index 1f62b2dd8..f32a6d46d 100644 --- a/polars/lazy/groupby.ts +++ b/polars/lazy/groupby.ts @@ -1,29 +1,42 @@ -import {Expr} from "./expr"; -import {selectionToExprList} from "../utils"; -import {_LazyDataFrame, LazyDataFrame} from "./dataframe"; - -export interface LazyGroupBy { - agg(...aggs: Expr[]): LazyDataFrame - head(n?: number): LazyDataFrame - tail(n?: number): LazyDataFrame -} - - -export const LazyGroupBy = (_lgb: any): LazyGroupBy => { +import { Expr } from "./expr"; +import { selectionToExprList } from "../utils"; +import { _LazyDataFrame, LazyDataFrame } from "./dataframe"; +/** @ignore */ +export const _LazyGroupBy = (_lgb: any): LazyGroupBy => { return { - agg(...aggs: Expr[]) { - aggs = selectionToExprList(aggs, false); + agg(...aggs: Expr[]) { + aggs = selectionToExprList(aggs, false); const ret = _lgb.agg(aggs.flat()); return _LazyDataFrame(ret); }, - head(n=5) { + head(n = 5) { return _LazyDataFrame(_lgb.head(n)); }, - tail(n=5) { + tail(n = 5) { return _LazyDataFrame(_lgb.tail(n)); - - } + }, }; }; + +/** + * LazyGroupBy + * @category lazy + */ +export interface LazyGroupBy { + /** + * Aggregate the groupby. + */ + agg(...aggs: Expr[]): LazyDataFrame; + /** + * Return the first n rows of the groupby. + * @param n number of rows to return + */ + head(n?: number): LazyDataFrame; + /** + * Return the last n rows of the groupby. + * @param n number of rows to return + */ + tail(n?: number): LazyDataFrame; +} diff --git a/polars/lazy/index.ts b/polars/lazy/index.ts index 7b637d549..00b70946c 100644 --- a/polars/lazy/index.ts +++ b/polars/lazy/index.ts @@ -1,13 +1,4 @@ - -import * as func from "./functions"; -import * as gb from "./groupby"; -import * as expr from "./expr"; -import * as whenthen from "./whenthen"; -namespace lazy { - export import GroupBy = gb.LazyGroupBy; - export import Expr = expr; - export import funcs = func; - export import when = whenthen; -} - -export = lazy; +export * from "./functions"; +export * from "./groupby"; +export * from "./expr"; +export * from "./whenthen"; diff --git a/polars/lazy/whenthen.ts b/polars/lazy/whenthen.ts index d210fda83..b31b991f5 100644 --- a/polars/lazy/whenthen.ts +++ b/polars/lazy/whenthen.ts @@ -1,63 +1,65 @@ -import {Expr} from "./expr"; +import { Expr } from "./expr"; import pli from "../internals/polars_internal"; - export interface When { /** Values to return in case of the predicate being `true`.*/ - then(expr: Expr): WhenThen + then(expr: Expr): WhenThen; } export interface WhenThen { /** Start another when, then, otherwise layer. */ - when(predicate: Expr): WhenThenThen + when(predicate: Expr): WhenThenThen; /** Values to return in case of the predicate being `false`. */ - otherwise(expr: Expr): Expr + otherwise(expr: Expr): Expr; } export interface WhenThenThen { /** Start another when, then, otherwise layer. */ - when(predicate: Expr): WhenThenThen + when(predicate: Expr): WhenThenThen; /** Values to return in case of the predicate being `true`. */ - then(expr: Expr): WhenThenThen + then(expr: Expr): WhenThenThen; /** Values to return in case of the predicate being `false`. */ - otherwise(expr: Expr): Expr + otherwise(expr: Expr): Expr; } function WhenThenThen(_whenthenthen: any): WhenThenThen { return { - when: ({_expr}: Expr): WhenThenThen => WhenThenThen(_whenthenthen.when(_expr)), - then: ({_expr}: Expr): WhenThenThen => WhenThenThen(_whenthenthen.then(_expr)), - otherwise: ({_expr}: Expr): Expr => (Expr as any)(_whenthenthen.otherwise(_expr)) + when: ({ _expr }: Expr): WhenThenThen => + WhenThenThen(_whenthenthen.when(_expr)), + then: ({ _expr }: Expr): WhenThenThen => + WhenThenThen(_whenthenthen.then(_expr)), + otherwise: ({ _expr }: Expr): Expr => + (Expr as any)(_whenthenthen.otherwise(_expr)), }; } function WhenThen(_whenthen: any): WhenThen { return { - when: ({_expr}: Expr): WhenThenThen => WhenThenThen(_whenthen.when(_expr)), - otherwise: ({_expr}: Expr): Expr => (Expr as any)(_whenthen.otherwise(_expr)) + when: ({ _expr }: Expr): WhenThenThen => + WhenThenThen(_whenthen.when(_expr)), + otherwise: ({ _expr }: Expr): Expr => + (Expr as any)(_whenthen.otherwise(_expr)), }; } - /** * Utility function. * @see {@link when} */ function When(_when: any): When { return { - then: ({_expr}: Expr): WhenThen => WhenThen(_when.then(_expr)) + then: ({ _expr }: Expr): WhenThen => WhenThen(_when.then(_expr)), }; } - /** * Start a when, then, otherwise expression. * * @example * ``` * // Below we add a column with the value 1, where column "foo" > 2 and the value -1 where it isn't. - * >>> df = pl.DataFrame({"foo": [1, 3, 4], "bar": [3, 4, 0]}) - * >>> df.withColumn(pl.when(pl.col("foo").gt(2)).then(pl.lit(1)).otherwise(pl.lit(-1))) + * > df = pl.DataFrame({"foo": [1, 3, 4], "bar": [3, 4, 0]}) + * > df.withColumn(pl.when(pl.col("foo").gt(2)).then(pl.lit(1)).otherwise(pl.lit(-1))) * shape: (3, 3) * ┌─────┬─────┬─────────┐ * │ foo ┆ bar ┆ literal │ @@ -72,7 +74,7 @@ function When(_when: any): When { * └─────┴─────┴─────────┘ * * // Or with multiple `when, thens` chained: - * >>> df.with_column( + * > df.with_column( * ... pl.when(pl.col("foo").gt(2)) * ... .then(1) * ... .when(pl.col("bar").gt(2)) @@ -93,7 +95,6 @@ function When(_when: any): When { * └─────┴─────┴─────────┘ * ``` */ -export function when(expr: Expr): When { - +export function when(expr: Expr): When { return When(pli.when(expr._expr)); } diff --git a/polars/series/datetime.ts b/polars/series/datetime.ts index 3234ac3e1..9077743ed 100644 --- a/polars/series/datetime.ts +++ b/polars/series/datetime.ts @@ -1,11 +1,10 @@ -import {Series, _Series} from "./series"; -import {DateFunctions} from "../shared_traits"; +import { Series, _Series } from "."; +import { DateFunctions } from "../shared_traits"; export type SeriesDateFunctions = DateFunctions; export const SeriesDateFunctions = (_s): SeriesDateFunctions => { const wrap = (method, ...args: any[]): Series => { - return _Series(_s[method](...args)) as any; }; diff --git a/polars/series/series.ts b/polars/series/index.ts similarity index 76% rename from polars/series/series.ts rename to polars/series/index.ts index 3af45867a..b5422c5b1 100644 --- a/polars/series/series.ts +++ b/polars/series/index.ts @@ -1,44 +1,55 @@ import pli from "../internals/polars_internal"; -import {arrayToJsSeries} from "../internals/construction"; -import {DataType, DTYPE_TO_FFINAME, Optional} from "../datatypes"; -import {DataFrame, _DataFrame} from "../dataframe"; -import {StringFunctions} from "./string"; -import {SeriesListFunctions} from "./list"; -import {SeriesDateFunctions} from "./datetime"; -import {SeriesStructFunctions} from "./struct"; -import {InvalidOperationError} from "../error"; -import {RankMethod} from "../utils"; -import {Arithmetic, Comparison, Cumulative, Deserialize, Rolling, Round, Sample, Serialize} from "../shared_traits"; -import {col} from "../lazy/functions"; -import {InterpolationMethod} from "../lazy/expr"; +import { arrayToJsSeries } from "../internals/construction"; +import { DataType, DTYPE_TO_FFINAME, Optional } from "../datatypes"; +import { DataFrame, _DataFrame } from "../dataframe"; +import { SeriesStringFunctions, StringNamespace } from "./string"; +import { ListNamespace, SeriesListFunctions } from "./list"; +import { SeriesDateFunctions } from "./datetime"; +import { SeriesStructFunctions } from "./struct"; +import { InvalidOperationError } from "../error"; +import { + Arithmetic, + Comparison, + Cumulative, + Deserialize, + Rolling, + Round, + Sample, + Serialize, +} from "../shared_traits"; +import { col } from "../lazy/functions"; +import { InterpolationMethod, RankMethod } from "../types"; const inspect = Symbol.for("nodejs.util.inspect.custom"); -export interface Series extends - ArrayLike, - Rolling, - Arithmetic, - Comparison, - Cumulative, - Round, - Sample, - Serialize { - inner(): any - name: string - dtype: DataType - str: StringFunctions - lst: SeriesListFunctions, - struct: SeriesStructFunctions, - date: SeriesDateFunctions +/** + * A Series represents a single column in a polars DataFrame. + */ +export interface Series + extends ArrayLike, + Rolling, + Arithmetic, + Comparison, + Cumulative, + Round, + Sample, + Serialize { + inner(): any; + name: string; + dtype: DataType; + str: StringNamespace; + lst: ListNamespace; + struct: SeriesStructFunctions; + date: SeriesDateFunctions; [inspect](): string; [Symbol.iterator](): IterableIterator; // inner(): JsSeries - bitand(other: Series): Series - bitor(other: Series): Series - bitxor(other: Series): Series + bitand(other: Series): Series; + bitor(other: Series): Series; + bitxor(other: Series): Series; /** * Take absolute values */ - abs(): Series + abs(): Series; /** * __Rename this Series.__ * @@ -46,15 +57,15 @@ export interface Series extends * @see {@link rename} * */ - alias(name: string): Series + alias(name: string): Series; /** * __Append a Series to this one.__ * ___ * @param {Series} other - Series to append. * @example - * > const s = pl.Series("a", [1, 2, 3]) - * > const s2 = pl.Series("b", [4, 5, 6]) - * > s.append(s2) + * > const s = pl.Series("a", [1, 2, 3]) + * > const s2 = pl.Series("b", [4, 5, 6]) + * > s.append(s2) * shape: (6,) * Series: 'a' [i64] * [ @@ -66,7 +77,7 @@ export interface Series extends * 6 * ] */ - append(other: Series): void + append(other: Series): void; // TODO! // /** // * __Apply a function over elements in this Series and return a new Series.__ @@ -78,8 +89,8 @@ export interface Series extends // * @returns {SeriesType} `Series | Series` // * @example // * ``` - // * > const s = pl.Series("a", [1, 2, 3]) - // * > s.apply(x => x + 10) + // * > const s = pl.Series("a", [1, 2, 3]) + // * > s.apply(x => x + 10) // * shape: (3,) // * Series: 'a' [i64] // * [ @@ -93,29 +104,29 @@ export interface Series extends /** * Get the index of the maximal value. */ - argMax(): Optional + argMax(): Optional; /** - * Get the index of the minimal value. - */ - argMin(): Optional + * Get the index of the minimal value. + */ + argMin(): Optional; /** * Get index values where Boolean Series evaluate True. * */ - argTrue(): Series + argTrue(): Series; /** * Get unique index as Series. */ - argUnique(): Series + argUnique(): Series; /** * Index location of the sorted variant of this Series. * ___ * @param reverse * @return {SeriesType} indexes - Indexes that can be used to sort this array. */ - argSort(): Series - argSort(reverse: boolean): Series - argSort({reverse}: {reverse: boolean}): Series + argSort(): Series; + argSort(reverse: boolean): Series; + argSort({ reverse }: { reverse: boolean }): Series; /** * __Rename this Series.__ * @@ -123,20 +134,20 @@ export interface Series extends * @see {@link rename} {@link alias} * */ - as(name: string): Series + as(name: string): Series; /** * Cast between data types. */ - cast(dtype: DataType, strict?: boolean): Series + cast(dtype: DataType, strict?: boolean): Series; /** * Get the length of each individual chunk */ - chunkLengths(): Array + chunkLengths(): Array; /** * Cheap deep clones. */ - clone(): Series - concat(other: Series): Series + clone(): Series; + concat(other: Series): Series; /** * __Quick summary statistics of a series. __ @@ -145,8 +156,8 @@ export interface Series extends * ___ * @example * ``` - * > const seriesNum = pl.Series([1,2,3,4,5]) - * > series_num.describe() + * > const seriesNum = pl.Series([1,2,3,4,5]) + * > series_num.describe() * * shape: (6, 2) * ┌──────────────┬────────────────────┐ @@ -167,8 +178,8 @@ export interface Series extends * │ "count" ┆ 5 │ * └──────────────┴────────────────────┘ * - * > series_str = pl.Series(["a", "a", None, "b", "c"]) - * > series_str.describe() + * > series_str = pl.Series(["a", "a", None, "b", "c"]) + * > series_str.describe() * * shape: (3, 2) * ┌──────────────┬───────┐ @@ -184,30 +195,33 @@ export interface Series extends * └──────────────┴───────┘ * ``` */ - describe(): DataFrame + describe(): DataFrame; /** * Calculates the n-th discrete difference. * @param n - number of slots to shift * @param nullBehavior - `'ignore' | 'drop'` */ - diff(n: number, nullBehavior: "ignore" | "drop"): Series - diff({n, nullBehavior}: {n: number, nullBehavior: "ignore" | "drop"}): Series - /** - * Compute the dot/inner product between two Series - * ___ - * @example - * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > const s2 = pl.Series("b", [4.0, 5.0, 6.0]) - * > s.dot(s2) - * 32.0 - * ``` - */ - dot(other: Series): number | undefined | null + diff(n: number, nullBehavior: "ignore" | "drop"): Series; + diff({ + n, + nullBehavior, + }: { n: number; nullBehavior: "ignore" | "drop" }): Series; + /** + * Compute the dot/inner product between two Series + * ___ + * @example + * ``` + * > const s = pl.Series("a", [1, 2, 3]) + * > const s2 = pl.Series("b", [4.0, 5.0, 6.0]) + * > s.dot(s2) + * 32.0 + * ``` + */ + dot(other: Series): number | undefined | null; /** * Create a new Series that copies data from this Series without null values. */ - dropNulls(): Series + dropNulls(): Series; /** * __Explode a list or utf8 Series.__ * @@ -215,8 +229,8 @@ export interface Series extends * ___ * @example * ``` - * > const s = pl.Series('a', [[1, 2], [3, 4], [9, 10]]) - * > s.explode() + * > const s = pl.Series('a', [[1, 2], [3, 4], [9, 10]]) + * > s.explode() * shape: (6,) * Series: 'a' [i64] * [ @@ -229,7 +243,7 @@ export interface Series extends * ] * ``` */ - explode(): any + explode(): any; /** * Extend the Series with given number of values. * @param value The value to extend the Series with. This value may be null to fill with nulls. @@ -237,21 +251,21 @@ export interface Series extends * @deprecated * @see {@link extendConstant} */ - extend(value: any, n: number): Series + extend(value: any, n: number): Series; /** * Extend the Series with given number of values. * @param value The value to extend the Series with. This value may be null to fill with nulls. * @param n The number of values to extend. */ - extendConstant(value: any, n: number): Series + extendConstant(value: any, n: number): Series; /** * __Fill null values with a filling strategy.__ * ___ * @param strategy - Filling Strategy * @example * ``` - * > const s = pl.Series("a", [1, 2, 3, None]) - * > s.fill_null('forward')) + * > const s = pl.Series("a", [1, 2, 3, None]) + * > s.fill_null('forward')) * shape: (4,) * Series: '' [i64] * [ @@ -260,7 +274,7 @@ export interface Series extends * 3 * 3 * ] - * > s.fill_null('min')) + * > s.fill_null('min')) * shape: (4,) * Series: 'a' [i64] * [ @@ -271,22 +285,28 @@ export interface Series extends * ] * ``` */ - fillNull(strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero"): Series - fillNull({strategy}: {strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero"}): Series + fillNull( + strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero", + ): Series; + fillNull({ + strategy, + }: { + strategy: "backward" | "forward" | "min" | "max" | "mean" | "one" | "zero"; + }): Series; /** * __Filter elements by a boolean mask.__ * @param {SeriesType} predicate - Boolean mask * */ - filter(predicate: Series): Series - filter({predicate}: {predicate: Series}): Series - get(index: number): any - getIndex(n: number): any + filter(predicate: Series): Series; + filter({ predicate }: { predicate: Series }): Series; + get(index: number): any; + getIndex(n: number): any; /** * Returns True if the Series has a validity bitmask. * If there is none, it means that there are no null values. */ - hasValidity(): boolean + hasValidity(): boolean; /** * Hash the Series * The hash value is of type `UInt64` @@ -297,8 +317,8 @@ export interface Series extends * @param k3 - seed parameter * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.hash(42) + * > const s = pl.Series("a", [1, 2, 3]) + * > s.hash(42) * shape: (3,) * Series: 'a' [u64] * [ @@ -308,16 +328,31 @@ export interface Series extends * ] * ``` */ - hash(k0?: number | bigint, k1?: number | bigint, k2?: number | bigint, k3?: number | bigint): Series - hash({k0, k1, k2, k3}: {k0?: number | bigint, k1?: number | bigint, k2?: number | bigint, k3?: number | bigint}): Series + hash( + k0?: number | bigint, + k1?: number | bigint, + k2?: number | bigint, + k3?: number | bigint, + ): Series; + hash({ + k0, + k1, + k2, + k3, + }: { + k0?: number | bigint; + k1?: number | bigint; + k2?: number | bigint; + k3?: number | bigint; + }): Series; /** * __Get first N elements as Series.__ * ___ * @param length Length of the head * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.head(2) + * > const s = pl.Series("a", [1, 2, 3]) + * > s.head(2) * shape: (2,) * Series: 'a' [i64] * [ @@ -326,7 +361,7 @@ export interface Series extends * ] * ``` */ - head(length?: number): Series + head(length?: number): Series; /** * __Interpolate intermediate values.__ * @@ -334,8 +369,8 @@ export interface Series extends * ___ * @example * ``` - * > const s = pl.Series("a", [1, 2, None, None, 5]) - * > s.interpolate() + * > const s = pl.Series("a", [1, 2, None, None, 5]) + * > s.interpolate() * shape: (5,) * Series: 'a' [i64] * [ @@ -347,22 +382,22 @@ export interface Series extends * ] * ``` */ - interpolate(method?: InterpolationMethod): Series + interpolate(method?: InterpolationMethod): Series; /** * Check if this Series is a Boolean. */ - isBoolean(): boolean + isBoolean(): boolean; /** * Check if this Series is a DataTime. */ - isDateTime(): boolean + isDateTime(): boolean; /** * __Get mask of all duplicated values.__ * * @example * ``` - * > const s = pl.Series("a", [1, 2, 2, 3]) - * > s.isDuplicated() + * > const s = pl.Series("a", [1, 2, 2, 3]) + * > s.isDuplicated() * * shape: (4,) * Series: 'a' [bool] @@ -374,29 +409,29 @@ export interface Series extends * ] * ``` */ - isDuplicated(): Series + isDuplicated(): Series; /** * Get mask of finite values if Series dtype is Float. */ - isFinite(): Series + isFinite(): Series; /** * Get a mask of the first unique value. */ - isFirst(): Series + isFirst(): Series; /** * Check if this Series is a Float. */ - isFloat(): boolean + isFloat(): boolean; /** * Check if elements of this Series are in the right Series, or List values of the right Series. */ - isIn(other: Series | U[]): Series + isIn(other: Series | U[]): Series; /** * __Get mask of infinite values if Series dtype is Float.__ * @example * ``` - * > const s = pl.Series("a", [1.0, 2.0, 3.0]) - * > s.isInfinite() + * > const s = pl.Series("a", [1.0, 2.0, 3.0]) + * > s.isInfinite() * * shape: (3,) * Series: 'a' [bool] @@ -407,7 +442,7 @@ export interface Series extends * ] * ``` */ - isInfinite(): Series + isInfinite(): Series; /** * __Get mask of non null values.__ * @@ -415,8 +450,8 @@ export interface Series extends * ___ * @example * ``` - * > const s = pl.Series("a", [1.0, undefined, 2.0, 3.0, null]) - * > s.isNotNull() + * > const s = pl.Series("a", [1.0, undefined, 2.0, 3.0, null]) + * > s.isNotNull() * shape: (5,) * Series: 'a' [bool] * [ @@ -428,7 +463,7 @@ export interface Series extends * ] * ``` */ - isNotNull(): Series + isNotNull(): Series; /** * __Get mask of null values.__ * @@ -436,8 +471,8 @@ export interface Series extends * ___ * @example * ``` - * > const s = pl.Series("a", [1.0, undefined, 2.0, 3.0, null]) - * > s.isNull() + * > const s = pl.Series("a", [1.0, undefined, 2.0, 3.0, null]) + * > s.isNull() * shape: (5,) * Series: 'a' [bool] * [ @@ -449,18 +484,18 @@ export interface Series extends * ] * ``` */ - isNull(): Series + isNull(): Series; /** * Check if this Series datatype is numeric. */ - isNumeric(): boolean + isNumeric(): boolean; /** * __Get mask of unique values.__ * ___ * @example * ``` - * > const s = pl.Series("a", [1, 2, 2, 3]) - * > s.isUnique() + * > const s = pl.Series("a", [1, 2, 2, 3]) + * > s.isUnique() * shape: (4,) * Series: 'a' [bool] * [ @@ -471,11 +506,11 @@ export interface Series extends * ] * ``` */ - isUnique(): Series + isUnique(): Series; /** * Checks if this Series datatype is a Utf8. */ - isUtf8(): boolean + isUtf8(): boolean; /** * __Compute the kurtosis (Fisher or Pearson) of a dataset.__ * @@ -489,20 +524,23 @@ export interface Series extends * - If True, Fisher's definition is used (normal ==> 0.0). * - If False, Pearson's definition is used (normal ==> 3.0) */ - kurtosis(): Optional - kurtosis(fisher: boolean, bias?: boolean): Optional - kurtosis({fisher, bias}: {fisher?: boolean, bias?: boolean}): Optional + kurtosis(): Optional; + kurtosis(fisher: boolean, bias?: boolean): Optional; + kurtosis({ + fisher, + bias, + }: { fisher?: boolean; bias?: boolean }): Optional; /** * __Length of this Series.__ * ___ * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.len() + * > const s = pl.Series("a", [1, 2, 3]) + * > s.len() * 3 * ``` */ - len(): number + len(): number; /** * __Take `n` elements from this Series.__ * ___ @@ -520,47 +558,47 @@ export interface Series extends * ] * ``` */ - limit(n?: number): Series + limit(n?: number): Series; /** * Get the maximum value in this Series. * @example * ``` - * >>> s = pl.Series("a", [1, 2, 3]) - * >>> s.max() + * > s = pl.Series("a", [1, 2, 3]) + * > s.max() * 3 * ``` */ - max(): number + max(): number; /** * Reduce this Series to the mean value. * @example * ``` - * >>> s = pl.Series("a", [1, 2, 3]) - * >>> s.mean() + * > s = pl.Series("a", [1, 2, 3]) + * > s.mean() * 2 * ``` */ - mean(): number + mean(): number; /** * Get the median of this Series * @example * ``` - * >>> s = pl.Series("a", [1, 2, 3]) - * >>> s.median() + * > s = pl.Series("a", [1, 2, 3]) + * > s.median() * 2 * ``` */ - median(): number + median(): number; /** * Get the minimal value in this Series. * @example * ``` - * >>> s = pl.Series("a", [1, 2, 3]) - * >>> s.min() + * > s = pl.Series("a", [1, 2, 3]) + * > s.min() * 1 * ``` */ - min(): number + min(): number; /** * __Compute the most occurring value(s). Can return multiple Values__ * ___ @@ -584,11 +622,11 @@ export interface Series extends * ] * ``` */ - mode(): Series + mode(): Series; /** * Get the number of chunks that this Series contains. */ - nChunks(): number + nChunks(): number; /** * __Count the number of unique values in this Series.__ * ___ @@ -599,13 +637,13 @@ export interface Series extends * 3 * ``` */ - nUnique(): number + nUnique(): number; /** * Count the null values in this Series. -- * _`undefined` values are treated as null_ * */ - nullCount(): number + nullCount(): number; /** * Get a boolean mask of the local maximum peaks. * ___ @@ -624,7 +662,7 @@ export interface Series extends * ] * ``` */ - peakMax(): Series + peakMax(): Series; /** * Get a boolean mask of the local minimum peaks. * ___ @@ -643,7 +681,7 @@ export interface Series extends * ] * ``` */ - peakMin(): Series + peakMin(): Series; /** * Get the quantile value of this Series. * ___ @@ -655,7 +693,7 @@ export interface Series extends * 2 * ``` */ - quantile(quantile: number, interpolation?: string): number + quantile(quantile: number, interpolation?: string): number; /** * Assign ranks to data, dealing with ties appropriately. * @param method @@ -677,10 +715,10 @@ export interface Series extends * * __'random'__: Like 'ordinal', but the rank for ties is not dependent * on the order that the values occur in `a`. */ - rank(method?: RankMethod): Series - rechunk(): Series - rechunk(inPlace: true): Series - rechunk(inPlace: false): void + rank(method?: RankMethod): Series; + rechunk(): Series; + rechunk(inPlace: true): Series; + rechunk(inPlace: false): void; /** * __Reinterpret the underlying bits as a signed/unsigned integer.__ * @@ -694,7 +732,7 @@ export interface Series extends * @see {@link cast} * */ - reinterpret(signed?: boolean): Series + reinterpret(signed?: boolean): Series; /** * __Rename this Series.__ * @@ -715,9 +753,9 @@ export interface Series extends * ``` */ rename(name: string): Series; - rename(name: string, inPlace: boolean): void - rename({name, inPlace}: {name: string, inPlace?: boolean}): void - rename({name, inPlace}: {name: string, inPlace: true}): void + rename(name: string, inPlace: boolean): void; + rename({ name, inPlace }: { name: string; inPlace?: boolean }): void; + rename({ name, inPlace }: { name: string; inPlace: true }): void; /** * __Check if series is equal with another Series.__ @@ -734,14 +772,14 @@ export interface Series extends * false * ``` */ - seriesEqual(other: Series, nullEqual?: boolean, strict?: boolean): boolean + seriesEqual(other: Series, nullEqual?: boolean, strict?: boolean): boolean; /** * __Set masked values__ * @param filter Boolean mask * @param value value to replace masked values with */ - set(filter: Series, value: any): Series - setAtIdx(indices: number[] | Series, value: any): void + set(filter: Series, value: any): Series; + setAtIdx(indices: number[] | Series, value: any): void; /** * __Shift the values by a given period__ * @@ -769,7 +807,7 @@ export interface Series extends * ] * ``` */ - shift(periods: number): Series + shift(periods: number): Series; /** * Shift the values by a given period * @@ -778,15 +816,15 @@ export interface Series extends * @param periods - Number of places to shift (may be negative). * @param fillValue - Fill null & undefined values with the result of this expression. */ - shiftAndFill(periods: number, fillValue: any): Series - shiftAndFill(args: {periods: number, fillValue: any}): Series + shiftAndFill(periods: number, fillValue: any): Series; + shiftAndFill(args: { periods: number; fillValue: any }): Series; /** * __Shrink memory usage of this Series to fit the exact capacity needed to hold the data.__ * @param inPlace - Modify the Series in-place. */ - shrinkToFit(): Series - shrinkToFit(inPlace: true): void + shrinkToFit(): Series; + shrinkToFit(inPlace: true): void; /** * __Compute the sample skewness of a data set.__ * @@ -798,14 +836,14 @@ export interface Series extends * ___ * @param bias - If false, then the calculations are corrected for statistical bias. */ - skew(bias?: boolean): number | undefined + skew(bias?: boolean): number | undefined; /** * Create subslices of the Series. * * @param offset - Start of the slice (negative indexing may be used). * @param length - length of the slice. */ - slice(start: number, length?: number): Series + slice(start: number, length?: number): Series; /** * __Sort this Series.__ * @param reverse - Reverse sort @@ -832,19 +870,19 @@ export interface Series extends * ] * ``` */ - sort(): Series - sort(reverse?: boolean): Series - sort(options: {reverse: boolean}): Series + sort(): Series; + sort(reverse?: boolean): Series; + sort(options: { reverse: boolean }): Series; /** * Reduce this Series to the sum value. * @example * ``` - * >>> s = pl.Series("a", [1, 2, 3]) - * >>> s.sum() + * > s = pl.Series("a", [1, 2, 3]) + * > s.sum() * 6 * ``` */ - sum(): number + sum(): number; /** * __Get last N elements as Series.__ * @@ -863,7 +901,7 @@ export interface Series extends * ] * ``` */ - tail(length?: number): Series + tail(length?: number): Series; /** * Take every nth value in the Series and return as new Series. * @param n - nth value to take @@ -879,7 +917,7 @@ export interface Series extends * ] * ``` */ - takeEvery(n: number): Series + takeEvery(n: number): Series; /** * Take values by index. * ___ @@ -896,7 +934,7 @@ export interface Series extends * ] * ``` */ - take(indices: Array): Series + take(indices: Array): Series; /** * __Get unique elements in series.__ @@ -915,29 +953,29 @@ export interface Series extends * ] * ``` */ - unique(maintainOrder?: boolean | {maintainOrder: boolean}): Series - /** - * __Count the unique values in a Series.__ - * ___ - * @example - * ``` - * s = pl.Series("a", [1, 2, 2, 3]) - * s.valueCounts() - * shape: (3, 2) - * ╭─────┬────────╮ - * │ a ┆ counts │ - * │ --- ┆ --- │ - * │ i64 ┆ u32 │ - * ╞═════╪════════╡ - * │ 2 ┆ 2 │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 1 ┆ 1 │ - * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ - * │ 3 ┆ 1 │ - * ╰─────┴────────╯ - * ``` - */ - valueCounts(): DataFrame + unique(maintainOrder?: boolean | { maintainOrder: boolean }): Series; + /** + * __Count the unique values in a Series.__ + * ___ + * @example + * ``` + * s = pl.Series("a", [1, 2, 2, 3]) + * s.valueCounts() + * shape: (3, 2) + * ╭─────┬────────╮ + * │ a ┆ counts │ + * │ --- ┆ --- │ + * │ i64 ┆ u32 │ + * ╞═════╪════════╡ + * │ 2 ┆ 2 │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 1 ┆ 1 │ + * ├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ 1 │ + * ╰─────┴────────╯ + * ``` + */ + valueCounts(): DataFrame; /** * Where mask evaluates true, take values from self. * @@ -947,7 +985,7 @@ export interface Series extends * @param other - Series of same type * */ - zipWith(mask: Series, other: Series): Series + zipWith(mask: Series, other: Series): Series; /** * __Convert this Series to a Javascript Array.__ @@ -964,14 +1002,14 @@ export interface Series extends * true * ``` */ - toArray(): Array + toArray(): Array; /** * Converts series to a javascript typedArray. * * __Warning:__ * This will throw an error if you have nulls, or are using non numeric data types */ - toTypedArray(): any + toTypedArray(): any; /** * _Returns a Javascript object representation of Series_ @@ -988,20 +1026,14 @@ export interface Series extends * } * ``` */ - toObject(): {name: string, datatype: string, values: any[]} - toFrame(): DataFrame + toObject(): { name: string; datatype: string; values: any[] }; + toFrame(): DataFrame; /** compat with `JSON.stringify */ - toJSON(): string + toJSON(): string; /** Returns an iterator over the values */ - values(): IterableIterator + values(): IterableIterator; } -export interface RollingOptions { - windowSize: number - weights?: Array - minPeriods: number - center: boolean -} export function _Series(_s: any): Series { const unwrap = (method: keyof any, ...args: any[]) => { return _s[method as any](...args); @@ -1067,7 +1099,7 @@ export function _Series(_s: any): Series { return _s.len(); }, get str() { - return StringFunctions(_s); + return SeriesStringFunctions(_s); }, get lst() { return SeriesListFunctions(_s); @@ -1104,19 +1136,17 @@ export function _Series(_s: any): Series { return _Series(_s.argsort(reverse, nullsLast)); } - return _Series(_s.argsort( - reverse.reverse, - reverse.nullsLast ?? nullsLast - )); + return _Series( + _s.argsort(reverse.reverse, reverse.nullsLast ?? nullsLast), + ); }, argTrue() { - return _Series(this - .toFrame() - ._df - .lazy() - .select([pli.argWhere(pli.col(this.name))]) - .collectSync() - .column(this.name) + return _Series( + this.toFrame() + ._df.lazy() + .select([pli.argWhere(pli.col(this.name))]) + .collectSync() + .column(this.name), ); }, argUnique() { @@ -1173,37 +1203,37 @@ export function _Series(_s: any): Series { if (this.isNumeric()) { s = s.cast(DataType.Float64); stats = { - "min": s.min(), - "max": s.max(), - "null_count": s.nullCount(), - "mean": s.mean(), - "count": s.len(), + min: s.min(), + max: s.max(), + null_count: s.nullCount(), + mean: s.mean(), + count: s.len(), }; } else if (s.isBoolean()) { stats = { - "sum": s.sum(), - "null_count": s.nullCount(), - "count": s.len(), + sum: s.sum(), + null_count: s.nullCount(), + count: s.len(), }; } else if (s.isUtf8()) { stats = { - "unique": s.nUnique(), - "null_count": s.nullCount(), - "count": s.len(), + unique: s.nUnique(), + null_count: s.nullCount(), + count: s.len(), }; } else { throw new InvalidOperationError("describe", s.dtype); } return DataFrame({ - "statistic": Object.keys(stats), - "value": Object.values(stats) + statistic: Object.keys(stats), + value: Object.values(stats), }); }, diff(n: any = 1, nullBehavior = "ignore") { - return typeof n === "number" ? - _Series(_s.diff(n, nullBehavior)) : - _Series(_s.diff(n?.n ?? 1, n.nullBehavior ?? nullBehavior)); + return typeof n === "number" + ? _Series(_s.diff(n, nullBehavior)) + : _Series(_s.diff(n?.n ?? 1, n.nullBehavior ?? nullBehavior)); }, div(field: Series) { return dtypeWrap("Div", field); @@ -1233,14 +1263,14 @@ export function _Series(_s: any): Series { return wrap("extendConstant", value, n); }, fillNull(strategy) { - return typeof strategy === "string" ? - wrap("fillNull", strategy) : - wrap("fillNull", strategy.strategy); + return typeof strategy === "string" + ? wrap("fillNull", strategy) + : wrap("fillNull", strategy.strategy); }, filter(predicate) { - return Series.isSeries(predicate) ? - wrap("filter", (predicate as any)._s) : - wrap("filter", (SeriesConstructor("", predicate) as any)._s); + return Series.isSeries(predicate) + ? wrap("filter", (predicate as any)._s) + : wrap("filter", (SeriesConstructor("", predicate) as any)._s); }, get(field) { return dtypeUnwrap("Get", field); @@ -1264,14 +1294,14 @@ export function _Series(_s: any): Series { if (typeof obj === "number" || typeof obj === "bigint") { return wrap("hash", BigInt(obj), BigInt(k1), BigInt(k2), BigInt(k3)); } - const o = {k0: obj, k1: k1, k2: k2, k3: k3, ...obj}; + const o = { k0: obj, k1: k1, k2: k2, k3: k3, ...obj }; return wrap( "hash", BigInt(o.k0), BigInt(o.k1), BigInt(o.k2), - BigInt(o.k3) + BigInt(o.k3), ); }, hasValidity() { @@ -1302,7 +1332,11 @@ export function _Series(_s: any): Series { isFinite() { const dtype = this.dtype; - if (![DataType.Float32.variant, DataType.Float64.variant].includes(dtype.variant)) { + if ( + ![DataType.Float32.variant, DataType.Float64.variant].includes( + dtype.variant, + ) + ) { throw new InvalidOperationError("isFinite", dtype); } else { return wrap("isFinite"); @@ -1314,17 +1348,23 @@ export function _Series(_s: any): Series { isFloat() { const dtype = this.dtype; - return [DataType.Float32.variant, DataType.Float64.variant].includes(dtype.variant); + return [DataType.Float32.variant, DataType.Float64.variant].includes( + dtype.variant, + ); }, isIn(other) { - return Series.isSeries(other) ? - wrap("isIn", (other as any)._s) : - wrap("isIn", (Series("", other) as any)._s); + return Series.isSeries(other) + ? wrap("isIn", (other as any)._s) + : wrap("isIn", (Series("", other) as any)._s); }, isInfinite() { const dtype = this.dtype; - if (![DataType.Float32.variant, DataType.Float64.variant].includes(dtype.variant)) { + if ( + ![DataType.Float32.variant, DataType.Float64.variant].includes( + dtype.variant, + ) + ) { throw new InvalidOperationError("isFinite", dtype); } else { return wrap("isInfinite"); @@ -1355,7 +1395,7 @@ export function _Series(_s: any): Series { DataType.UInt32.variant, DataType.UInt64.variant, DataType.Float32.variant, - DataType.Float64.variant + DataType.Float64.variant, ]; return numericTypes.includes(dtype.variant); @@ -1373,7 +1413,7 @@ export function _Series(_s: any): Series { const d = { fisher: true, bias, - ...fisher + ...fisher, }; return _s.kurtosis(d.fisher, d.bias); @@ -1452,7 +1492,11 @@ export function _Series(_s: any): Series { }, reinterpret(signed = true) { const dtype = this.dtype; - if ([DataType.UInt64.variant, DataType.Int64.variant].includes(dtype.variant)) { + if ( + [DataType.UInt64.variant, DataType.Int64.variant].includes( + dtype.variant, + ) + ) { return wrap("reinterpret", signed); } else { throw new InvalidOperationError("reinterpret", dtype); @@ -1472,7 +1516,6 @@ export function _Series(_s: any): Series { } }, - rollingMax(...args) { return expr_op("rollingMax", ...args); }, @@ -1513,7 +1556,6 @@ export function _Series(_s: any): Series { } else { return wrap("round", opt.decimals); } - } else { throw new InvalidOperationError("round", this.dtype); } @@ -1522,7 +1564,9 @@ export function _Series(_s: any): Series { return expr_op("clip", ...args); }, setAtIdx(indices, value) { - indices = Series.isSeries(indices) ? indices.cast(DataType.UInt32) : Series(indices); + indices = Series.isSeries(indices) + ? indices.cast(DataType.UInt32) + : Series(indices); if (!Series.isSeries(value)) { if (!Array.isArray(value)) { value = [value]; @@ -1530,9 +1574,8 @@ export function _Series(_s: any): Series { value = Series(value); } - if(indices.length > 0) { + if (indices.length > 0) { value = value.extendConstant(value[0], indices.length - 1); - } _s.setAtIdx(indices._s, value._s); }, @@ -1543,37 +1586,20 @@ export function _Series(_s: any): Series { }, sample(opts?, frac?, withReplacement = false, seed?) { // rome-ignore lint/style/noArguments: - if (arguments.length === 0) { - return wrap("sampleN", - 1, - withReplacement, - false, - seed - ); + if (arguments.length === 0) { + return wrap("sampleN", 1, withReplacement, false, seed); } if (opts?.n !== undefined || opts?.frac !== undefined) { return this.sample(opts.n, opts.frac, opts.withReplacement, seed); } if (typeof opts === "number") { - return wrap("sampleN", - opts, - withReplacement, - false, - seed - ); + return wrap("sampleN", opts, withReplacement, false, seed); } if (typeof frac === "number") { - return wrap("sampleFrac", - frac, - withReplacement, - false, - seed - ); - } - else { + return wrap("sampleFrac", frac, withReplacement, false, seed); + } else { throw new TypeError("must specify either 'frac' or 'n'"); } - }, seriesEqual(other, nullEqual: any = true, strict = false) { return _s.seriesEqual(other._s, nullEqual, strict); @@ -1593,7 +1619,6 @@ export function _Series(_s: any): Series { return s as any; } - }, skew(bias: any = true) { if (typeof bias === "boolean") { @@ -1615,7 +1640,6 @@ export function _Series(_s: any): Series { } return wrap("sort", reverse?.reverse ?? false); - }, sub(field) { return dtypeWrap("Sub", field); @@ -1677,7 +1701,7 @@ export function _Series(_s: any): Series { }, zipWith(mask, other) { return wrap("zipWith", mask._s, other._s); - } + }, }; return new Proxy(series, { @@ -1694,34 +1718,73 @@ export function _Series(_s: any): Series { return true; } - } + }, }); } +/** + * @ignore + * @inheritDoc {Series} + */ export interface SeriesConstructor extends Deserialize { - (values: any): Series - (name: string, values: any[], dtype?): Series + /** + * Creates a new Series from a set of values. + * @param values — A set of values to include in the new Series object. + * @example + * ``` + * > pl.Series([1, 2, 3]) + * shape: (3,) + * Series: '' [f64] + * [ + * 1 + * 2 + * 3 + * ] + * ``` + */ + (values: any): Series; + /** + * Create a new named series + * @param name - The name of the series + * @param values - A set of values to include in the new Series object. + * @example + * ``` + * > pl.Series('foo', [1, 2, 3]) + * shape: (3,) + * Series: 'foo' [f64] + * [ + * 1 + * 2 + * 3 + * ] + * ``` + */ + (name: string, values: any[], dtype?): Series; /** * 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 + * 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; isSeries(arg: any): arg is Series; /** * @param binary used to serialize/deserialize series. This will only work with the output from series.toBinary(). - */ + */ // fromBinary(binary: Buffer): Series } - -let SeriesConstructor = function (arg0: any, arg1?: any, dtype?: any, strict?: any): Series { +let SeriesConstructor = function ( + arg0: any, + arg1?: any, + dtype?: any, + strict?: any, +): Series { if (typeof arg0 === "string") { const _s = arrayToJsSeries(arg0, arg1, dtype, strict); @@ -1741,7 +1804,6 @@ const isSeries = (anyVal: any): anyVal is Series => { const from = (name, values?: ArrayLike): Series => { if (Array.isArray(name)) { return SeriesConstructor("", values); - } else { return SeriesConstructor(name, values); } @@ -1750,10 +1812,9 @@ const of = (...values: any[]): Series => { return Series.from(values); }; - export const Series: SeriesConstructor = Object.assign(SeriesConstructor, { isSeries, from, of, - deserialize: (buf, fmt) => _Series(pli.JsSeries.deserialize(buf, fmt)) + deserialize: (buf, fmt) => _Series(pli.JsSeries.deserialize(buf, fmt)), }); diff --git a/polars/series/list.ts b/polars/series/list.ts index c4ccc36bf..160d05889 100644 --- a/polars/series/list.ts +++ b/polars/series/list.ts @@ -1,8 +1,9 @@ -import { Series, _Series } from "./series"; +import { Series, _Series } from "."; import { col } from "../lazy/functions"; import { ListFunctions } from "../shared_traits"; -export type SeriesListFunctions = ListFunctions; +export interface ListNamespace extends ListFunctions {} + export const SeriesListFunctions = (_s): ListFunctions => { const wrap = (method, ...args) => { const s = _Series(_s); @@ -12,7 +13,7 @@ export const SeriesListFunctions = (_s): ListFunctions => { .select( col(s.name) .lst[method](...args) - .as(s.name) + .as(s.name), ) .getColumn(s.name); }; diff --git a/polars/series/string.ts b/polars/series/string.ts index 47e37518c..950d3c91f 100644 --- a/polars/series/string.ts +++ b/polars/series/string.ts @@ -1,30 +1,28 @@ -import pli from "../internals/polars_internal"; -import {DataType} from "../datatypes"; -import {_Series, Series} from "./series"; -import {regexToString} from "../utils"; -import {todo} from "../error"; -import {col} from "../lazy/functions"; - +import { DataType } from "../datatypes"; +import { _Series, Series } from "."; +import { regexToString } from "../utils"; +import { col } from "../lazy/functions"; +import { StringFunctions } from "../shared_traits"; /** * namespace containing series string functions */ -export interface StringFunctions { +export interface StringNamespace extends StringFunctions { /** * Vertically concat the values in the Series to a single string value. * @example * ``` - * >>> pl.Series([1, null, 2]).str.concat("-")[0] + * > pl.Series([1, null, 2]).str.concat("-")[0] * '1-null-2' * ``` */ - concat(delimiter: string): Series + concat(delimiter: string): Series; /** * Check if strings in Series contain regex pattern. * @param pattern A valid regex pattern * @returns Boolean mask */ - contains(pattern: string | RegExp): Series + contains(pattern: string | RegExp): Series; /** * Decodes a value using the provided encoding * @param encoding - hex | base64 @@ -45,8 +43,8 @@ export interface StringFunctions { * ] * ``` */ - decode(encoding: "hex" | "base64", strict?: boolean): Series - decode(options: {encoding: "hex" | "base64", strict?: boolean}): Series + decode(encoding: "hex" | "base64", strict?: boolean): Series; + decode(options: { encoding: "hex" | "base64"; strict?: boolean }): Series; /** * Encodes a value using the provided encoding * @param encoding - hex | base64 @@ -63,7 +61,7 @@ export interface StringFunctions { * ] * ``` */ - encode(encoding: "hex" | "base64"): Series + encode(encoding: "hex" | "base64"): Series; /** * Extract the target capture group from provided patterns. * @param pattern A valid regex pattern @@ -73,13 +71,13 @@ export interface StringFunctions { * @returns Utf8 array. Contain null if original value is null or regex capture nothing. * @example * ``` - * > df = pl.DataFrame({ + * > df = pl.DataFrame({ * ... 'a': [ * ... 'http://vote.com/ballon_dor?candidate=messi&ref=polars', * ... 'http://vote.com/ballon_dor?candidat=jorginho&ref=polars', * ... 'http://vote.com/ballon_dor?candidate=ronaldo&ref=polars' * ... ]}) - * > df.getColumn("a").str.extract(/candidate=(\w+)/, 1) + * > df.getColumn("a").str.extract(/candidate=(\w+)/, 1) * shape: (3, 1) * ┌─────────┐ * │ a │ @@ -94,7 +92,7 @@ export interface StringFunctions { * └─────────┘ * ``` */ - extract(pattern: string | RegExp, groupIndex: number): Series + extract(pattern: string | RegExp, groupIndex: number): Series; /** * Extract the first match of json string with provided JSONPath expression. * Throw errors if encounter invalid json strings. @@ -104,14 +102,14 @@ export interface StringFunctions { * @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing. * @example * ``` - * >>> s = pl.Series('json_val', [ + * > s = pl.Series('json_val', [ * ... '{"a":"1"}', * ... null, * ... '{"a":2}', * ... '{"a":2.1}', * ... '{"a":true}' * ... ]) - * >>> s.str.jsonPathMatch('$.a') + * > s.str.jsonPathMatch('$.a') * shape: (5,) * Series: 'json_val' [str] * [ @@ -123,12 +121,12 @@ export interface StringFunctions { * ] * ``` */ - jsonPathMatch(jsonPath: string): Series + jsonPathMatch(jsonPath: string): Series; /** Get length of the string values in the Series. */ - lengths(): Series + lengths(): Series; /** Remove leading whitespace. */ - lstrip(): Series - /** + lstrip(): Series; + /** * Add a leading fillChar to a string until string length is reached. * If string is longer or equal to given length no modifications will be done * @param {number} length - of the final string @@ -159,8 +157,8 @@ export interface StringFunctions { * │ cow │ * └──────────┘ * ``` - */ - padStart(length: number, fillChar: string): Series + */ + padStart(length: number, fillChar: string): Series; /** * Add a leading '0' to a string until string length is reached. * If string is longer or equal to given length no modifications will be done @@ -190,54 +188,54 @@ export interface StringFunctions { * │ cow │ * └──────────┘ * ``` - */ - zFill(length: number): Series + */ + zFill(length: number): Series; /** Add trailing zeros */ - padEnd(length: number, fillChar: string): Series + padEnd(length: number, fillChar: string): Series; /** * Replace first regex match with a string value. * @param pattern A valid regex pattern * @param value Substring to replace. */ - replace(pattern: string | RegExp, value: string): Series + replace(pattern: string | RegExp, value: string): Series; /** * Replace all regex matches with a string value. * @param pattern - A valid regex pattern * @param value Substring to replace. */ - replaceAll(pattern: string | RegExp, value: string): Series + replaceAll(pattern: string | RegExp, value: string): Series; /** Modify the strings to their lowercase equivalent. */ - toLowerCase(): Series + toLowerCase(): Series; /** Modify the strings to their uppercase equivalent. */ - toUpperCase(): Series + toUpperCase(): Series; /** Remove trailing whitespace. */ - rstrip(): Series + rstrip(): Series; /** Remove leading and trailing whitespace. */ - strip(): Series + strip(): Series; /** * Create subslices of the string values of a Utf8 Series. * @param start - Start of the slice (negative indexing may be used). * @param length - Optional length of the slice. */ - slice(start: number, length?: number): Series + slice(start: number, length?: number): Series; /** * Split a string into substrings using the specified separator. * The return type will by of type List * @param separator — A string that identifies character or characters to use in separating the string. * @param inclusive Include the split character/string in the results */ - split(separator: string, options?: {inclusive?: boolean} | boolean): Series + split(separator: string, options?: { inclusive?: boolean } | boolean): Series; /** * Parse a Series of dtype Utf8 to a Date/Datetime Series. * @param datatype Date or Datetime. * @param fmt formatting syntax. [Read more](https://docs.rs/chrono/0.4.19/chrono/format/strptime/index.html) */ - strptime(datatype: DataType.Date, fmt?: string): Series - strptime(datatype: DataType.Datetime, fmt?: string): Series + strptime(datatype: DataType.Date, fmt?: string): Series; + strptime(datatype: DataType.Datetime, fmt?: string): Series; } -export const StringFunctions = (_s: any): StringFunctions => { +export const SeriesStringFunctions = (_s: any): StringNamespace => { const wrap = (method, ...args): any => { const ret = _s[method](...args); @@ -246,34 +244,27 @@ export const StringFunctions = (_s: any): StringFunctions => { const handleDecode = (encoding, strict) => { switch (encoding) { - case "hex": - return wrap("strHexDecode", strict); - case "base64": - - return wrap("strBase64Decode", strict); - default: - throw new RangeError("supported encodings are 'hex' and 'base64'"); + case "hex": + return wrap("strHexDecode", strict); + case "base64": + return wrap("strBase64Decode", strict); + default: + throw new RangeError("supported encodings are 'hex' and 'base64'"); } }; return { concat(delimiter: string) { - return _Series(_s) .toFrame() - .select( - col(_s.name) - .str - .concat(delimiter) - .as(_s.name) - ) + .select(col(_s.name).str.concat(delimiter).as(_s.name)) .getColumn(_s.name); }, contains(pat: string | RegExp) { return wrap("strContains", regexToString(pat)); }, - decode(arg, strict=false) { - if(typeof arg === "string") { + decode(arg, strict = false) { + if (typeof arg === "string") { return handleDecode(arg, strict); } @@ -281,19 +272,18 @@ export const StringFunctions = (_s: any): StringFunctions => { }, encode(encoding) { switch (encoding) { - case "hex": - return wrap(`strHexEncode`); - case "base64": - return wrap(`strBase64Encode`); - default: - throw new RangeError("supported encodings are 'hex' and 'base64'"); + case "hex": + return wrap("strHexEncode"); + case "base64": + return wrap("strBase64Encode"); + default: + throw new RangeError("supported encodings are 'hex' and 'base64'"); } }, extract(pat: string | RegExp, groupIndex: number) { return wrap("strExtract", regexToString(pat), groupIndex); }, jsonPathMatch(pat: string) { - return wrap("strJsonPathMatch", pat); }, lengths() { @@ -324,47 +314,30 @@ export const StringFunctions = (_s: any): StringFunctions => { return wrap("strSlice", start, length); }, split(by: string, options?) { - const inclusive = typeof options === "boolean" ? options : options?.inclusive; + const inclusive = + typeof options === "boolean" ? options : options?.inclusive; const s = _Series(_s); return s .toFrame() - .select( - col(s.name) - .str - .split(by, inclusive) - .as(s.name) - ) + .select(col(s.name).str.split(by, inclusive).as(s.name)) .getColumn(s.name); - }, strip() { const s = _Series(_s); return s .toFrame() - .select( - col(s.name) - .str - .strip() - .as(s.name) - ) + .select(col(s.name).str.strip().as(s.name)) .getColumn(s.name); - }, strptime(dtype, fmt?) { const s = _Series(_s); return s .toFrame() - .select( - col(s.name) - .str - .strptime(dtype, fmt) - .as(s.name) - ) + .select(col(s.name).str.strptime(dtype, fmt).as(s.name)) .getColumn(s.name); - }, toLowerCase() { return wrap("strToLowercase"); diff --git a/polars/series/struct.ts b/polars/series/struct.ts index 52d06f751..64a8c2858 100644 --- a/polars/series/struct.ts +++ b/polars/series/struct.ts @@ -1,16 +1,15 @@ import pli from "../internals/polars_internal"; -import {_DataFrame, DataFrame} from "../dataframe"; -import {_Series, Series} from "./series"; -import {_Expr} from "../lazy/expr"; +import { _DataFrame, DataFrame } from "../dataframe"; +import { _Series, Series } from "."; +import { _Expr } from "../lazy/expr"; export interface SeriesStructFunctions { - fields: string[] + fields: string[]; toFrame(): DataFrame; field(name: string): Series; - renameFields(names: string[]): Series + renameFields(names: string[]): Series; } - export const SeriesStructFunctions = (_s: any): SeriesStructFunctions => { return { get fields() { @@ -20,12 +19,14 @@ export const SeriesStructFunctions = (_s: any): SeriesStructFunctions => { return _DataFrame(_s.structToFrame()); }, field(name) { - return DataFrame({}).select(_Expr(pli.lit(_s).structFieldByName(name))) + return DataFrame({}) + .select(_Expr(pli.lit(_s).structFieldByName(name))) .toSeries(); }, renameFields(names) { - return DataFrame({}).select(_Expr(pli.lit(_s).structRenameFields(names))) + return DataFrame({}) + .select(_Expr(pli.lit(_s).structRenameFields(names))) .toSeries(); - } + }, }; }; diff --git a/polars/shared_traits.ts b/polars/shared_traits.ts index a37f920a7..f23aefe5c 100644 --- a/polars/shared_traits.ts +++ b/polars/shared_traits.ts @@ -1,54 +1,141 @@ import { ColumnsOrExpr } from "./utils"; import { Expr, _Expr } from "./lazy/expr"; -import { Series } from "./series/series"; -import { concatList } from "./lazy/functions"; -import pli from "./internals/polars_internal"; - -export type RollingOptions = { - windowSize: number; - weights?: Array; - minPeriods?: number; - center?: boolean; -}; - -export type Interpolation = - | "nearest" - | "higher" - | "lower" - | "midpoint" - | "linear"; +import { + InterpolationMethod, + RollingOptions, + RollingQuantileOptions, + RollingSkewOptions, +} from "./types"; +import { DataType } from "./datatypes"; +/** + * Arithmetic operations + */ export interface Arithmetic { - add(rhs: any): T; - sub(rhs: any): T; - div(rhs: any): T; - mul(rhs: any): T; - rem(rhs: any): T; - plus(rhs: any): T; - minus(rhs: any): T; - divideBy(rhs: any): T; - multiplyBy(rhs: any): T; - modulo(rhs: any): T; + /** + * Add self to other + * @category Arithmetic + */ + add(other: any): T; + /** + * Subtract other from self + * @category Arithmetic + */ + sub(other: any): T; + /** + * Divide self by other + * @category Arithmetic + */ + div(other: any): T; + /** + * Multiply self by other + * @category Arithmetic + */ + mul(other: any): T; + /** + * Get the remainder of self divided by other + * @category Arithmetic + */ + rem(other: any): T; + /** + * Add self to other + * @category Arithmetic + */ + plus(other: any): T; + /** + * Subtract other from self + * @category Arithmetic + */ + minus(other: any): T; + /** + * Divide self by other + * @category Arithmetic + */ + divideBy(other: any): T; + /** + * Multiply self by other + * @category Arithmetic + */ + multiplyBy(other: any): T; + /** + * Get the remainder of self divided by other + * @category Arithmetic + */ + modulo(other: any): T; } export interface Comparison { - eq(rhs: any): T; - equals(rhs: any): T; - gtEq(rhs: any): T; - greaterThanEquals(rhs: any): T; - gt(rhs: any): T; - greaterThan(rhs: any): T; - ltEq(rhs: any): T; - lessThanEquals(rhs: any): T; - lt(rhs: any): T; - lessThan(rhs: any): T; - neq(rhs: any): T; - notEquals(rhs: any): T; + /** + * Compare self to other: `self == other` + * @category Comparison + */ + eq(other: any): T; + /** + * Compare self to other: `self == other` + * @category Comparison + */ + equals(other: any): T; + /** + * Compare self to other: `self >= other` + * @category Comparison + */ + gtEq(other: any): T; + /** + * Compare self to other: `self >= other` + * @category Comparison + */ + greaterThanEquals(other: any): T; + /** + * Compare self to other: `self > other` + * @category Comparison + */ + gt(other: any): T; + /** + * Compare self to other: `self > other` + * @category Comparison + */ + greaterThan(other: any): T; + /** + * Compare self to other: `self <= other` + * @category Comparison + */ + ltEq(other: any): T; + /** + * Compare self to other: `self =< other` + * @category Comparison + */ + lessThanEquals(other: any): T; + /** + * Compare self to other: `self < other` + * @category Comparison + */ + lt(other: any): T; + /** + * Compare self to other: `self < other` + * @category Comparison + */ + lessThan(other: any): T; + /** + * Compare self to other: `self !== other` + * @category Comparison + */ + neq(other: any): T; + /** + * Compare self to other: `self !== other` + * @category Comparison + */ + notEquals(other: any): T; } +/** + * A trait for cumulative operations. + */ export interface Cumulative { - /** Get an array with the cumulative count computed at every element. */ + /** + * Get an array with the cumulative count computed at every element. + * @category Cumulative + */ cumCount(reverse?: boolean): T; cumCount({ reverse }: { reverse: boolean }): T; /** @@ -57,8 +144,8 @@ export interface Cumulative { * @param reverse - reverse the operation * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.cumMax() + * > const s = pl.Series("a", [1, 2, 3]) + * > s.cumMax() * shape: (3,) * Series: 'b' [i64] * [ @@ -67,6 +154,7 @@ export interface Cumulative { * 3 * ] * ``` + * @category Cumulative */ cumMax(reverse?: boolean): T; cumMax({ reverse }: { reverse: boolean }): T; @@ -76,8 +164,8 @@ export interface Cumulative { * @param reverse - reverse the operation * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.cumMin() + * > const s = pl.Series("a", [1, 2, 3]) + * > s.cumMin() * shape: (3,) * Series: 'b' [i64] * [ @@ -86,6 +174,7 @@ export interface Cumulative { * 1 * ] * ``` + * @category Cumulative */ cumMin(reverse?: boolean): T; cumMin({ reverse }: { reverse: boolean }): T; @@ -95,8 +184,8 @@ export interface Cumulative { * @param reverse - reverse the operation * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.cumProd() + * > const s = pl.Series("a", [1, 2, 3]) + * > s.cumProd() * shape: (3,) * Series: 'b' [i64] * [ @@ -105,6 +194,7 @@ export interface Cumulative { * 6 * ] * ``` + * @category Cumulative */ cumProd(reverse?: boolean): T; cumProd({ reverse }: { reverse: boolean }): T; @@ -114,8 +204,8 @@ export interface Cumulative { * @param reverse - reverse the operation * @example * ``` - * > const s = pl.Series("a", [1, 2, 3]) - * > s.cumSum() + * > const s = pl.Series("a", [1, 2, 3]) + * > s.cumSum() * shape: (3,) * Series: 'b' [i64] * [ @@ -124,11 +214,15 @@ export interface Cumulative { * 6 * ] * ``` + * @category Cumulative */ cumSum(reverse?: boolean): T; cumSum({ reverse }: { reverse: boolean }): T; } +/** + * __A trait for DataFrame and Series that allows for the application of a rolling window.__ + */ export interface Rolling { /** * __Apply a rolling max (moving max) over the values in this Series.__ @@ -144,6 +238,7 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ rollingMax(options: RollingOptions): T; rollingMax( @@ -166,6 +261,7 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ rollingMean(options: RollingOptions): T; rollingMean( @@ -188,6 +284,7 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ rollingMin(options: RollingOptions): T; rollingMin( @@ -209,6 +306,7 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ rollingStd(options: RollingOptions): T; rollingStd( @@ -231,6 +329,7 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ rollingSum(options: RollingOptions): T; rollingSum( @@ -253,6 +352,7 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ rollingVar(options: RollingOptions): T; rollingVar( @@ -261,7 +361,10 @@ export interface Rolling { minPeriods?: Array, center?: boolean, ): T; - /** Compute a rolling median */ + /** + * Compute a rolling median + * @category Rolling + */ rollingMedian(options: RollingOptions): T; rollingMedian( windowSize: number, @@ -279,16 +382,12 @@ export interface Rolling { * @param minPeriods The number of values in the window that should be non-null before computing a result. * If undefined, it will be set equal to window size. * @param center - Set the labels at the center of the window + * @category Rolling */ - rollingQuantile( - options: RollingOptions & { - quantile: number; - interpolation?: Interpolation; - }, - ): T; + rollingQuantile(options: RollingQuantileOptions): T; rollingQuantile( quantile: number, - interpolation?: Interpolation, + interpolation?: InterpolationMethod, windowSize?: number, weights?: Array, minPeriods?: Array, @@ -298,9 +397,17 @@ export interface Rolling { * Compute a rolling skew * @param windowSize Size of the rolling window * @param bias If false, then the calculations are corrected for statistical bias. + * @category Rolling */ rollingSkew(windowSize: number, bias?: boolean): T; - rollingSkew({ windowSize, bias }: { windowSize: number; bias?: boolean }): T; + /** + * Compute a rolling skew + * @param options + * @param options.windowSize Size of the rolling window + * @param options.bias If false, then the calculations are corrected for statistical bias. + * @category Rolling + */ + rollingSkew(options: RollingSkewOptions): T; } export interface Round { @@ -309,17 +416,20 @@ export interface Round { * * Similar functionality to javascript `toFixed` * @param decimals number of decimals to round by. + * @category Math */ round(decimals: number): T; round(options: { decimals: number }): T; /** * Floor underlying floating point array to the lowest integers smaller or equal to the float value. * Only works on floating point Series + * @category Math */ floor(): T; /** * Ceil underlying floating point array to the highest integers smaller or equal to the float value. * Only works on floating point Series + * @category Math */ ceil(): T; @@ -329,6 +439,7 @@ export interface Round { * If you want to clip other dtypes, consider writing a when -> then -> otherwise expression * @param min Minimum value * @param max Maximum value + * @category Math */ clip(min: number, max: number): T; clip(options: { min: number; max: number }); @@ -343,12 +454,12 @@ export interface Sample { * @param seed - Seed initialization. If not provided, a random seed will be used * @example * ``` - * >>> df = pl.DataFrame({ - * >>> "foo": [1, 2, 3], - * >>> "bar": [6, 7, 8], - * >>> "ham": ['a', 'b', 'c'] - * >>> }) - * >>> df.sample({n: 2}) + * > df = pl.DataFrame({ + * > "foo": [1, 2, 3], + * > "bar": [6, 7, 8], + * > "ham": ['a', 'b', 'c'] + * > }) + * > df.sample({n: 2}) * shape: (2, 3) * ╭─────┬─────┬─────╮ * │ foo ┆ bar ┆ ham │ @@ -360,6 +471,7 @@ export interface Sample { * │ 3 ┆ 8 ┆ "c" │ * ╰─────┴─────┴─────╯ * ``` + * @category Math */ sample(opts?: { @@ -385,6 +497,9 @@ export interface Bincode { getState(T): Uint8Array; } +/** + * Functions that can be applied to dtype List + */ export interface ListFunctions { argMin(): T; argMax(): T; @@ -410,6 +525,7 @@ export interface ListFunctions { * │ ["x", "y", "z"] │ * └─────────────────┘ * ``` + * @category List */ concat(other: (string | T)[] | string | T): T; /** @@ -433,6 +549,7 @@ export interface ListFunctions { * │ true │ * └───────┘ * ``` + * @category List */ contains(item: any): T; /** @@ -450,6 +567,7 @@ export interface ListFunctions { * [null, -8, -1] * ] * ``` + * @category List */ diff(n?: number, nullBehavior?: "ignore" | "drop"): T; /** @@ -457,45 +575,49 @@ export interface ListFunctions { * So index `0` would return the first item of every sublist * and index `-1` would return the last item of every sublist * if an index is out of bounds, it will return a `null`. + * @category List */ get(index: number | Expr): T; /** - Run any polars expression against the lists' elements - Parameters - ---------- - @param expr - Expression to run. Note that you can select an element with `pl.first()`, or `pl.col()` - @param parallel - Run all expression parallel. Don't activate this blindly. - Parallelism is worth it if there is enough work to do per thread. - This likely should not be use in the groupby context, because we already parallel execution per group - @example - -------- - >>> df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) - >>> df.withColumn( - ... pl.concatList(["a", "b"]).lst.eval(pl.first().rank()).alias("rank") - ... ) - shape: (3, 3) - ┌─────┬─────┬────────────┐ - │ a ┆ b ┆ rank │ - │ --- ┆ --- ┆ --- │ - │ i64 ┆ i64 ┆ list [f32] │ - ╞═════╪═════╪════════════╡ - │ 1 ┆ 4 ┆ [1.0, 2.0] │ - ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ - │ 8 ┆ 5 ┆ [2.0, 1.0] │ - ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ - │ 3 ┆ 2 ┆ [2.0, 1.0] │ - └─────┴─────┴────────────┘ + * Run any polars expression against the lists' elements + * Parameters + * ---------- + * @param expr + * Expression to run. Note that you can select an element with `pl.first()`, or `pl.col()` + * @param parallel + * Run all expression parallel. Don't activate this blindly. + * Parallelism is worth it if there is enough work to do per thread. + * This likely should not be use in the groupby context, because we already parallel execution per group + * @example + * >df = pl.DataFrame({"a": [1, 8, 3], "b": [4, 5, 2]}) + * >df.withColumn( + * ... pl.concatList(["a", "b"]).lst.eval(pl.first().rank()).alias("rank") + * ... ) + * shape: (3, 3) + * ┌─────┬─────┬────────────┐ + * │ a ┆ b ┆ rank │ + * │ --- ┆ --- ┆ --- │ + * │ i64 ┆ i64 ┆ list [f32] │ + * ╞═════╪═════╪════════════╡ + * │ 1 ┆ 4 ┆ [1.0, 2.0] │ + * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 8 ┆ 5 ┆ [2.0, 1.0] │ + * ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ + * │ 3 ┆ 2 ┆ [2.0, 1.0] │ + * └─────┴─────┴────────────┘ + * @category List */ eval(expr: Expr, parallel?: boolean): T; - /** Get the first value of the sublists. */ + /** + * Get the first value of the sublists. + * @category List + */ first(): T; /** * Slice the head of every sublist - * @param n How many values to take in the slice. + * @param n - How many values to take in the slice. * @example - * -------- + * ``` * s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]]) * s.lst.head(2) * shape: (2,) @@ -504,13 +626,15 @@ export interface ListFunctions { * [1, 2] * [10, 2] * ] + * ``` + * @category List */ head(n: number): T; /** * Slice the tail of every sublist - * @param n How many values to take in the slice. + * @param n - How many values to take in the slice. * @example - * -------- + * ``` * s = pl.Series("a", [[1, 2, 3, 4], [10, 2, 1]]) * s.lst.tail(2) * shape: (2,) @@ -519,6 +643,8 @@ export interface ListFunctions { * [3, 4] * [2, q] * ] + * ``` + * @category List */ tail(n: number): T; /** @@ -526,23 +652,74 @@ export interface ListFunctions { * This errors if inner type of list `!= Utf8`. * @param separator A string used to separate one element of the list from the next in the resulting string. * If omitted, the list elements are separated with a comma. + * @category List */ join(separator?: string): T; - /** Get the last value of the sublists. */ + /** + * Get the last value of the sublists. + * @category List + */ last(): T; + /** + * Get the length of the sublists. + * @category List + */ lengths(): T; + /** + * Get the maximum value of the sublists. + * @category List + */ max(): T; + /** + * Get the mean value of the sublists. + * @category List + */ mean(): T; + /** + * Get the median value of the sublists. + * @category List + */ min(): T; + /** + * Reverse the sublists. + * @category List + */ reverse(): T; + /** + * Shift the sublists. + * @param periods - Number of periods to shift. Can be positive or negative. + * @category List + */ shift(periods: number): T; + /** + * Slice the sublists. + * @param offset - The offset of the slice. + * @param length - The length of the slice. + * @category List + */ slice(offset: number, length: number): T; + /** + * Sort the sublists. + * @param reverse - Sort in reverse order. + * @category List + */ sort(reverse?: boolean): T; sort(opt: { reverse: boolean }): T; + /** + * Sum all elements of the sublists. + * @category List + */ sum(): T; + /** + * Get the unique values of the sublists. + * @category List + */ unique(): T; } +/** + * Functions that can be applied to a Date or Datetime column. + */ export interface DateFunctions { /** * Extract day from underlying Date representation. @@ -637,6 +814,174 @@ export interface DateFunctions { year(): T; } +export interface StringFunctions { + /** + * Vertically concat the values in the Series to a single string value. + * @example + * ``` + * > df = pl.DataFrame({"foo": [1, null, 2]}) + * > df = df.select(pl.col("foo").str.concat("-")) + * > df + * shape: (1, 1) + * ┌──────────┐ + * │ foo │ + * │ --- │ + * │ str │ + * ╞══════════╡ + * │ 1-null-2 │ + * └──────────┘ + * ``` + */ + concat(delimiter: string): T; + /** Check if strings in Series contain regex pattern. */ + contains(pat: string | RegExp): T; + /** + * Decodes a value using the provided encoding + * @param encoding - hex | base64 + * @param strict - how to handle invalid inputs + * + * - true: method will throw error if unable to decode a value + * - false: unhandled values will be replaced with `null` + * @example + * ``` + * > df = pl.DataFrame({"strings": ["666f6f", "626172", null]}) + * > df.select(col("strings").str.decode("hex")) + * shape: (3, 1) + * ┌─────────┐ + * │ strings │ + * │ --- │ + * │ str │ + * ╞═════════╡ + * │ foo │ + * ├╌╌╌╌╌╌╌╌╌┤ + * │ bar │ + * ├╌╌╌╌╌╌╌╌╌┤ + * │ null │ + * └─────────┘ + * ``` + */ + decode(encoding: "hex" | "base64", strict?: boolean): T; + decode(options: { encoding: "hex" | "base64"; strict?: boolean }): T; + /** + * Encodes a value using the provided encoding + * @param encoding - hex | base64 + * @example + * ``` + * > df = pl.DataFrame({"strings", ["foo", "bar", null]}) + * > df.select(col("strings").str.encode("hex")) + * shape: (3, 1) + * ┌─────────┐ + * │ strings │ + * │ --- │ + * │ str │ + * ╞═════════╡ + * │ 666f6f │ + * ├╌╌╌╌╌╌╌╌╌┤ + * │ 626172 │ + * ├╌╌╌╌╌╌╌╌╌┤ + * │ null │ + * └─────────┘ + * ``` + */ + encode(encoding: "hex" | "base64"): T; + /** + * Extract the target capture group from provided patterns. + * @param pattern A valid regex pattern + * @param groupIndex Index of the targeted capture group. + * Group 0 mean the whole pattern, first group begin at index 1 + * Default to the first capture group + * @returns Utf8 array. Contain null if original value is null or regex capture nothing. + * @example + * ``` + * > df = pl.DataFrame({ + * ... 'a': [ + * ... 'http://vote.com/ballon_dor?candidate=messi&ref=polars', + * ... 'http://vote.com/ballon_dor?candidat=jorginho&ref=polars', + * ... 'http://vote.com/ballon_dor?candidate=ronaldo&ref=polars' + * ... ]}) + * > df.select(pl.col('a').str.extract(/candidate=(\w+)/, 1)) + * shape: (3, 1) + * ┌─────────┐ + * │ a │ + * │ --- │ + * │ str │ + * ╞═════════╡ + * │ messi │ + * ├╌╌╌╌╌╌╌╌╌┤ + * │ null │ + * ├╌╌╌╌╌╌╌╌╌┤ + * │ ronaldo │ + * └─────────┘ + * ``` + */ + extract(pat: string | RegExp, groupIndex: number): T; + /** + * Extract the first match of json string with provided JSONPath expression. + * Throw errors if encounter invalid json strings. + * All return value will be casted to Utf8 regardless of the original value. + * @see https://goessner.net/articles/JsonPath/ + * @param jsonPath - A valid JSON path query string + * @returns Utf8 array. Contain null if original value is null or the `jsonPath` return nothing. + * @example + * ``` + * > df = pl.DataFrame({ + * ... 'json_val': [ + * ... '{"a":"1"}', + * ... null, + * ... '{"a":2}', + * ... '{"a":2.1}', + * ... '{"a":true}' + * ... ] + * ... }) + * > df.select(pl.col('json_val').str.jsonPathMatch('$.a') + * shape: (5,) + * Series: 'json_val' [str] + * [ + * "1" + * null + * "2" + * "2.1" + * "true" + * ] + * ``` + */ + jsonPathMatch(pat: string): T; + /** Get length of the string values in the Series. */ + lengths(): T; + /** Remove leading whitespace. */ + lstrip(): T; + /** Replace first regex match with a string value. */ + replace(pat: string | RegExp, val: string): T; + /** Replace all regex matches with a string value. */ + replaceAll(pat: string | RegExp, val: string): T; + /** Modify the strings to their lowercase equivalent. */ + toLowerCase(): T; + /** Modify the strings to their uppercase equivalent. */ + toUpperCase(): T; + /** Remove trailing whitespace. */ + rstrip(): T; + /** + * Create subslices of the string values of a Utf8 Series. + * @param start - Start of the slice (negative indexing may be used). + * @param length - Optional length of the slice. + */ + slice(start: number, length?: number): T; + /** + * Split a string into substrings using the specified separator and return them as a Series. + * @param separator — A string that identifies character or characters to use in separating the string. + * @param inclusive Include the split character/string in the results + */ + split(by: string, options?: { inclusive?: boolean } | boolean): T; + /** Remove leading and trailing whitespace. */ + strip(): T; + /** + * Parse a Series of dtype Utf8 to a Date/Datetime Series. + * @param datatype Date or Datetime. + * @param fmt formatting syntax. [Read more](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html) + */ + strptime(datatype: DataType.Date | DataType.Datetime, fmt?: string): T; +} + export interface Serialize { /** * Serializes object to desired format via [serde](https://serde.rs/) @@ -656,6 +1001,9 @@ export interface Deserialize { deserialize(buf: Buffer, format: "json" | "bincode"): T; } +/** + * GroupBy operations that can be applied to a DataFrame or LazyFrame. + */ export interface GroupByOps { /** Create rolling groups based on a time column (or index value of type Int32, Int64). @@ -703,7 +1051,7 @@ export interface GroupByOps { @example ``` - >>> dates = [ + >dates = [ ... "2020-01-01 13:45:48", ... "2020-01-01 16:42:13", ... "2020-01-01 16:45:09", @@ -711,20 +1059,20 @@ export interface GroupByOps { ... "2020-01-03 19:45:32", ... "2020-01-08 23:16:43", ... ] - >>> df = pl.DataFrame({"dt": dates, "a": [3, 7, 5, 9, 2, 1]}).withColumn( + >df = pl.DataFrame({"dt": dates, "a": [3, 7, 5, 9, 2, 1]}).withColumn( ... pl.col("dt").str.strptime(pl.Datetime) ... ) - >>> out = df.groupbyRolling({indexColumn:"dt", period:"2d"}).agg( + >out = df.groupbyRolling({indexColumn:"dt", period:"2d"}).agg( ... [ ... pl.sum("a").alias("sum_a"), ... pl.min("a").alias("min_a"), ... pl.max("a").alias("max_a"), ... ] ... ) - >>> assert(out["sum_a"].toArray() === [3, 10, 15, 24, 11, 1]) - >>> assert(out["max_a"].toArray() === [3, 7, 7, 9, 9, 1]) - >>> assert(out["min_a"].toArray() === [3, 3, 3, 3, 2, 1]) - >>> out + >assert(out["sum_a"].toArray() === [3, 10, 15, 24, 11, 1]) + >assert(out["max_a"].toArray() === [3, 7, 7, 9, 9, 1]) + >assert(out["min_a"].toArray() === [3, 3, 3, 3, 2, 1]) + >out shape: (6, 4) ┌─────────────────────┬───────┬───────┬───────┐ │ dt ┆ a_sum ┆ a_max ┆ a_min │ diff --git a/polars/types.ts b/polars/types.ts new file mode 100644 index 000000000..1f25d341d --- /dev/null +++ b/polars/types.ts @@ -0,0 +1,215 @@ +/** + * Downsample rules + */ +export type DownsampleRule = + | "month" + | "week" + | "day" + | "hour" + | "minute" + | "second"; +/** + * Fill null strategies + */ +export type FillNullStrategy = + | "backward" + | "forward" + | "mean" + | "min" + | "max" + | "zero" + | "one"; + +/** + * Rank methods + */ +export type RankMethod = + | "average" + | "min" + | "max" + | "dense" + | "ordinal" + | "random"; + +/** + * Options for {@link concat} + */ +export interface ConcatOptions { + rechunk?: boolean; + how?: "vertical" | "horizontal"; +} +/** + * Options for {@link DataFrame.writeCSV} + * @category Options + */ +export interface WriteCsvOptions { + hasHeader?: boolean; + sep?: string; +} + +/** + * Options for {@link DataFrame.writeJSON} + * @category Options + */ +export interface WriteJsonOptions { + orient?: "row" | "col" | "dataframe"; + multiline?: boolean; +} + +/** + * Options for {@link scanJson} + */ +export interface JsonScanOptions { + inferSchemaLength?: number; + nThreads?: number; + batchSize?: number; + lowMemory?: boolean; + numRows?: number; + skipRows?: number; + rowCount?: RowCount; +} + +/** + * Options for {@link DataFrame.writeParquet} + * @category Options + */ +export interface WriteParquetOptions { + compression?: + | "uncompressed" + | "snappy" + | "gzip" + | "lzo" + | "brotli" + | "lz4" + | "zstd"; +} +/** + * Options for {@link readParquet} + */ +export interface ReadParquetOptions { + columns?: string[] | number[]; + numRows?: number; + parallel?: "auto" | "columns" | "row_groups" | "none"; + rowCount?: RowCount; +} +/** + * Options for {@link scanParquet} + */ +export interface ScanParquetOptions { + columns?: string[] | number[]; + numRows?: number; + parallel?: "auto" | "columns" | "row_groups" | "none"; + rowCount?: RowCount; + cache?: boolean; + rechunk?: boolean; +} + +/** + * Add row count as column + */ +export interface RowCount { + /** name of column */ + name: string; + /** offset */ + offset: string; +} + +/** + * Options for {@link DataFrame.writeIPC} + * @category Options + */ +export interface WriteIPCOptions { + compression?: "uncompressed" | "lz4" | "zstd"; +} + +/** + * Options for writing Avro files + * @category Options + */ +export interface WriteAvroOptions { + compression?: "uncompressed" | "snappy" | "deflate"; +} + +/** + * Interpolation types + */ +export type InterpolationMethod = + | "nearest" + | "higher" + | "lower" + | "midpoint" + | "linear"; + +/** + * Join types + */ +export type JoinType = "left" | "inner" | "outer" | "semi" | "anti" | "cross"; + +/** @ignore */ +export type JoinBaseOptions = { + how?: JoinType; + suffix?: string; +}; +/** + * options for join operations @see {@link DataFrame.join} + */ +export interface JoinOptions { + /** left join column */ + leftOn?: string | Array; + /** right join column */ + rightOn?: string | Array; + /** left and right join column */ + on?: string | Array; + /** join type */ + how?: JoinType; + suffix?: string; +} + +/** + * options for lazy join operations @see {@link LazyDataFrame.join} + */ +export interface LazyJoinOptions extends JoinOptions { + allowParallel?: boolean; + forceParallel?: boolean; +} + +/** + * options for lazy operations @see {@link LazyDataFrame.collect} + */ +export type LazyOptions = { + typeCoercion?: boolean; + predicatePushdown?: boolean; + projectionPushdown?: boolean; + simplifyExpression?: boolean; + stringCache?: boolean; + noOptimization?: boolean; +}; + +/** + * options for rolling window operations + * @category Options + */ +export interface RollingOptions { + windowSize: number; + weights?: Array; + minPeriods?: number; + center?: boolean; +} + +/** + * options for rolling quantile operations + * @category Options + */ +export interface RollingQuantileOptions extends RollingOptions { + quantile: number; + interpolation?: InterpolationMethod; +} + +/** + * options for rolling mean operations + * @category Options + */ +export interface RollingSkewOptions { + windowSize: number; + bias?: boolean; +} diff --git a/polars/utils.ts b/polars/utils.ts index a2285be5e..e33c9f659 100644 --- a/polars/utils.ts +++ b/polars/utils.ts @@ -1,39 +1,45 @@ -import {Expr, exprToLitOrExpr} from "./lazy/expr"; -import {Series} from "./series/series"; -import {DataFrame} from "./dataframe"; +import { Expr, exprToLitOrExpr } from "./lazy/expr"; +import { Series } from "./series"; +import { DataFrame } from "./dataframe"; import path from "path"; -import {isExternal, isRegExp} from "util/types"; +import { isExternal, isRegExp } from "util/types"; +/** @ignore */ export type ValueOrArray = T | Array>; -export type ColumnSelection = ValueOrArray -export type ExpressionSelection = ValueOrArray -export type ColumnsOrExpr = ColumnSelection | ExpressionSelection -export type ExprOrString = Expr | string -export type DownsampleRule = "month" | "week" | "day" | "hour" | "minute" | "second" -export type FillNullStrategy = "backward" | "forward" | "mean" | "min" | "max" | "zero" | "one" -export type RankMethod = "average" | "min" | "max" | "dense" | "ordinal" | "random"; -export type RollingOptions = { - windowSize: number, - weights?: Array, - minPeriods?: number, - center?: boolean -}; +/** @ignore */ +export type ColumnSelection = ValueOrArray; +/** @ignore */ +export type ExpressionSelection = ValueOrArray; +/** @ignore */ +export type ColumnsOrExpr = ColumnSelection | ExpressionSelection; +/** @ignore */ +export type ExprOrString = Expr | string; -export function columnOrColumns(columns: ColumnSelection | string | Array | undefined): Array | undefined { +/** @ignore */ +export function columnOrColumns( + columns: ColumnSelection | string | Array | undefined, +): Array | undefined { if (columns) { return columnOrColumnsStrict(columns); } } -export function columnOrColumnsStrict(...columns: string[] | ValueOrArray[]): Array { +/** @ignore */ +export function columnOrColumnsStrict( + ...columns: string[] | ValueOrArray[] +): Array { return columns.flat(3) as any; } +/** @ignore */ export function selectionToExprList(columns: any[], stringToLit?) { - return [columns].flat(3).map(expr => exprToLitOrExpr(expr, stringToLit)._expr); + return [columns] + .flat(3) + .map((expr) => exprToLitOrExpr(expr, stringToLit)._expr); } +/** @ignore */ export function isPath(s: string, expectedExtensions?: string[]): boolean { - const {base, ext, name} = path.parse(s); + const { base, ext, name } = path.parse(s); - return Boolean(base && ext && name) && !!(expectedExtensions?.includes(ext)); + return Boolean(base && ext && name) && !!expectedExtensions?.includes(ext); } export const range = (start: number, end: number) => { @@ -42,13 +48,16 @@ export const range = (start: number, end: number) => { return Array.from({ length }, (_, i) => start + i); }; - -export const isDataFrameArray = (ty: any): ty is DataFrame[] => Array.isArray(ty) && DataFrame.isDataFrame(ty[0]); -export const isSeriesArray = (ty: any): ty is Series[] => Array.isArray(ty) && Series.isSeries(ty[0]); -export const isExprArray = (ty: any): ty is Expr[] => Array.isArray(ty) && Expr.isExpr(ty[0]); -export const isIterator = (ty: any): ty is Iterable => ty !== null && typeof ty[Symbol.iterator] === "function"; +export const isDataFrameArray = (ty: any): ty is DataFrame[] => + Array.isArray(ty) && DataFrame.isDataFrame(ty[0]); +export const isSeriesArray = (ty: any): ty is Series[] => + Array.isArray(ty) && Series.isSeries(ty[0]); +export const isExprArray = (ty: any): ty is Expr[] => + Array.isArray(ty) && Expr.isExpr(ty[0]); +export const isIterator = (ty: any): ty is Iterable => + ty !== null && typeof ty[Symbol.iterator] === "function"; export const regexToString = (r: string | RegExp): string => { - if(isRegExp(r)) { + if (isRegExp(r)) { return r.source; } diff --git a/rome.json b/rome.json new file mode 100644 index 000000000..e701a4932 --- /dev/null +++ b/rome.json @@ -0,0 +1,30 @@ +{ + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "suspicious": { + "noExplicitAny": "off" + } + }, + "ignore": [ + "polars/native-polars.js", + "./docs/*", + "./bin/*" + ] + }, + "formatter": { + "indentSize": 2, + "indentStyle": "space", + "ignore": [ + "polars/native-polars.js", + "./docs/*", + "./bin/*" + ] + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + } +} \ No newline at end of file diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index c9595a36f..000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly-2022-11-24 \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..270b314ac --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2022-11-24" \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 6b656330d..e4b5e893c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,7 @@ } }, "exclude": [ + "./target/*", "./docs/*", "./coverage/*", "./examples/*", @@ -31,22 +32,15 @@ "./jest.config.ts" ], "typedocOptions": { + "entryPointStrategy": "expand", "excludePrivate": true, + "excludeProtected": true, + "excludeExternals": true, + "categorizeByGroup": true, "entryPoints": [ - "polars/series/series.ts", - "polars/dataframe.ts", - "polars/groupby.ts", - "polars/io.ts", - "polars/cfg.ts", - "polars/lazy/expr.ts", - "polars/lazy/dataframe.ts", - "polars/lazy/functions.ts", - "polars/lazy/groupby.ts", - "polars/lazy/whenthen.ts", - "polars/series/datetime.ts", - "polars/series/string.ts", - "polars/series/list.ts" + "polars/index.ts" ], - "out": "docs" + "out": "docs", + "sort": ["alphabetical"] } } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index adffcd0ff..7c2b31988 100644 --- a/yarn.lock +++ b/yarn.lock @@ -406,23 +406,6 @@ __metadata: languageName: node linkType: hard -"@eslint/eslintrc@npm:^1.4.0": - version: 1.4.0 - resolution: "@eslint/eslintrc@npm:1.4.0" - dependencies: - ajv: ^6.12.4 - debug: ^4.3.2 - espree: ^9.4.0 - globals: ^13.19.0 - ignore: ^5.2.0 - import-fresh: ^3.2.1 - js-yaml: ^4.1.0 - minimatch: ^3.1.2 - strip-json-comments: ^3.1.1 - checksum: 73e39c833deafde8d8706e6fa9b52b6d99927c094ead8e405ea4174e8197ec24aac9ba88ae38cc8ad32eaccf07b9c7fc5dc70761d1fba6da41a928691447305f - languageName: node - linkType: hard - "@gar/promisify@npm:^1.1.3": version: 1.1.3 resolution: "@gar/promisify@npm:1.1.3" @@ -430,31 +413,6 @@ __metadata: languageName: node linkType: hard -"@humanwhocodes/config-array@npm:^0.11.8": - version: 0.11.8 - resolution: "@humanwhocodes/config-array@npm:0.11.8" - dependencies: - "@humanwhocodes/object-schema": ^1.2.1 - debug: ^4.1.1 - minimatch: ^3.0.5 - checksum: 0fd6b3c54f1674ce0a224df09b9c2f9846d20b9e54fabae1281ecfc04f2e6ad69bf19e1d6af6a28f88e8aa3990168b6cb9e1ef755868c3256a630605ec2cb1d3 - languageName: node - linkType: hard - -"@humanwhocodes/module-importer@npm:^1.0.1": - version: 1.0.1 - resolution: "@humanwhocodes/module-importer@npm:1.0.1" - checksum: 0fd22007db8034a2cdf2c764b140d37d9020bbfce8a49d3ec5c05290e77d4b0263b1b972b752df8c89e5eaa94073408f2b7d977aed131faf6cf396ebb5d7fb61 - languageName: node - linkType: hard - -"@humanwhocodes/object-schema@npm:^1.2.1": - version: 1.2.1 - resolution: "@humanwhocodes/object-schema@npm:1.2.1" - checksum: a824a1ec31591231e4bad5787641f59e9633827d0a2eaae131a288d33c9ef0290bd16fda8da6f7c0fcb014147865d12118df10db57f27f41e20da92369fcb3f1 - languageName: node - linkType: hard - "@istanbuljs/load-nyc-config@npm:^1.0.0": version: 1.1.0 resolution: "@istanbuljs/load-nyc-config@npm:1.1.0" @@ -747,33 +705,6 @@ __metadata: languageName: node linkType: hard -"@nodelib/fs.scandir@npm:2.1.5": - version: 2.1.5 - resolution: "@nodelib/fs.scandir@npm:2.1.5" - dependencies: - "@nodelib/fs.stat": 2.0.5 - run-parallel: ^1.1.9 - checksum: a970d595bd23c66c880e0ef1817791432dbb7acbb8d44b7e7d0e7a22f4521260d4a83f7f9fd61d44fda4610105577f8f58a60718105fb38352baed612fd79e59 - languageName: node - linkType: hard - -"@nodelib/fs.stat@npm:2.0.5, @nodelib/fs.stat@npm:^2.0.2": - version: 2.0.5 - resolution: "@nodelib/fs.stat@npm:2.0.5" - checksum: 012480b5ca9d97bff9261571dbbec7bbc6033f69cc92908bc1ecfad0792361a5a1994bc48674b9ef76419d056a03efadfce5a6cf6dbc0a36559571a7a483f6f0 - languageName: node - linkType: hard - -"@nodelib/fs.walk@npm:^1.2.3, @nodelib/fs.walk@npm:^1.2.8": - version: 1.2.8 - resolution: "@nodelib/fs.walk@npm:1.2.8" - dependencies: - "@nodelib/fs.scandir": 2.1.5 - fastq: ^1.6.0 - checksum: 190c643f156d8f8f277bf2a6078af1ffde1fd43f498f187c2db24d35b4b4b5785c02c7dc52e356497b9a1b65b13edc996de08de0b961c32844364da02986dc53 - languageName: node - linkType: hard - "@npmcli/fs@npm:^2.1.0": version: 2.1.2 resolution: "@npmcli/fs@npm:2.1.2" @@ -794,6 +725,48 @@ __metadata: languageName: node linkType: hard +"@rometools/cli-darwin-arm64@npm:11.0.0": + version: 11.0.0 + resolution: "@rometools/cli-darwin-arm64@npm:11.0.0" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@rometools/cli-darwin-x64@npm:11.0.0": + version: 11.0.0 + resolution: "@rometools/cli-darwin-x64@npm:11.0.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@rometools/cli-linux-arm64@npm:11.0.0": + version: 11.0.0 + resolution: "@rometools/cli-linux-arm64@npm:11.0.0" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"@rometools/cli-linux-x64@npm:11.0.0": + version: 11.0.0 + resolution: "@rometools/cli-linux-x64@npm:11.0.0" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@rometools/cli-win32-arm64@npm:11.0.0": + version: 11.0.0 + resolution: "@rometools/cli-win32-arm64@npm:11.0.0" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"@rometools/cli-win32-x64@npm:11.0.0": + version: 11.0.0 + resolution: "@rometools/cli-win32-x64@npm:11.0.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@sinonjs/commons@npm:^1.7.0": version: 1.8.6 resolution: "@sinonjs/commons@npm:1.8.6" @@ -946,20 +919,6 @@ __metadata: languageName: node linkType: hard -"@types/json-schema@npm:^7.0.9": - version: 7.0.11 - resolution: "@types/json-schema@npm:7.0.11" - checksum: 527bddfe62db9012fccd7627794bd4c71beb77601861055d87e3ee464f2217c85fca7a4b56ae677478367bbd248dbde13553312b7d4dbc702a2f2bbf60c4018d - languageName: node - linkType: hard - -"@types/json5@npm:^0.0.29": - version: 0.0.29 - resolution: "@types/json5@npm:0.0.29" - checksum: e60b153664572116dfea673c5bda7778dbff150498f44f998e34b5886d8afc47f16799280e4b6e241c0472aef1bc36add771c569c68fc5125fc2ae519a3eb9ac - languageName: node - linkType: hard - "@types/node@npm:*": version: 18.11.17 resolution: "@types/node@npm:18.11.17" @@ -974,13 +933,6 @@ __metadata: languageName: node linkType: hard -"@types/parse-json@npm:^4.0.0": - version: 4.0.0 - resolution: "@types/parse-json@npm:4.0.0" - checksum: fd6bce2b674b6efc3db4c7c3d336bd70c90838e8439de639b909ce22f3720d21344f52427f1d9e57b265fcb7f6c018699b99e5e0c208a1a4823014269a6bf35b - languageName: node - linkType: hard - "@types/prettier@npm:^2.1.5": version: 2.7.2 resolution: "@types/prettier@npm:2.7.2" @@ -988,13 +940,6 @@ __metadata: languageName: node linkType: hard -"@types/semver@npm:^7.3.12": - version: 7.3.13 - resolution: "@types/semver@npm:7.3.13" - checksum: 00c0724d54757c2f4bc60b5032fe91cda6410e48689633d5f35ece8a0a66445e3e57fa1d6e07eb780f792e82ac542948ec4d0b76eb3484297b79bd18b8cf1cb0 - languageName: node - linkType: hard - "@types/stack-utils@npm:^2.0.0": version: 2.0.1 resolution: "@types/stack-utils@npm:2.0.1" @@ -1018,137 +963,6 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:^5.4.0": - version: 5.47.0 - resolution: "@typescript-eslint/eslint-plugin@npm:5.47.0" - dependencies: - "@typescript-eslint/scope-manager": 5.47.0 - "@typescript-eslint/type-utils": 5.47.0 - "@typescript-eslint/utils": 5.47.0 - debug: ^4.3.4 - ignore: ^5.2.0 - natural-compare-lite: ^1.4.0 - regexpp: ^3.2.0 - semver: ^7.3.7 - tsutils: ^3.21.0 - peerDependencies: - "@typescript-eslint/parser": ^5.0.0 - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - peerDependenciesMeta: - typescript: - optional: true - checksum: fd867eb2b668d1f476fd28d38c2df2a680bf510a265a6e714b28d8f77e7a37e74e32294b70262a6fd1aec99ddb2fddef0212c862b4465ca4f83bb1172476f6e7 - languageName: node - linkType: hard - -"@typescript-eslint/experimental-utils@npm:^5.0.0": - version: 5.47.0 - resolution: "@typescript-eslint/experimental-utils@npm:5.47.0" - dependencies: - "@typescript-eslint/utils": 5.47.0 - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: 75b8a47d3881f0a1ca5fd52ba757b5de499f2a898ddf4b6c2def5a9bd6176770e1995198ddd49370023f5fe088ad26d544b1ddfc5883e6dce06ae9fc8297c8c3 - languageName: node - linkType: hard - -"@typescript-eslint/parser@npm:^5.4.0": - version: 5.47.0 - resolution: "@typescript-eslint/parser@npm:5.47.0" - dependencies: - "@typescript-eslint/scope-manager": 5.47.0 - "@typescript-eslint/types": 5.47.0 - "@typescript-eslint/typescript-estree": 5.47.0 - debug: ^4.3.4 - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - peerDependenciesMeta: - typescript: - optional: true - checksum: 5c864ca74b86ca740c73e5b87d90d43bb832b20ba6be0a39089175435771527722a7bf0a8ef7ddbd64b85235fbb7f6dbe8ae55a8bc73c6242f5559d580a8a80c - languageName: node - linkType: hard - -"@typescript-eslint/scope-manager@npm:5.47.0": - version: 5.47.0 - resolution: "@typescript-eslint/scope-manager@npm:5.47.0" - dependencies: - "@typescript-eslint/types": 5.47.0 - "@typescript-eslint/visitor-keys": 5.47.0 - checksum: f637268a4cb065a89bb53d72620cc553f8c0d9f00805d6e6aac558cc4d3c08f3329208b0b4d5566d21eb636b080d453e5890221baef0e4bc4d67251f07cccd0d - languageName: node - linkType: hard - -"@typescript-eslint/type-utils@npm:5.47.0": - version: 5.47.0 - resolution: "@typescript-eslint/type-utils@npm:5.47.0" - dependencies: - "@typescript-eslint/typescript-estree": 5.47.0 - "@typescript-eslint/utils": 5.47.0 - debug: ^4.3.4 - tsutils: ^3.21.0 - peerDependencies: - eslint: "*" - peerDependenciesMeta: - typescript: - optional: true - checksum: 504b3e883ac02cb8e69957b706e76cb79fa2192aa62702c2a658119f28f8f50f1e668efb62318e85aeda6522e1d948b59382cae4ef3300a3f4eea809a87dec26 - languageName: node - linkType: hard - -"@typescript-eslint/types@npm:5.47.0": - version: 5.47.0 - resolution: "@typescript-eslint/types@npm:5.47.0" - checksum: 5a856e190cc2103427dbe15ccbbf87238261b5ed0859390a9e55f93afc2057f79dcbb4ac0db4d35787466f5e73f271111d19b2e725cf444af41d30e09678bf7a - languageName: node - linkType: hard - -"@typescript-eslint/typescript-estree@npm:5.47.0": - version: 5.47.0 - resolution: "@typescript-eslint/typescript-estree@npm:5.47.0" - dependencies: - "@typescript-eslint/types": 5.47.0 - "@typescript-eslint/visitor-keys": 5.47.0 - debug: ^4.3.4 - globby: ^11.1.0 - is-glob: ^4.0.3 - semver: ^7.3.7 - tsutils: ^3.21.0 - peerDependenciesMeta: - typescript: - optional: true - checksum: a9adfe8955b7dc9dfa9f43d450b782b83f506eaadae2a13f4e1bbe6c733be446d3edb26910954aec1bdc60d94ecc55c4e200d5b19bb24e6742f02329a4fb3e8c - languageName: node - linkType: hard - -"@typescript-eslint/utils@npm:5.47.0": - version: 5.47.0 - resolution: "@typescript-eslint/utils@npm:5.47.0" - dependencies: - "@types/json-schema": ^7.0.9 - "@types/semver": ^7.3.12 - "@typescript-eslint/scope-manager": 5.47.0 - "@typescript-eslint/types": 5.47.0 - "@typescript-eslint/typescript-estree": 5.47.0 - eslint-scope: ^5.1.1 - eslint-utils: ^3.0.0 - semver: ^7.3.7 - peerDependencies: - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: f168920eec6f77651107f190b4ecadd82951fe4e3c0321ff660ac7380f4315d5ae30a1b63b4d2818f5e6f007a3f34c5df202619c24ec3a7e2ef25b215ec7b813 - languageName: node - linkType: hard - -"@typescript-eslint/visitor-keys@npm:5.47.0": - version: 5.47.0 - resolution: "@typescript-eslint/visitor-keys@npm:5.47.0" - dependencies: - "@typescript-eslint/types": 5.47.0 - eslint-visitor-keys: ^3.3.0 - checksum: 2191c079154bdfd1b85b8cd24baa6c0f55c73527c6c8460789483555b4eb5c72e3dc6d1aa4bbac2cf7b86b474588b45682a8deb151e9d903cf72c8f336141f1f - languageName: node - linkType: hard - "abab@npm:^2.0.3, abab@npm:^2.0.5": version: 2.0.6 resolution: "abab@npm:2.0.6" @@ -1173,15 +987,6 @@ __metadata: languageName: node linkType: hard -"acorn-jsx@npm:^5.3.2": - version: 5.3.2 - resolution: "acorn-jsx@npm:5.3.2" - peerDependencies: - acorn: ^6.0.0 || ^7.0.0 || ^8.0.0 - checksum: c3d3b2a89c9a056b205b69530a37b972b404ee46ec8e5b341666f9513d3163e2a4f214a71f4dfc7370f5a9c07472d2fd1c11c91c3f03d093e37637d95da98950 - languageName: node - linkType: hard - "acorn-walk@npm:^7.1.1": version: 7.2.0 resolution: "acorn-walk@npm:7.2.0" @@ -1205,7 +1010,7 @@ __metadata: languageName: node linkType: hard -"acorn@npm:^8.2.4, acorn@npm:^8.4.1, acorn@npm:^8.8.0": +"acorn@npm:^8.2.4, acorn@npm:^8.4.1": version: 8.8.1 resolution: "acorn@npm:8.8.1" bin: @@ -1244,26 +1049,7 @@ __metadata: languageName: node linkType: hard -"ajv@npm:^6.10.0, ajv@npm:^6.12.4": - version: 6.12.6 - resolution: "ajv@npm:6.12.6" - dependencies: - fast-deep-equal: ^3.1.1 - fast-json-stable-stringify: ^2.0.0 - json-schema-traverse: ^0.4.1 - uri-js: ^4.2.2 - checksum: 874972efe5c4202ab0a68379481fbd3d1b5d0a7bd6d3cc21d40d3536ebff3352a2a1fabb632d4fd2cc7fe4cbdcd5ed6782084c9bbf7f32a1536d18f9da5007d4 - languageName: node - linkType: hard - -"ansi-colors@npm:^4.1.1": - version: 4.1.3 - resolution: "ansi-colors@npm:4.1.3" - checksum: a9c2ec842038a1fabc7db9ece7d3177e2fe1c5dc6f0c51ecfbf5f39911427b89c00b5dc6b8bd95f82a26e9b16aaae2e83d45f060e98070ce4d1333038edceb0e - languageName: node - linkType: hard - -"ansi-escapes@npm:^4.2.1, ansi-escapes@npm:^4.3.0": +"ansi-escapes@npm:^4.2.1": version: 4.3.2 resolution: "ansi-escapes@npm:4.3.2" dependencies: @@ -1347,52 +1133,6 @@ __metadata: languageName: node linkType: hard -"argparse@npm:^2.0.1": - version: 2.0.1 - resolution: "argparse@npm:2.0.1" - checksum: 83644b56493e89a254bae05702abf3a1101b4fa4d0ca31df1c9985275a5a5bd47b3c27b7fa0b71098d41114d8ca000e6ed90cad764b306f8a503665e4d517ced - languageName: node - linkType: hard - -"array-includes@npm:^3.1.4": - version: 3.1.6 - resolution: "array-includes@npm:3.1.6" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.4 - es-abstract: ^1.20.4 - get-intrinsic: ^1.1.3 - is-string: ^1.0.7 - checksum: f22f8cd8ba8a6448d91eebdc69f04e4e55085d09232b5216ee2d476dab3ef59984e8d1889e662c6a0ed939dcb1b57fd05b2c0209c3370942fc41b752c82a2ca5 - languageName: node - linkType: hard - -"array-union@npm:^2.1.0": - version: 2.1.0 - resolution: "array-union@npm:2.1.0" - checksum: 5bee12395cba82da674931df6d0fea23c4aa4660cb3b338ced9f828782a65caa232573e6bf3968f23e0c5eb301764a382cef2f128b170a9dc59de0e36c39f98d - languageName: node - linkType: hard - -"array.prototype.flat@npm:^1.2.5": - version: 1.3.1 - resolution: "array.prototype.flat@npm:1.3.1" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.4 - es-abstract: ^1.20.4 - es-shim-unscopables: ^1.0.0 - checksum: 5a8415949df79bf6e01afd7e8839bbde5a3581300e8ad5d8449dea52639e9e59b26a467665622783697917b43bf39940a6e621877c7dd9b3d1c1f97484b9b88b - languageName: node - linkType: hard - -"astral-regex@npm:^2.0.0": - version: 2.0.0 - resolution: "astral-regex@npm:2.0.0" - checksum: 876231688c66400473ba505731df37ea436e574dd524520294cc3bbc54ea40334865e01fa0d074d74d036ee874ee7e62f486ea38bc421ee8e6a871c06f011766 - languageName: node - linkType: hard - "asynckit@npm:^0.4.0": version: 0.4.0 resolution: "asynckit@npm:0.4.0" @@ -1593,16 +1333,6 @@ __metadata: languageName: node linkType: hard -"call-bind@npm:^1.0.0, call-bind@npm:^1.0.2": - version: 1.0.2 - resolution: "call-bind@npm:1.0.2" - dependencies: - function-bind: ^1.1.1 - get-intrinsic: ^1.0.2 - checksum: f8e31de9d19988a4b80f3e704788c4a2d6b6f3d17cfec4f57dc29ced450c53a49270dc66bf0fbd693329ee948dd33e6c90a329519aef17474a4d961e8d6426b0 - languageName: node - linkType: hard - "callsites@npm:^3.0.0": version: 3.1.0 resolution: "callsites@npm:3.1.0" @@ -1694,25 +1424,6 @@ __metadata: languageName: node linkType: hard -"cli-cursor@npm:^3.1.0": - version: 3.1.0 - resolution: "cli-cursor@npm:3.1.0" - dependencies: - restore-cursor: ^3.1.0 - checksum: 2692784c6cd2fd85cfdbd11f53aea73a463a6d64a77c3e098b2b4697a20443f430c220629e1ca3b195ea5ac4a97a74c2ee411f3807abf6df2b66211fec0c0a29 - languageName: node - linkType: hard - -"cli-truncate@npm:2.1.0, cli-truncate@npm:^2.1.0": - version: 2.1.0 - resolution: "cli-truncate@npm:2.1.0" - dependencies: - slice-ansi: ^3.0.0 - string-width: ^4.2.0 - checksum: bf1e4e6195392dc718bf9cd71f317b6300dc4a9191d052f31046b8773230ece4fa09458813bf0e3455a5e68c0690d2ea2c197d14a8b85a7b5e01c97f4b5feb5d - languageName: node - linkType: hard - "cliui@npm:^7.0.2": version: 7.0.4 resolution: "cliui@npm:7.0.4" @@ -1779,20 +1490,6 @@ __metadata: languageName: node linkType: hard -"colorette@npm:^1.4.0": - version: 1.4.0 - resolution: "colorette@npm:1.4.0" - checksum: 01c3c16058b182a4ab4c126a65a75faa4d38a20fa7c845090b25453acec6c371bb2c5dceb0a2338511f17902b9d1a9af0cadd8509c9403894b79311032c256c3 - languageName: node - linkType: hard - -"colorette@npm:^2.0.16": - version: 2.0.19 - resolution: "colorette@npm:2.0.19" - checksum: 888cf5493f781e5fcf54ce4d49e9d7d698f96ea2b2ef67906834bb319a392c667f9ec69f4a10e268d2946d13a9503d2d19b3abaaaf174e3451bfe91fb9d82427 - languageName: node - linkType: hard - "combined-stream@npm:^1.0.8": version: 1.0.8 resolution: "combined-stream@npm:1.0.8" @@ -1802,13 +1499,6 @@ __metadata: languageName: node linkType: hard -"commander@npm:^8.2.0": - version: 8.3.0 - resolution: "commander@npm:8.3.0" - checksum: 0f82321821fc27b83bd409510bb9deeebcfa799ff0bf5d102128b500b7af22872c0c92cb6a0ebc5a4cf19c6b550fba9cedfa7329d18c6442a625f851377bacf0 - languageName: node - linkType: hard - "concat-map@npm:0.0.1": version: 0.0.1 resolution: "concat-map@npm:0.0.1" @@ -1830,19 +1520,6 @@ __metadata: languageName: node linkType: hard -"cosmiconfig@npm:^7.0.1": - version: 7.1.0 - resolution: "cosmiconfig@npm:7.1.0" - dependencies: - "@types/parse-json": ^4.0.0 - import-fresh: ^3.2.1 - parse-json: ^5.0.0 - path-type: ^4.0.0 - yaml: ^1.10.0 - checksum: c53bf7befc1591b2651a22414a5e786cd5f2eeaa87f3678a3d49d6069835a9d8d1aef223728e98aa8fec9a95bf831120d245096db12abe019fecb51f5696c96f - languageName: node - linkType: hard - "create-require@npm:^1.1.0": version: 1.1.1 resolution: "create-require@npm:1.1.1" @@ -1850,7 +1527,7 @@ __metadata: languageName: node linkType: hard -"cross-spawn@npm:^7.0.2, cross-spawn@npm:^7.0.3": +"cross-spawn@npm:^7.0.3": version: 7.0.3 resolution: "cross-spawn@npm:7.0.3" dependencies: @@ -1895,7 +1572,7 @@ __metadata: languageName: node linkType: hard -"debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.2, debug@npm:^4.3.3, debug@npm:^4.3.4": +"debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.3": version: 4.3.4 resolution: "debug@npm:4.3.4" dependencies: @@ -1907,24 +1584,6 @@ __metadata: languageName: node linkType: hard -"debug@npm:^2.6.9": - version: 2.6.9 - resolution: "debug@npm:2.6.9" - dependencies: - ms: 2.0.0 - checksum: d2f51589ca66df60bf36e1fa6e4386b318c3f1e06772280eea5b1ae9fd3d05e9c2b7fd8a7d862457d00853c75b00451aa2d7459b924629ee385287a650f58fe6 - languageName: node - linkType: hard - -"debug@npm:^3.2.7": - version: 3.2.7 - resolution: "debug@npm:3.2.7" - dependencies: - ms: ^2.1.1 - checksum: b3d8c5940799914d30314b7c3304a43305fd0715581a919dacb8b3176d024a782062368405b47491516d2091d6462d4d11f2f4974a405048094f8bfebfa3071c - languageName: node - linkType: hard - "decimal.js@npm:^10.2.1": version: 10.4.3 resolution: "decimal.js@npm:10.4.3" @@ -1939,7 +1598,7 @@ __metadata: languageName: node linkType: hard -"deep-is@npm:^0.1.3, deep-is@npm:~0.1.3": +"deep-is@npm:~0.1.3": version: 0.1.4 resolution: "deep-is@npm:0.1.4" checksum: edb65dd0d7d1b9c40b2f50219aef30e116cedd6fc79290e740972c132c09106d2e80aa0bc8826673dd5a00222d4179c84b36a790eef63a4c4bca75a37ef90804 @@ -1953,16 +1612,6 @@ __metadata: languageName: node linkType: hard -"define-properties@npm:^1.1.3, define-properties@npm:^1.1.4": - version: 1.1.4 - resolution: "define-properties@npm:1.1.4" - dependencies: - has-property-descriptors: ^1.0.0 - object-keys: ^1.1.1 - checksum: ce0aef3f9eb193562b5cfb79b2d2c86b6a109dfc9fdcb5f45d680631a1a908c06824ddcdb72b7573b54e26ace07f0a23420aaba0d5c627b34d2c1de8ef527e2b - languageName: node - linkType: hard - "delayed-stream@npm:~1.0.0": version: 1.0.0 resolution: "delayed-stream@npm:1.0.0" @@ -2005,33 +1654,6 @@ __metadata: languageName: node linkType: hard -"dir-glob@npm:^3.0.1": - version: 3.0.1 - resolution: "dir-glob@npm:3.0.1" - dependencies: - path-type: ^4.0.0 - checksum: fa05e18324510d7283f55862f3161c6759a3f2f8dbce491a2fc14c8324c498286c54282c1f0e933cb930da8419b30679389499b919122952a4f8592362ef4615 - languageName: node - linkType: hard - -"doctrine@npm:^2.1.0": - version: 2.1.0 - resolution: "doctrine@npm:2.1.0" - dependencies: - esutils: ^2.0.2 - checksum: a45e277f7feaed309fe658ace1ff286c6e2002ac515af0aaf37145b8baa96e49899638c7cd47dccf84c3d32abfc113246625b3ac8f552d1046072adee13b0dc8 - languageName: node - linkType: hard - -"doctrine@npm:^3.0.0": - version: 3.0.0 - resolution: "doctrine@npm:3.0.0" - dependencies: - esutils: ^2.0.2 - checksum: fd7673ca77fe26cd5cba38d816bc72d641f500f1f9b25b83e8ce28827fe2da7ad583a8da26ab6af85f834138cf8dae9f69b0cd6ab925f52ddab1754db44d99ce - languageName: node - linkType: hard - "domexception@npm:^2.0.1": version: 2.0.1 resolution: "domexception@npm:2.0.1" @@ -2071,15 +1693,6 @@ __metadata: languageName: node linkType: hard -"enquirer@npm:^2.3.6": - version: 2.3.6 - resolution: "enquirer@npm:2.3.6" - dependencies: - ansi-colors: ^4.1.1 - checksum: 1c0911e14a6f8d26721c91e01db06092a5f7675159f0261d69c403396a385afd13dd76825e7678f66daffa930cfaa8d45f506fb35f818a2788463d022af1b884 - languageName: node - linkType: hard - "env-paths@npm:^2.2.0": version: 2.2.1 resolution: "env-paths@npm:2.2.1" @@ -2103,59 +1716,6 @@ __metadata: languageName: node linkType: hard -"es-abstract@npm:^1.19.0, es-abstract@npm:^1.20.4": - version: 1.20.5 - resolution: "es-abstract@npm:1.20.5" - dependencies: - call-bind: ^1.0.2 - es-to-primitive: ^1.2.1 - function-bind: ^1.1.1 - function.prototype.name: ^1.1.5 - get-intrinsic: ^1.1.3 - get-symbol-description: ^1.0.0 - gopd: ^1.0.1 - has: ^1.0.3 - has-property-descriptors: ^1.0.0 - has-symbols: ^1.0.3 - internal-slot: ^1.0.3 - is-callable: ^1.2.7 - is-negative-zero: ^2.0.2 - is-regex: ^1.1.4 - is-shared-array-buffer: ^1.0.2 - is-string: ^1.0.7 - is-weakref: ^1.0.2 - object-inspect: ^1.12.2 - object-keys: ^1.1.1 - object.assign: ^4.1.4 - regexp.prototype.flags: ^1.4.3 - safe-regex-test: ^1.0.0 - string.prototype.trimend: ^1.0.6 - string.prototype.trimstart: ^1.0.6 - unbox-primitive: ^1.0.2 - checksum: 00564779ddaf7fb977ab5aa2b8ea2cbd4fa2335ad5368f788bd0bb094c86bc1790335dd9c3e30374bb0af2fa54c724fb4e0c73659dcfe8e427355a56f2b65946 - languageName: node - linkType: hard - -"es-shim-unscopables@npm:^1.0.0": - version: 1.0.0 - resolution: "es-shim-unscopables@npm:1.0.0" - dependencies: - has: ^1.0.3 - checksum: 83e95cadbb6ee44d3644dfad60dcad7929edbc42c85e66c3e99aefd68a3a5c5665f2686885cddb47dfeabfd77bd5ea5a7060f2092a955a729bbd8834f0d86fa1 - languageName: node - linkType: hard - -"es-to-primitive@npm:^1.2.1": - version: 1.2.1 - resolution: "es-to-primitive@npm:1.2.1" - dependencies: - is-callable: ^1.1.4 - is-date-object: ^1.0.1 - is-symbol: ^1.0.2 - checksum: 4ead6671a2c1402619bdd77f3503991232ca15e17e46222b0a41a5d81aebc8740a77822f5b3c965008e631153e9ef0580540007744521e72de8e33599fca2eed - languageName: node - linkType: hard - "escalade@npm:^3.1.1": version: 3.1.1 resolution: "escalade@npm:3.1.1" @@ -2177,13 +1737,6 @@ __metadata: languageName: node linkType: hard -"escape-string-regexp@npm:^4.0.0": - version: 4.0.0 - resolution: "escape-string-regexp@npm:4.0.0" - checksum: 98b48897d93060f2322108bf29db0feba7dd774be96cd069458d1453347b25ce8682ecc39859d4bca2203cc0ab19c237bcc71755eff49a0f8d90beadeeba5cc5 - languageName: node - linkType: hard - "escodegen@npm:^2.0.0": version: 2.0.0 resolution: "escodegen@npm:2.0.0" @@ -2203,295 +1756,33 @@ __metadata: languageName: node linkType: hard -"eslint-config-prettier@npm:^8.3.0": - version: 8.5.0 - resolution: "eslint-config-prettier@npm:8.5.0" - peerDependencies: - eslint: ">=7.0.0" +"esprima@npm:^4.0.0, esprima@npm:^4.0.1": + version: 4.0.1 + resolution: "esprima@npm:4.0.1" bin: - eslint-config-prettier: bin/cli.js - checksum: 0d0f5c32e7a0ad91249467ce71ca92394ccd343178277d318baf32063b79ea90216f4c81d1065d60f96366fdc60f151d4d68ae7811a58bd37228b84c2083f893 - languageName: node - linkType: hard - -"eslint-import-resolver-node@npm:^0.3.6": - version: 0.3.6 - resolution: "eslint-import-resolver-node@npm:0.3.6" - dependencies: - debug: ^3.2.7 - resolve: ^1.20.0 - checksum: 6266733af1e112970e855a5bcc2d2058fb5ae16ad2a6d400705a86b29552b36131ffc5581b744c23d550de844206fb55e9193691619ee4dbf225c4bde526b1c8 + esparse: ./bin/esparse.js + esvalidate: ./bin/esvalidate.js + checksum: b45bc805a613dbea2835278c306b91aff6173c8d034223fa81498c77dcbce3b2931bf6006db816f62eacd9fd4ea975dfd85a5b7f3c6402cfd050d4ca3c13a628 languageName: node linkType: hard -"eslint-module-utils@npm:^2.7.3": - version: 2.7.4 - resolution: "eslint-module-utils@npm:2.7.4" - dependencies: - debug: ^3.2.7 - peerDependenciesMeta: - eslint: - optional: true - checksum: 5da13645daff145a5c922896b258f8bba560722c3767254e458d894ff5fbb505d6dfd945bffa932a5b0ae06714da2379bd41011c4c20d2d59cc83e23895360f7 +"estraverse@npm:^5.2.0": + version: 5.3.0 + resolution: "estraverse@npm:5.3.0" + checksum: 072780882dc8416ad144f8fe199628d2b3e7bbc9989d9ed43795d2c90309a2047e6bc5979d7e2322a341163d22cfad9e21f4110597fe487519697389497e4e2b languageName: node linkType: hard -"eslint-plugin-es@npm:^3.0.0": - version: 3.0.1 - resolution: "eslint-plugin-es@npm:3.0.1" - dependencies: - eslint-utils: ^2.0.0 - regexpp: ^3.0.0 - peerDependencies: - eslint: ">=4.19.1" - checksum: e57592c52301ee8ddc296ae44216df007f3a870bcb3be8d1fbdb909a1d3a3efe3fa3785de02066f9eba1d6466b722d3eb3cc3f8b75b3cf6a1cbded31ac6298e4 +"esutils@npm:^2.0.2": + version: 2.0.3 + resolution: "esutils@npm:2.0.3" + checksum: 22b5b08f74737379a840b8ed2036a5fb35826c709ab000683b092d9054e5c2a82c27818f12604bfc2a9a76b90b6834ef081edbc1c7ae30d1627012e067c6ec87 languageName: node linkType: hard -"eslint-plugin-import@npm:^2.25.3": - version: 2.26.0 - resolution: "eslint-plugin-import@npm:2.26.0" - dependencies: - array-includes: ^3.1.4 - array.prototype.flat: ^1.2.5 - debug: ^2.6.9 - doctrine: ^2.1.0 - eslint-import-resolver-node: ^0.3.6 - eslint-module-utils: ^2.7.3 - has: ^1.0.3 - is-core-module: ^2.8.1 - is-glob: ^4.0.3 - minimatch: ^3.1.2 - object.values: ^1.1.5 - resolve: ^1.22.0 - tsconfig-paths: ^3.14.1 - peerDependencies: - eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 - checksum: 0bf77ad80339554481eafa2b1967449e1f816b94c7a6f9614ce33fb4083c4e6c050f10d241dd50b4975d47922880a34de1e42ea9d8e6fd663ebb768baa67e655 - languageName: node - linkType: hard - -"eslint-plugin-jest@npm:^25.2.4": - version: 25.7.0 - resolution: "eslint-plugin-jest@npm:25.7.0" - dependencies: - "@typescript-eslint/experimental-utils": ^5.0.0 - peerDependencies: - "@typescript-eslint/eslint-plugin": ^4.0.0 || ^5.0.0 - eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 - peerDependenciesMeta: - "@typescript-eslint/eslint-plugin": - optional: true - jest: - optional: true - checksum: fc6da96131f4cbf33d15ef911ec8e600ccd71deb97d73c0ca340427cef7b01ff41a797e2e7d1e351abf97321a46ed0c0acff5ee8eeedac94961dd6dad1f718a9 - languageName: node - linkType: hard - -"eslint-plugin-node@npm:^11.1.0": - version: 11.1.0 - resolution: "eslint-plugin-node@npm:11.1.0" - dependencies: - eslint-plugin-es: ^3.0.0 - eslint-utils: ^2.0.0 - ignore: ^5.1.1 - minimatch: ^3.0.4 - resolve: ^1.10.1 - semver: ^6.1.0 - peerDependencies: - eslint: ">=5.16.0" - checksum: 5804c4f8a6e721f183ef31d46fbe3b4e1265832f352810060e0502aeac7de034df83352fc88643b19641bb2163f2587f1bd4119aff0fd21e8d98c57c450e013b - languageName: node - linkType: hard - -"eslint-plugin-prettier@npm:^4.0.0": - version: 4.2.1 - resolution: "eslint-plugin-prettier@npm:4.2.1" - dependencies: - prettier-linter-helpers: ^1.0.0 - peerDependencies: - eslint: ">=7.28.0" - prettier: ">=2.0.0" - peerDependenciesMeta: - eslint-config-prettier: - optional: true - checksum: b9e839d2334ad8ec7a5589c5cb0f219bded260839a857d7a486997f9870e95106aa59b8756ff3f37202085ebab658de382b0267cae44c3a7f0eb0bcc03a4f6d6 - languageName: node - linkType: hard - -"eslint-scope@npm:^5.1.1": - version: 5.1.1 - resolution: "eslint-scope@npm:5.1.1" - dependencies: - esrecurse: ^4.3.0 - estraverse: ^4.1.1 - checksum: 47e4b6a3f0cc29c7feedee6c67b225a2da7e155802c6ea13bbef4ac6b9e10c66cd2dcb987867ef176292bf4e64eccc680a49e35e9e9c669f4a02bac17e86abdb - languageName: node - linkType: hard - -"eslint-scope@npm:^7.1.1": - version: 7.1.1 - resolution: "eslint-scope@npm:7.1.1" - dependencies: - esrecurse: ^4.3.0 - estraverse: ^5.2.0 - checksum: 9f6e974ab2db641ca8ab13508c405b7b859e72afe9f254e8131ff154d2f40c99ad4545ce326fd9fde3212ff29707102562a4834f1c48617b35d98c71a97fbf3e - languageName: node - linkType: hard - -"eslint-utils@npm:^2.0.0": - version: 2.1.0 - resolution: "eslint-utils@npm:2.1.0" - dependencies: - eslint-visitor-keys: ^1.1.0 - checksum: 27500938f348da42100d9e6ad03ae29b3de19ba757ae1a7f4a087bdcf83ac60949bbb54286492ca61fac1f5f3ac8692dd21537ce6214240bf95ad0122f24d71d - languageName: node - linkType: hard - -"eslint-utils@npm:^3.0.0": - version: 3.0.0 - resolution: "eslint-utils@npm:3.0.0" - dependencies: - eslint-visitor-keys: ^2.0.0 - peerDependencies: - eslint: ">=5" - checksum: 0668fe02f5adab2e5a367eee5089f4c39033af20499df88fe4e6aba2015c20720404d8c3d6349b6f716b08fdf91b9da4e5d5481f265049278099c4c836ccb619 - languageName: node - linkType: hard - -"eslint-visitor-keys@npm:^1.1.0": - version: 1.3.0 - resolution: "eslint-visitor-keys@npm:1.3.0" - checksum: 37a19b712f42f4c9027e8ba98c2b06031c17e0c0a4c696cd429bd9ee04eb43889c446f2cd545e1ff51bef9593fcec94ecd2c2ef89129fcbbf3adadbef520376a - languageName: node - linkType: hard - -"eslint-visitor-keys@npm:^2.0.0": - version: 2.1.0 - resolution: "eslint-visitor-keys@npm:2.1.0" - checksum: e3081d7dd2611a35f0388bbdc2f5da60b3a3c5b8b6e928daffff7391146b434d691577aa95064c8b7faad0b8a680266bcda0a42439c18c717b80e6718d7e267d - languageName: node - linkType: hard - -"eslint-visitor-keys@npm:^3.3.0": - version: 3.3.0 - resolution: "eslint-visitor-keys@npm:3.3.0" - checksum: d59e68a7c5a6d0146526b0eec16ce87fbf97fe46b8281e0d41384224375c4e52f5ffb9e16d48f4ea50785cde93f766b0c898e31ab89978d88b0e1720fbfb7808 - languageName: node - linkType: hard - -"eslint@npm:^8.1.0": - version: 8.30.0 - resolution: "eslint@npm:8.30.0" - dependencies: - "@eslint/eslintrc": ^1.4.0 - "@humanwhocodes/config-array": ^0.11.8 - "@humanwhocodes/module-importer": ^1.0.1 - "@nodelib/fs.walk": ^1.2.8 - ajv: ^6.10.0 - chalk: ^4.0.0 - cross-spawn: ^7.0.2 - debug: ^4.3.2 - doctrine: ^3.0.0 - escape-string-regexp: ^4.0.0 - eslint-scope: ^7.1.1 - eslint-utils: ^3.0.0 - eslint-visitor-keys: ^3.3.0 - espree: ^9.4.0 - esquery: ^1.4.0 - esutils: ^2.0.2 - fast-deep-equal: ^3.1.3 - file-entry-cache: ^6.0.1 - find-up: ^5.0.0 - glob-parent: ^6.0.2 - globals: ^13.19.0 - grapheme-splitter: ^1.0.4 - ignore: ^5.2.0 - import-fresh: ^3.0.0 - imurmurhash: ^0.1.4 - is-glob: ^4.0.0 - is-path-inside: ^3.0.3 - js-sdsl: ^4.1.4 - js-yaml: ^4.1.0 - json-stable-stringify-without-jsonify: ^1.0.1 - levn: ^0.4.1 - lodash.merge: ^4.6.2 - minimatch: ^3.1.2 - natural-compare: ^1.4.0 - optionator: ^0.9.1 - regexpp: ^3.2.0 - strip-ansi: ^6.0.1 - strip-json-comments: ^3.1.0 - text-table: ^0.2.0 - bin: - eslint: bin/eslint.js - checksum: b7525bb465b342665c3b8bab7e114d514ef1bc4e79f211c919863f9c71767e7412ec82383a22614a92d159783f91101018817000f7c61ce69a5e7015280cafaf - languageName: node - linkType: hard - -"espree@npm:^9.4.0": - version: 9.4.1 - resolution: "espree@npm:9.4.1" - dependencies: - acorn: ^8.8.0 - acorn-jsx: ^5.3.2 - eslint-visitor-keys: ^3.3.0 - checksum: 4d266b0cf81c7dfe69e542c7df0f246e78d29f5b04dda36e514eb4c7af117ee6cfbd3280e560571ed82ff6c9c3f0003c05b82583fc7a94006db7497c4fe4270e - languageName: node - linkType: hard - -"esprima@npm:^4.0.0, esprima@npm:^4.0.1": - version: 4.0.1 - resolution: "esprima@npm:4.0.1" - bin: - esparse: ./bin/esparse.js - esvalidate: ./bin/esvalidate.js - checksum: b45bc805a613dbea2835278c306b91aff6173c8d034223fa81498c77dcbce3b2931bf6006db816f62eacd9fd4ea975dfd85a5b7f3c6402cfd050d4ca3c13a628 - languageName: node - linkType: hard - -"esquery@npm:^1.4.0": - version: 1.4.0 - resolution: "esquery@npm:1.4.0" - dependencies: - estraverse: ^5.1.0 - checksum: a0807e17abd7fbe5fbd4fab673038d6d8a50675cdae6b04fbaa520c34581be0c5fa24582990e8acd8854f671dd291c78bb2efb9e0ed5b62f33bac4f9cf820210 - languageName: node - linkType: hard - -"esrecurse@npm:^4.3.0": - version: 4.3.0 - resolution: "esrecurse@npm:4.3.0" - dependencies: - estraverse: ^5.2.0 - checksum: ebc17b1a33c51cef46fdc28b958994b1dc43cd2e86237515cbc3b4e5d2be6a811b2315d0a1a4d9d340b6d2308b15322f5c8291059521cc5f4802f65e7ec32837 - languageName: node - linkType: hard - -"estraverse@npm:^4.1.1": - version: 4.3.0 - resolution: "estraverse@npm:4.3.0" - checksum: a6299491f9940bb246124a8d44b7b7a413a8336f5436f9837aaa9330209bd9ee8af7e91a654a3545aee9c54b3308e78ee360cef1d777d37cfef77d2fa33b5827 - languageName: node - linkType: hard - -"estraverse@npm:^5.1.0, estraverse@npm:^5.2.0": - version: 5.3.0 - resolution: "estraverse@npm:5.3.0" - checksum: 072780882dc8416ad144f8fe199628d2b3e7bbc9989d9ed43795d2c90309a2047e6bc5979d7e2322a341163d22cfad9e21f4110597fe487519697389497e4e2b - languageName: node - linkType: hard - -"esutils@npm:^2.0.2": - version: 2.0.3 - resolution: "esutils@npm:2.0.3" - checksum: 22b5b08f74737379a840b8ed2036a5fb35826c709ab000683b092d9054e5c2a82c27818f12604bfc2a9a76b90b6834ef081edbc1c7ae30d1627012e067c6ec87 - languageName: node - linkType: hard - -"execa@npm:^5.0.0, execa@npm:^5.1.1": - version: 5.1.1 - resolution: "execa@npm:5.1.1" +"execa@npm:^5.0.0": + version: 5.1.1 + resolution: "execa@npm:5.1.1" dependencies: cross-spawn: ^7.0.3 get-stream: ^6.0.0 @@ -2525,33 +1816,6 @@ __metadata: languageName: node linkType: hard -"fast-deep-equal@npm:^3.1.1, fast-deep-equal@npm:^3.1.3": - version: 3.1.3 - resolution: "fast-deep-equal@npm:3.1.3" - checksum: e21a9d8d84f53493b6aa15efc9cfd53dd5b714a1f23f67fb5dc8f574af80df889b3bce25dc081887c6d25457cce704e636395333abad896ccdec03abaf1f3f9d - languageName: node - linkType: hard - -"fast-diff@npm:^1.1.2": - version: 1.2.0 - resolution: "fast-diff@npm:1.2.0" - checksum: 1b5306eaa9e826564d9e5ffcd6ebd881eb5f770b3f977fcbf38f05c824e42172b53c79920e8429c54eb742ce15a0caf268b0fdd5b38f6de52234c4a8368131ae - languageName: node - linkType: hard - -"fast-glob@npm:^3.2.9": - version: 3.2.12 - resolution: "fast-glob@npm:3.2.12" - dependencies: - "@nodelib/fs.stat": ^2.0.2 - "@nodelib/fs.walk": ^1.2.3 - glob-parent: ^5.1.2 - merge2: ^1.3.0 - micromatch: ^4.0.4 - checksum: 0b1990f6ce831c7e28c4d505edcdaad8e27e88ab9fa65eedadb730438cfc7cde4910d6c975d6b7b8dc8a73da4773702ebcfcd6e3518e73938bb1383badfe01c2 - languageName: node - linkType: hard - "fast-json-stable-stringify@npm:2.x, fast-json-stable-stringify@npm:^2.0.0": version: 2.1.0 resolution: "fast-json-stable-stringify@npm:2.1.0" @@ -2559,22 +1823,13 @@ __metadata: languageName: node linkType: hard -"fast-levenshtein@npm:^2.0.6, fast-levenshtein@npm:~2.0.6": +"fast-levenshtein@npm:~2.0.6": version: 2.0.6 resolution: "fast-levenshtein@npm:2.0.6" checksum: 92cfec0a8dfafd9c7a15fba8f2cc29cd0b62b85f056d99ce448bbcd9f708e18ab2764bda4dd5158364f4145a7c72788538994f0d1787b956ef0d1062b0f7c24c languageName: node linkType: hard -"fastq@npm:^1.6.0": - version: 1.14.0 - resolution: "fastq@npm:1.14.0" - dependencies: - reusify: ^1.0.4 - checksum: da2c05ec1446ef77b8ba2b76619c90d483404f5087e71e77469fbee797280a1f4ef26a63be15b2377198bc20d09fdf25c7d6e1e492a1e568a29dfdd9bcb7538c - languageName: node - linkType: hard - "fb-watchman@npm:^2.0.0": version: 2.0.2 resolution: "fb-watchman@npm:2.0.2" @@ -2584,15 +1839,6 @@ __metadata: languageName: node linkType: hard -"file-entry-cache@npm:^6.0.1": - version: 6.0.1 - resolution: "file-entry-cache@npm:6.0.1" - dependencies: - flat-cache: ^3.0.4 - checksum: f49701feaa6314c8127c3c2f6173cfefff17612f5ed2daaafc6da13b5c91fd43e3b2a58fd0d63f9f94478a501b167615931e7200e31485e320f74a33885a9c74 - languageName: node - linkType: hard - "fill-range@npm:^7.0.1": version: 7.0.1 resolution: "fill-range@npm:7.0.1" @@ -2612,33 +1858,6 @@ __metadata: languageName: node linkType: hard -"find-up@npm:^5.0.0": - version: 5.0.0 - resolution: "find-up@npm:5.0.0" - dependencies: - locate-path: ^6.0.0 - path-exists: ^4.0.0 - checksum: 07955e357348f34660bde7920783204ff5a26ac2cafcaa28bace494027158a97b9f56faaf2d89a6106211a8174db650dd9f503f9c0d526b1202d5554a00b9095 - languageName: node - linkType: hard - -"flat-cache@npm:^3.0.4": - version: 3.0.4 - resolution: "flat-cache@npm:3.0.4" - dependencies: - flatted: ^3.1.0 - rimraf: ^3.0.2 - checksum: 4fdd10ecbcbf7d520f9040dd1340eb5dfe951e6f0ecf2252edeec03ee68d989ec8b9a20f4434270e71bcfd57800dc09b3344fca3966b2eb8f613072c7d9a2365 - languageName: node - linkType: hard - -"flatted@npm:^3.1.0": - version: 3.2.7 - resolution: "flatted@npm:3.2.7" - checksum: 427633049d55bdb80201c68f7eb1cbd533e03eac541f97d3aecab8c5526f12a20ccecaeede08b57503e772c769e7f8680b37e8d482d1e5f8d7e2194687f9ea35 - languageName: node - linkType: hard - "form-data@npm:^3.0.0": version: 3.0.1 resolution: "form-data@npm:3.0.1" @@ -2692,25 +1911,6 @@ __metadata: languageName: node linkType: hard -"function.prototype.name@npm:^1.1.5": - version: 1.1.5 - resolution: "function.prototype.name@npm:1.1.5" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.3 - es-abstract: ^1.19.0 - functions-have-names: ^1.2.2 - checksum: acd21d733a9b649c2c442f067567743214af5fa248dbeee69d8278ce7df3329ea5abac572be9f7470b4ec1cd4d8f1040e3c5caccf98ebf2bf861a0deab735c27 - languageName: node - linkType: hard - -"functions-have-names@npm:^1.2.2": - version: 1.2.3 - resolution: "functions-have-names@npm:1.2.3" - checksum: c3f1f5ba20f4e962efb71344ce0a40722163e85bee2101ce25f88214e78182d2d2476aa85ef37950c579eb6cf6ee811c17b3101bb84004bb75655f3e33f3fdb5 - languageName: node - linkType: hard - "gauge@npm:^4.0.3": version: 4.0.4 resolution: "gauge@npm:4.0.4" @@ -2741,24 +1941,6 @@ __metadata: languageName: node linkType: hard -"get-intrinsic@npm:^1.0.2, get-intrinsic@npm:^1.1.1, get-intrinsic@npm:^1.1.3": - version: 1.1.3 - resolution: "get-intrinsic@npm:1.1.3" - dependencies: - function-bind: ^1.1.1 - has: ^1.0.3 - has-symbols: ^1.0.3 - checksum: 152d79e87251d536cf880ba75cfc3d6c6c50e12b3a64e1ea960e73a3752b47c69f46034456eae1b0894359ce3bc64c55c186f2811f8a788b75b638b06fab228a - languageName: node - linkType: hard - -"get-own-enumerable-property-symbols@npm:^3.0.0": - version: 3.0.2 - resolution: "get-own-enumerable-property-symbols@npm:3.0.2" - checksum: 8f0331f14159f939830884799f937343c8c0a2c330506094bc12cbee3665d88337fe97a4ea35c002cc2bdba0f5d9975ad7ec3abb925015cdf2a93e76d4759ede - languageName: node - linkType: hard - "get-package-type@npm:^0.1.0": version: 0.1.0 resolution: "get-package-type@npm:0.1.0" @@ -2773,34 +1955,6 @@ __metadata: languageName: node linkType: hard -"get-symbol-description@npm:^1.0.0": - version: 1.0.0 - resolution: "get-symbol-description@npm:1.0.0" - dependencies: - call-bind: ^1.0.2 - get-intrinsic: ^1.1.1 - checksum: 9ceff8fe968f9270a37a1f73bf3f1f7bda69ca80f4f80850670e0e7b9444ff99323f7ac52f96567f8b5f5fbe7ac717a0d81d3407c7313e82810c6199446a5247 - languageName: node - linkType: hard - -"glob-parent@npm:^5.1.2": - version: 5.1.2 - resolution: "glob-parent@npm:5.1.2" - dependencies: - is-glob: ^4.0.1 - checksum: f4f2bfe2425296e8a47e36864e4f42be38a996db40420fe434565e4480e3322f18eb37589617a98640c5dc8fdec1a387007ee18dbb1f3f5553409c34d17f425e - languageName: node - linkType: hard - -"glob-parent@npm:^6.0.2": - version: 6.0.2 - resolution: "glob-parent@npm:6.0.2" - dependencies: - is-glob: ^4.0.3 - checksum: c13ee97978bef4f55106b71e66428eb1512e71a7466ba49025fc2aec59a5bfb0954d5abd58fc5ee6c9b076eef4e1f6d3375c2e964b88466ca390da4419a786a8 - languageName: node - linkType: hard - "glob@npm:^7.1.1, glob@npm:^7.1.2, glob@npm:^7.1.3, glob@npm:^7.1.4": version: 7.2.3 resolution: "glob@npm:7.2.3" @@ -2815,7 +1969,7 @@ __metadata: languageName: node linkType: hard -"glob@npm:^8.0.1, glob@npm:^8.0.3": +"glob@npm:^8.0.1": version: 8.0.3 resolution: "glob@npm:8.0.3" dependencies: @@ -2835,38 +1989,6 @@ __metadata: languageName: node linkType: hard -"globals@npm:^13.19.0": - version: 13.19.0 - resolution: "globals@npm:13.19.0" - dependencies: - type-fest: ^0.20.2 - checksum: a000dbd00bcf28f0941d8a29c3522b1c3b8e4bfe4e60e262c477a550c3cbbe8dbe2925a6905f037acd40f9a93c039242e1f7079c76b0fd184bc41dcc3b5c8e2e - languageName: node - linkType: hard - -"globby@npm:^11.1.0": - version: 11.1.0 - resolution: "globby@npm:11.1.0" - dependencies: - array-union: ^2.1.0 - dir-glob: ^3.0.1 - fast-glob: ^3.2.9 - ignore: ^5.2.0 - merge2: ^1.4.1 - slash: ^3.0.0 - checksum: b4be8885e0cfa018fc783792942d53926c35c50b3aefd3fdcfb9d22c627639dc26bd2327a40a0b74b074100ce95bb7187bfeae2f236856aa3de183af7a02aea6 - languageName: node - linkType: hard - -"gopd@npm:^1.0.1": - version: 1.0.1 - resolution: "gopd@npm:1.0.1" - dependencies: - get-intrinsic: ^1.1.3 - checksum: a5ccfb8806e0917a94e0b3de2af2ea4979c1da920bc381667c260e00e7cafdbe844e2cb9c5bcfef4e5412e8bf73bab837285bc35c7ba73aaaf0134d4583393a6 - languageName: node - linkType: hard - "graceful-fs@npm:^4.2.6, graceful-fs@npm:^4.2.9": version: 4.2.10 resolution: "graceful-fs@npm:4.2.10" @@ -2874,20 +1996,6 @@ __metadata: languageName: node linkType: hard -"grapheme-splitter@npm:^1.0.4": - version: 1.0.4 - resolution: "grapheme-splitter@npm:1.0.4" - checksum: 0c22ec54dee1b05cd480f78cf14f732cb5b108edc073572c4ec205df4cd63f30f8db8025afc5debc8835a8ddeacf648a1c7992fe3dcd6ad38f9a476d84906620 - languageName: node - linkType: hard - -"has-bigints@npm:^1.0.1, has-bigints@npm:^1.0.2": - version: 1.0.2 - resolution: "has-bigints@npm:1.0.2" - checksum: 390e31e7be7e5c6fe68b81babb73dfc35d413604d7ee5f56da101417027a4b4ce6a27e46eff97ad040c835b5d228676eae99a9b5c3bc0e23c8e81a49241ff45b - languageName: node - linkType: hard - "has-flag@npm:^3.0.0": version: 3.0.0 resolution: "has-flag@npm:3.0.0" @@ -2902,31 +2010,6 @@ __metadata: languageName: node linkType: hard -"has-property-descriptors@npm:^1.0.0": - version: 1.0.0 - resolution: "has-property-descriptors@npm:1.0.0" - dependencies: - get-intrinsic: ^1.1.1 - checksum: a6d3f0a266d0294d972e354782e872e2fe1b6495b321e6ef678c9b7a06a40408a6891817350c62e752adced73a94ac903c54734fee05bf65b1905ee1368194bb - languageName: node - linkType: hard - -"has-symbols@npm:^1.0.2, has-symbols@npm:^1.0.3": - version: 1.0.3 - resolution: "has-symbols@npm:1.0.3" - checksum: a054c40c631c0d5741a8285010a0777ea0c068f99ed43e5d6eb12972da223f8af553a455132fdb0801bdcfa0e0f443c0c03a68d8555aa529b3144b446c3f2410 - languageName: node - linkType: hard - -"has-tostringtag@npm:^1.0.0": - version: 1.0.0 - resolution: "has-tostringtag@npm:1.0.0" - dependencies: - has-symbols: ^1.0.2 - checksum: cc12eb28cb6ae22369ebaad3a8ab0799ed61270991be88f208d508076a1e99abe4198c965935ce85ea90b60c94ddda73693b0920b58e7ead048b4a391b502c1c - languageName: node - linkType: hard - "has-unicode@npm:^2.0.1": version: 2.0.1 resolution: "has-unicode@npm:2.0.1" @@ -3014,15 +2097,6 @@ __metadata: languageName: node linkType: hard -"husky@npm:^7.0.4": - version: 7.0.4 - resolution: "husky@npm:7.0.4" - bin: - husky: lib/bin.js - checksum: c6ec4af63da2c9522da8674a20ad9b48362cc92704896cc8a58c6a2a39d797feb2b806f93fbd83a6d653fbdceb2c3b6e0b602c6b2e8565206ffc2882ef7db9e9 - languageName: node - linkType: hard - "iconv-lite@npm:0.4.24": version: 0.4.24 resolution: "iconv-lite@npm:0.4.24" @@ -3041,23 +2115,6 @@ __metadata: languageName: node linkType: hard -"ignore@npm:^5.1.1, ignore@npm:^5.2.0": - version: 5.2.4 - resolution: "ignore@npm:5.2.4" - checksum: 3d4c309c6006e2621659311783eaea7ebcd41fe4ca1d78c91c473157ad6666a57a2df790fe0d07a12300d9aac2888204d7be8d59f9aaf665b1c7fcdb432517ef - languageName: node - linkType: hard - -"import-fresh@npm:^3.0.0, import-fresh@npm:^3.2.1": - version: 3.3.0 - resolution: "import-fresh@npm:3.3.0" - dependencies: - parent-module: ^1.0.0 - resolve-from: ^4.0.0 - checksum: 2cacfad06e652b1edc50be650f7ec3be08c5e5a6f6d12d035c440a42a8cc028e60a5b99ca08a77ab4d6b1346da7d971915828f33cdab730d3d42f08242d09baa - languageName: node - linkType: hard - "import-local@npm:^3.0.2": version: 3.1.0 resolution: "import-local@npm:3.1.0" @@ -3108,17 +2165,6 @@ __metadata: languageName: node linkType: hard -"internal-slot@npm:^1.0.3": - version: 1.0.4 - resolution: "internal-slot@npm:1.0.4" - dependencies: - get-intrinsic: ^1.1.3 - has: ^1.0.3 - side-channel: ^1.0.4 - checksum: 8974588d06bab4f675573a3b52975370facf6486df51bc0567a982c7024fa29495f10b76c0d4dc742dd951d1b72024fdc1e31bb0bedf1678dc7aacacaf5a4f73 - languageName: node - linkType: hard - "ip@npm:^2.0.0": version: 2.0.0 resolution: "ip@npm:2.0.0" @@ -3133,33 +2179,7 @@ __metadata: languageName: node linkType: hard -"is-bigint@npm:^1.0.1": - version: 1.0.4 - resolution: "is-bigint@npm:1.0.4" - dependencies: - has-bigints: ^1.0.1 - checksum: c56edfe09b1154f8668e53ebe8252b6f185ee852a50f9b41e8d921cb2bed425652049fbe438723f6cb48a63ca1aa051e948e7e401e093477c99c84eba244f666 - languageName: node - linkType: hard - -"is-boolean-object@npm:^1.1.0": - version: 1.1.2 - resolution: "is-boolean-object@npm:1.1.2" - dependencies: - call-bind: ^1.0.2 - has-tostringtag: ^1.0.0 - checksum: c03b23dbaacadc18940defb12c1c0e3aaece7553ef58b162a0f6bba0c2a7e1551b59f365b91e00d2dbac0522392d576ef322628cb1d036a0fe51eb466db67222 - languageName: node - linkType: hard - -"is-callable@npm:^1.1.4, is-callable@npm:^1.2.7": - version: 1.2.7 - resolution: "is-callable@npm:1.2.7" - checksum: 61fd57d03b0d984e2ed3720fb1c7a897827ea174bd44402878e059542ea8c4aeedee0ea0985998aa5cc2736b2fa6e271c08587addb5b3959ac52cf665173d1ac - languageName: node - linkType: hard - -"is-core-module@npm:^2.8.1, is-core-module@npm:^2.9.0": +"is-core-module@npm:^2.9.0": version: 2.11.0 resolution: "is-core-module@npm:2.11.0" dependencies: @@ -3168,22 +2188,6 @@ __metadata: languageName: node linkType: hard -"is-date-object@npm:^1.0.1": - version: 1.0.5 - resolution: "is-date-object@npm:1.0.5" - dependencies: - has-tostringtag: ^1.0.0 - checksum: baa9077cdf15eb7b58c79398604ca57379b2fc4cf9aa7a9b9e295278648f628c9b201400c01c5e0f7afae56507d741185730307cbe7cad3b9f90a77e5ee342fc - languageName: node - linkType: hard - -"is-extglob@npm:^2.1.1": - version: 2.1.1 - resolution: "is-extglob@npm:2.1.1" - checksum: df033653d06d0eb567461e58a7a8c9f940bd8c22274b94bf7671ab36df5719791aae15eef6d83bbb5e23283967f2f984b8914559d4449efda578c775c4be6f85 - languageName: node - linkType: hard - "is-fullwidth-code-point@npm:^3.0.0": version: 3.0.0 resolution: "is-fullwidth-code-point@npm:3.0.0" @@ -3198,15 +2202,6 @@ __metadata: languageName: node linkType: hard -"is-glob@npm:^4.0.0, is-glob@npm:^4.0.1, is-glob@npm:^4.0.3": - version: 4.0.3 - resolution: "is-glob@npm:4.0.3" - dependencies: - is-extglob: ^2.1.1 - checksum: d381c1319fcb69d341cc6e6c7cd588e17cd94722d9a32dbd60660b993c4fb7d0f19438674e68dfec686d09b7c73139c9166b47597f846af387450224a8101ab4 - languageName: node - linkType: hard - "is-lambda@npm:^1.0.1": version: 1.0.1 resolution: "is-lambda@npm:1.0.1" @@ -3214,22 +2209,6 @@ __metadata: languageName: node linkType: hard -"is-negative-zero@npm:^2.0.2": - version: 2.0.2 - resolution: "is-negative-zero@npm:2.0.2" - checksum: f3232194c47a549da60c3d509c9a09be442507616b69454716692e37ae9f37c4dea264fb208ad0c9f3efd15a796a46b79df07c7e53c6227c32170608b809149a - languageName: node - linkType: hard - -"is-number-object@npm:^1.0.4": - version: 1.0.7 - resolution: "is-number-object@npm:1.0.7" - dependencies: - has-tostringtag: ^1.0.0 - checksum: d1e8d01bb0a7134c74649c4e62da0c6118a0bfc6771ea3c560914d52a627873e6920dd0fd0ebc0e12ad2ff4687eac4c308f7e80320b973b2c8a2c8f97a7524f7 - languageName: node - linkType: hard - "is-number@npm:^7.0.0": version: 7.0.0 resolution: "is-number@npm:7.0.0" @@ -3237,20 +2216,6 @@ __metadata: languageName: node linkType: hard -"is-obj@npm:^1.0.1": - version: 1.0.1 - resolution: "is-obj@npm:1.0.1" - checksum: 3ccf0efdea12951e0b9c784e2b00e77e87b2f8bd30b42a498548a8afcc11b3287342a2030c308e473e93a7a19c9ea7854c99a8832a476591c727df2a9c79796c - languageName: node - linkType: hard - -"is-path-inside@npm:^3.0.3": - version: 3.0.3 - resolution: "is-path-inside@npm:3.0.3" - checksum: abd50f06186a052b349c15e55b182326f1936c89a78bf6c8f2b707412517c097ce04bc49a0ca221787bc44e1049f51f09a2ffb63d22899051988d3a618ba13e9 - languageName: node - linkType: hard - "is-potential-custom-element-name@npm:^1.0.1": version: 1.0.1 resolution: "is-potential-custom-element-name@npm:1.0.1" @@ -3258,32 +2223,6 @@ __metadata: languageName: node linkType: hard -"is-regex@npm:^1.1.4": - version: 1.1.4 - resolution: "is-regex@npm:1.1.4" - dependencies: - call-bind: ^1.0.2 - has-tostringtag: ^1.0.0 - checksum: 362399b33535bc8f386d96c45c9feb04cf7f8b41c182f54174c1a45c9abbbe5e31290bbad09a458583ff6bf3b2048672cdb1881b13289569a7c548370856a652 - languageName: node - linkType: hard - -"is-regexp@npm:^1.0.0": - version: 1.0.0 - resolution: "is-regexp@npm:1.0.0" - checksum: be692828e24cba479ec33644326fa98959ec68ba77965e0291088c1a741feaea4919d79f8031708f85fd25e39de002b4520622b55460660b9c369e6f7187faef - languageName: node - linkType: hard - -"is-shared-array-buffer@npm:^1.0.2": - version: 1.0.2 - resolution: "is-shared-array-buffer@npm:1.0.2" - dependencies: - call-bind: ^1.0.2 - checksum: 9508929cf14fdc1afc9d61d723c6e8d34f5e117f0bffda4d97e7a5d88c3a8681f633a74f8e3ad1fe92d5113f9b921dc5ca44356492079612f9a247efbce7032a - languageName: node - linkType: hard - "is-stream@npm:^2.0.0": version: 2.0.1 resolution: "is-stream@npm:2.0.1" @@ -3291,24 +2230,6 @@ __metadata: languageName: node linkType: hard -"is-string@npm:^1.0.5, is-string@npm:^1.0.7": - version: 1.0.7 - resolution: "is-string@npm:1.0.7" - dependencies: - has-tostringtag: ^1.0.0 - checksum: 323b3d04622f78d45077cf89aab783b2f49d24dc641aa89b5ad1a72114cfeff2585efc8c12ef42466dff32bde93d839ad321b26884cf75e5a7892a938b089989 - languageName: node - linkType: hard - -"is-symbol@npm:^1.0.2, is-symbol@npm:^1.0.3": - version: 1.0.4 - resolution: "is-symbol@npm:1.0.4" - dependencies: - has-symbols: ^1.0.2 - checksum: 92805812ef590738d9de49d677cd17dfd486794773fb6fa0032d16452af46e9b91bb43ffe82c983570f015b37136f4b53b28b8523bfb10b0ece7a66c31a54510 - languageName: node - linkType: hard - "is-typedarray@npm:^1.0.0": version: 1.0.0 resolution: "is-typedarray@npm:1.0.0" @@ -3316,15 +2237,6 @@ __metadata: languageName: node linkType: hard -"is-weakref@npm:^1.0.2": - version: 1.0.2 - resolution: "is-weakref@npm:1.0.2" - dependencies: - call-bind: ^1.0.2 - checksum: 95bd9a57cdcb58c63b1c401c60a474b0f45b94719c30f548c891860f051bc2231575c290a6b420c6bc6e7ed99459d424c652bd5bf9a1d5259505dc35b4bf83de - languageName: node - linkType: hard - "isexe@npm:^2.0.0": version: 2.0.0 resolution: "isexe@npm:2.0.0" @@ -3873,13 +2785,6 @@ __metadata: languageName: node linkType: hard -"js-sdsl@npm:^4.1.4": - version: 4.2.0 - resolution: "js-sdsl@npm:4.2.0" - checksum: 2cd0885f7212afb355929d72ca105cb37de7e95ad6031e6a32619eaefa46735a7d0fb682641a0ba666e1519cb138fe76abc1eea8a34e224140c9d94c995171f1 - languageName: node - linkType: hard - "js-tokens@npm:^4.0.0": version: 4.0.0 resolution: "js-tokens@npm:4.0.0" @@ -3899,17 +2804,6 @@ __metadata: languageName: node linkType: hard -"js-yaml@npm:^4.1.0": - version: 4.1.0 - resolution: "js-yaml@npm:4.1.0" - dependencies: - argparse: ^2.0.1 - bin: - js-yaml: bin/js-yaml.js - checksum: c7830dfd456c3ef2c6e355cc5a92e6700ceafa1d14bba54497b34a99f0376cecbb3e9ac14d3e5849b426d5a5140709a66237a8c991c675431271c4ce5504151a - languageName: node - linkType: hard - "jsdom@npm:^16.6.0": version: 16.7.0 resolution: "jsdom@npm:16.7.0" @@ -3966,20 +2860,6 @@ __metadata: languageName: node linkType: hard -"json-schema-traverse@npm:^0.4.1": - version: 0.4.1 - resolution: "json-schema-traverse@npm:0.4.1" - checksum: 7486074d3ba247769fda17d5181b345c9fb7d12e0da98b22d1d71a5db9698d8b4bd900a3ec1a4ffdd60846fc2556274a5c894d0c48795f14cb03aeae7b55260b - languageName: node - linkType: hard - -"json-stable-stringify-without-jsonify@npm:^1.0.1": - version: 1.0.1 - resolution: "json-stable-stringify-without-jsonify@npm:1.0.1" - checksum: cff44156ddce9c67c44386ad5cddf91925fe06b1d217f2da9c4910d01f358c6e3989c4d5a02683c7a5667f9727ff05831f7aa8ae66c8ff691c556f0884d49215 - languageName: node - linkType: hard - "json5@npm:2.x, json5@npm:^2.2.1": version: 2.2.2 resolution: "json5@npm:2.2.2" @@ -3989,17 +2869,6 @@ __metadata: languageName: node linkType: hard -"json5@npm:^1.0.1": - version: 1.0.1 - resolution: "json5@npm:1.0.1" - dependencies: - minimist: ^1.2.0 - bin: - json5: lib/cli.js - checksum: e76ea23dbb8fc1348c143da628134a98adf4c5a4e8ea2adaa74a80c455fc2cdf0e2e13e6398ef819bfe92306b610ebb2002668ed9fc1af386d593691ef346fc3 - languageName: node - linkType: hard - "jsonc-parser@npm:^3.0.0": version: 3.2.0 resolution: "jsonc-parser@npm:3.2.0" @@ -4021,16 +2890,6 @@ __metadata: languageName: node linkType: hard -"levn@npm:^0.4.1": - version: 0.4.1 - resolution: "levn@npm:0.4.1" - dependencies: - prelude-ls: ^1.2.1 - type-check: ~0.4.0 - checksum: 12c5021c859bd0f5248561bf139121f0358285ec545ebf48bb3d346820d5c61a4309535c7f387ed7d84361cf821e124ce346c6b7cef8ee09a67c1473b46d0fc4 - languageName: node - linkType: hard - "levn@npm:~0.3.0": version: 0.3.0 resolution: "levn@npm:0.3.0" @@ -4041,55 +2900,10 @@ __metadata: languageName: node linkType: hard -"lines-and-columns@npm:^1.1.6": - version: 1.2.4 - resolution: "lines-and-columns@npm:1.2.4" - checksum: 0c37f9f7fa212b38912b7145e1cd16a5f3cd34d782441c3e6ca653485d326f58b3caccda66efce1c5812bde4961bbde3374fae4b0d11bf1226152337f3894aa5 - languageName: node - linkType: hard - -"lint-staged@npm:^11.2.6": - version: 11.2.6 - resolution: "lint-staged@npm:11.2.6" - dependencies: - cli-truncate: 2.1.0 - colorette: ^1.4.0 - commander: ^8.2.0 - cosmiconfig: ^7.0.1 - debug: ^4.3.2 - enquirer: ^2.3.6 - execa: ^5.1.1 - listr2: ^3.12.2 - micromatch: ^4.0.4 - normalize-path: ^3.0.0 - please-upgrade-node: ^3.2.0 - string-argv: 0.3.1 - stringify-object: 3.3.0 - supports-color: 8.1.1 - bin: - lint-staged: bin/lint-staged.js - checksum: b9071621db351c553579bd18df3d80fb753f851c4f1f72db0aaf12e713eab25b6d8a044dab2957817de7da02054a63f7725a49c763aee09295133f0d554f4d3f - languageName: node - linkType: hard - -"listr2@npm:^3.12.2": - version: 3.14.0 - resolution: "listr2@npm:3.14.0" - dependencies: - cli-truncate: ^2.1.0 - colorette: ^2.0.16 - log-update: ^4.0.0 - p-map: ^4.0.0 - rfdc: ^1.3.0 - rxjs: ^7.5.1 - through: ^2.3.8 - wrap-ansi: ^7.0.0 - peerDependencies: - enquirer: ">= 2.3.0 < 3" - peerDependenciesMeta: - enquirer: - optional: true - checksum: fdb8b2d6bdf5df9371ebd5082bee46c6d0ca3d1e5f2b11fbb5a127839855d5f3da9d4968fce94f0a5ec67cac2459766abbb1faeef621065ebb1829b11ef9476d +"lines-and-columns@npm:^1.1.6": + version: 1.2.4 + resolution: "lines-and-columns@npm:1.2.4" + checksum: 0c37f9f7fa212b38912b7145e1cd16a5f3cd34d782441c3e6ca653485d326f58b3caccda66efce1c5812bde4961bbde3374fae4b0d11bf1226152337f3894aa5 languageName: node linkType: hard @@ -4102,15 +2916,6 @@ __metadata: languageName: node linkType: hard -"locate-path@npm:^6.0.0": - version: 6.0.0 - resolution: "locate-path@npm:6.0.0" - dependencies: - p-locate: ^5.0.0 - checksum: 72eb661788a0368c099a184c59d2fee760b3831c9c1c33955e8a19ae4a21b4116e53fa736dc086cdeb9fce9f7cc508f2f92d2d3aae516f133e16a2bb59a39f5a - languageName: node - linkType: hard - "lodash.memoize@npm:4.x": version: 4.1.2 resolution: "lodash.memoize@npm:4.1.2" @@ -4118,13 +2923,6 @@ __metadata: languageName: node linkType: hard -"lodash.merge@npm:^4.6.2": - version: 4.6.2 - resolution: "lodash.merge@npm:4.6.2" - checksum: ad580b4bdbb7ca1f7abf7e1bce63a9a0b98e370cf40194b03380a46b4ed799c9573029599caebc1b14e3f24b111aef72b96674a56cfa105e0f5ac70546cdc005 - languageName: node - linkType: hard - "lodash@npm:^4.17.21, lodash@npm:^4.7.0": version: 4.17.21 resolution: "lodash@npm:4.17.21" @@ -4132,18 +2930,6 @@ __metadata: languageName: node linkType: hard -"log-update@npm:^4.0.0": - version: 4.0.0 - resolution: "log-update@npm:4.0.0" - dependencies: - ansi-escapes: ^4.3.0 - cli-cursor: ^3.1.0 - slice-ansi: ^4.0.0 - wrap-ansi: ^6.2.0 - checksum: ae2f85bbabc1906034154fb7d4c4477c79b3e703d22d78adee8b3862fa913942772e7fa11713e3d96fb46de4e3cabefbf5d0a544344f03b58d3c4bff52aa9eb2 - languageName: node - linkType: hard - "lru-cache@npm:^6.0.0": version: 6.0.0 resolution: "lru-cache@npm:6.0.0" @@ -4216,12 +3002,12 @@ __metadata: languageName: node linkType: hard -"marked@npm:^4.0.16": - version: 4.2.4 - resolution: "marked@npm:4.2.4" +"marked@npm:^4.2.4": + version: 4.2.5 + resolution: "marked@npm:4.2.5" bin: marked: bin/marked.js - checksum: 5eb5bfa6ee4cf85712a3ccbe2a549c397e8886f5d18312a02696c7e3817625a6b91a8ad27a6ed43b06ddbdfb812f471b1270517c4b8fb068a6a9e5b4d555a5aa + checksum: dd7da20a3983c66b516463fad5dc8d15dc70e137d20b6dc491e134f671e84bd2ed5f859e2c35f21e56830a122e4356b9e574bcde49b72b7ad6bc121a215a1a98 languageName: node linkType: hard @@ -4232,13 +3018,6 @@ __metadata: languageName: node linkType: hard -"merge2@npm:^1.3.0, merge2@npm:^1.4.1": - version: 1.4.1 - resolution: "merge2@npm:1.4.1" - checksum: 7268db63ed5169466540b6fb947aec313200bcf6d40c5ab722c22e242f651994619bcd85601602972d3c85bd2cc45a358a4c61937e9f11a061919a1da569b0c2 - languageName: node - linkType: hard - "micromatch@npm:^4.0.4": version: 4.0.5 resolution: "micromatch@npm:4.0.5" @@ -4272,7 +3051,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^3.0.4, minimatch@npm:^3.0.5, minimatch@npm:^3.1.1, minimatch@npm:^3.1.2": +"minimatch@npm:^3.0.4, minimatch@npm:^3.1.1": version: 3.1.2 resolution: "minimatch@npm:3.1.2" dependencies: @@ -4281,7 +3060,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^5.0.1, minimatch@npm:^5.1.0": +"minimatch@npm:^5.0.1, minimatch@npm:^5.1.1": version: 5.1.2 resolution: "minimatch@npm:5.1.2" dependencies: @@ -4290,13 +3069,6 @@ __metadata: languageName: node linkType: hard -"minimist@npm:^1.2.0, minimist@npm:^1.2.6": - version: 1.2.7 - resolution: "minimist@npm:1.2.7" - checksum: 7346574a1038ca23c32e02252f603801f09384dd1d78b69a943a4e8c2c28730b80e96193882d3d3b22a063445f460e48316b29b8a25addca2d7e5e8f75478bec - languageName: node - linkType: hard - "minipass-collect@npm:^1.0.2": version: 1.0.2 resolution: "minipass-collect@npm:1.0.2" @@ -4385,13 +3157,6 @@ __metadata: languageName: node linkType: hard -"ms@npm:2.0.0": - version: 2.0.0 - resolution: "ms@npm:2.0.0" - checksum: 0e6a22b8b746d2e0b65a430519934fefd41b6db0682e3477c10f60c76e947c4c0ad06f63ffdf1d78d335f83edee8c0aa928aa66a36c7cd95b69b26f468d527f4 - languageName: node - linkType: hard - "ms@npm:2.1.2": version: 2.1.2 resolution: "ms@npm:2.1.2" @@ -4399,20 +3164,13 @@ __metadata: languageName: node linkType: hard -"ms@npm:^2.0.0, ms@npm:^2.1.1": +"ms@npm:^2.0.0": version: 2.1.3 resolution: "ms@npm:2.1.3" checksum: aa92de608021b242401676e35cfa5aa42dd70cbdc082b916da7fb925c542173e36bce97ea3e804923fe92c0ad991434e4a38327e15a1b5b5f945d66df615ae6d languageName: node linkType: hard -"natural-compare-lite@npm:^1.4.0": - version: 1.4.0 - resolution: "natural-compare-lite@npm:1.4.0" - checksum: 5222ac3986a2b78dd6069ac62cbb52a7bf8ffc90d972ab76dfe7b01892485d229530ed20d0c62e79a6b363a663b273db3bde195a1358ce9e5f779d4453887225 - languageName: node - linkType: hard - "natural-compare@npm:^1.4.0": version: 1.4.0 resolution: "natural-compare@npm:1.4.0" @@ -4469,24 +3227,14 @@ __metadata: "@types/chance": ^1.1.3 "@types/jest": ^27.0.3 "@types/node": ^16.11.9 - "@typescript-eslint/eslint-plugin": ^5.4.0 - "@typescript-eslint/parser": ^5.4.0 chance: ^1.1.8 - eslint: ^8.1.0 - eslint-config-prettier: ^8.3.0 - eslint-plugin-import: ^2.25.3 - eslint-plugin-jest: ^25.2.4 - eslint-plugin-node: ^11.1.0 - eslint-plugin-prettier: ^4.0.0 - husky: ^7.0.4 jest: ^27.3.1 - lint-staged: ^11.2.6 - prettier: ^2.4.1 + rome: ^11.0.0 source-map-support: ^0.5.21 ts-jest: ^27.1.0 ts-node: ^10.4.0 - typedoc: ^0.22.9 - typescript: 4.4.3 + typedoc: ^0.23 + typescript: 4.9 languageName: unknown linkType: soft @@ -4536,43 +3284,6 @@ __metadata: languageName: node linkType: hard -"object-inspect@npm:^1.12.2, object-inspect@npm:^1.9.0": - version: 1.12.2 - resolution: "object-inspect@npm:1.12.2" - checksum: a534fc1b8534284ed71f25ce3a496013b7ea030f3d1b77118f6b7b1713829262be9e6243acbcb3ef8c626e2b64186112cb7f6db74e37b2789b9c789ca23048b2 - languageName: node - linkType: hard - -"object-keys@npm:^1.1.1": - version: 1.1.1 - resolution: "object-keys@npm:1.1.1" - checksum: b363c5e7644b1e1b04aa507e88dcb8e3a2f52b6ffd0ea801e4c7a62d5aa559affe21c55a07fd4b1fd55fc03a33c610d73426664b20032405d7b92a1414c34d6a - languageName: node - linkType: hard - -"object.assign@npm:^4.1.4": - version: 4.1.4 - resolution: "object.assign@npm:4.1.4" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.4 - has-symbols: ^1.0.3 - object-keys: ^1.1.1 - checksum: 76cab513a5999acbfe0ff355f15a6a125e71805fcf53de4e9d4e082e1989bdb81d1e329291e1e4e0ae7719f0e4ef80e88fb2d367ae60500d79d25a6224ac8864 - languageName: node - linkType: hard - -"object.values@npm:^1.1.5": - version: 1.1.6 - resolution: "object.values@npm:1.1.6" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.4 - es-abstract: ^1.20.4 - checksum: f6fff9fd817c24cfd8107f50fb33061d81cd11bacc4e3dbb3852e9ff7692fde4dbce823d4333ea27cd9637ef1b6690df5fbb61f1ed314fa2959598dc3ae23d8e - languageName: node - linkType: hard - "once@npm:^1.3.0": version: 1.4.0 resolution: "once@npm:1.4.0" @@ -4582,7 +3293,7 @@ __metadata: languageName: node linkType: hard -"onetime@npm:^5.1.0, onetime@npm:^5.1.2": +"onetime@npm:^5.1.2": version: 5.1.2 resolution: "onetime@npm:5.1.2" dependencies: @@ -4605,20 +3316,6 @@ __metadata: languageName: node linkType: hard -"optionator@npm:^0.9.1": - version: 0.9.1 - resolution: "optionator@npm:0.9.1" - dependencies: - deep-is: ^0.1.3 - fast-levenshtein: ^2.0.6 - levn: ^0.4.1 - prelude-ls: ^1.2.1 - type-check: ^0.4.0 - word-wrap: ^1.2.3 - checksum: dbc6fa065604b24ea57d734261914e697bd73b69eff7f18e967e8912aa2a40a19a9f599a507fa805be6c13c24c4eae8c71306c239d517d42d4c041c942f508a0 - languageName: node - linkType: hard - "p-limit@npm:^2.2.0": version: 2.3.0 resolution: "p-limit@npm:2.3.0" @@ -4628,15 +3325,6 @@ __metadata: languageName: node linkType: hard -"p-limit@npm:^3.0.2": - version: 3.1.0 - resolution: "p-limit@npm:3.1.0" - dependencies: - yocto-queue: ^0.1.0 - checksum: 7c3690c4dbf62ef625671e20b7bdf1cbc9534e83352a2780f165b0d3ceba21907e77ad63401708145ca4e25bfc51636588d89a8c0aeb715e6c37d1c066430360 - languageName: node - linkType: hard - "p-locate@npm:^4.1.0": version: 4.1.0 resolution: "p-locate@npm:4.1.0" @@ -4646,15 +3334,6 @@ __metadata: languageName: node linkType: hard -"p-locate@npm:^5.0.0": - version: 5.0.0 - resolution: "p-locate@npm:5.0.0" - dependencies: - p-limit: ^3.0.2 - checksum: 1623088f36cf1cbca58e9b61c4e62bf0c60a07af5ae1ca99a720837356b5b6c5ba3eb1b2127e47a06865fee59dd0453cad7cc844cda9d5a62ac1a5a51b7c86d3 - languageName: node - linkType: hard - "p-map@npm:^4.0.0": version: 4.0.0 resolution: "p-map@npm:4.0.0" @@ -4671,16 +3350,7 @@ __metadata: languageName: node linkType: hard -"parent-module@npm:^1.0.0": - version: 1.0.1 - resolution: "parent-module@npm:1.0.1" - dependencies: - callsites: ^3.0.0 - checksum: 6ba8b255145cae9470cf5551eb74be2d22281587af787a2626683a6c20fbb464978784661478dd2a3f1dad74d1e802d403e1b03c1a31fab310259eec8ac560ff - languageName: node - linkType: hard - -"parse-json@npm:^5.0.0, parse-json@npm:^5.2.0": +"parse-json@npm:^5.2.0": version: 5.2.0 resolution: "parse-json@npm:5.2.0" dependencies: @@ -4727,13 +3397,6 @@ __metadata: languageName: node linkType: hard -"path-type@npm:^4.0.0": - version: 4.0.0 - resolution: "path-type@npm:4.0.0" - checksum: 5b1e2daa247062061325b8fdbfd1fb56dde0a448fb1455453276ea18c60685bdad23a445dc148cf87bc216be1573357509b7d4060494a6fd768c7efad833ee45 - languageName: node - linkType: hard - "picocolors@npm:^1.0.0": version: 1.0.0 resolution: "picocolors@npm:1.0.0" @@ -4764,22 +3427,6 @@ __metadata: languageName: node linkType: hard -"please-upgrade-node@npm:^3.2.0": - version: 3.2.0 - resolution: "please-upgrade-node@npm:3.2.0" - dependencies: - semver-compare: ^1.0.0 - checksum: d87c41581a2a022fbe25965a97006238cd9b8cbbf49b39f78d262548149a9d30bd2bdf35fec3d810e0001e630cd46ef13c7e19c389dea8de7e64db271a2381bb - languageName: node - linkType: hard - -"prelude-ls@npm:^1.2.1": - version: 1.2.1 - resolution: "prelude-ls@npm:1.2.1" - checksum: cd192ec0d0a8e4c6da3bb80e4f62afe336df3f76271ac6deb0e6a36187133b6073a19e9727a1ff108cd8b9982e4768850d413baa71214dd80c7979617dca827a - languageName: node - linkType: hard - "prelude-ls@npm:~1.1.2": version: 1.1.2 resolution: "prelude-ls@npm:1.1.2" @@ -4787,24 +3434,6 @@ __metadata: languageName: node linkType: hard -"prettier-linter-helpers@npm:^1.0.0": - version: 1.0.0 - resolution: "prettier-linter-helpers@npm:1.0.0" - dependencies: - fast-diff: ^1.1.2 - checksum: 00ce8011cf6430158d27f9c92cfea0a7699405633f7f1d4a45f07e21bf78e99895911cbcdc3853db3a824201a7c745bd49bfea8abd5fb9883e765a90f74f8392 - languageName: node - linkType: hard - -"prettier@npm:^2.4.1": - version: 2.8.1 - resolution: "prettier@npm:2.8.1" - bin: - prettier: bin-prettier.js - checksum: 4f21a0f1269f76fb36f54e9a8a1ea4c11e27478958bf860661fb4b6d7ac69aac1581f8724fa98ea3585e56d42a2ea317a17ff6e3324f40cb11ff9e20b73785cc - languageName: node - linkType: hard - "pretty-format@npm:^27.0.0, pretty-format@npm:^27.5.1": version: 27.5.1 resolution: "pretty-format@npm:27.5.1" @@ -4850,7 +3479,7 @@ __metadata: languageName: node linkType: hard -"punycode@npm:^2.1.0, punycode@npm:^2.1.1": +"punycode@npm:^2.1.1": version: 2.1.1 resolution: "punycode@npm:2.1.1" checksum: 823bf443c6dd14f669984dea25757b37993f67e8d94698996064035edd43bed8a5a17a9f12e439c2b35df1078c6bec05a6c86e336209eb1061e8025c481168e8 @@ -4864,13 +3493,6 @@ __metadata: languageName: node linkType: hard -"queue-microtask@npm:^1.2.2": - version: 1.2.3 - resolution: "queue-microtask@npm:1.2.3" - checksum: b676f8c040cdc5b12723ad2f91414d267605b26419d5c821ff03befa817ddd10e238d22b25d604920340fd73efd8ba795465a0377c4adf45a4a41e4234e42dc4 - languageName: node - linkType: hard - "ramda@npm:^0.27.1": version: 0.27.2 resolution: "ramda@npm:0.27.2" @@ -4896,24 +3518,6 @@ __metadata: languageName: node linkType: hard -"regexp.prototype.flags@npm:^1.4.3": - version: 1.4.3 - resolution: "regexp.prototype.flags@npm:1.4.3" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.3 - functions-have-names: ^1.2.2 - checksum: 51228bae732592adb3ededd5e15426be25f289e9c4ef15212f4da73f4ec3919b6140806374b8894036a86020d054a8d2657d3fee6bb9b4d35d8939c20030b7a6 - languageName: node - linkType: hard - -"regexpp@npm:^3.0.0, regexpp@npm:^3.2.0": - version: 3.2.0 - resolution: "regexpp@npm:3.2.0" - checksum: a78dc5c7158ad9ddcfe01aa9144f46e192ddbfa7b263895a70a5c6c73edd9ce85faf7c0430e59ac38839e1734e275b9c3de5c57ee3ab6edc0e0b1bdebefccef8 - languageName: node - linkType: hard - "require-directory@npm:^2.1.1": version: 2.1.1 resolution: "require-directory@npm:2.1.1" @@ -4937,13 +3541,6 @@ __metadata: languageName: node linkType: hard -"resolve-from@npm:^4.0.0": - version: 4.0.0 - resolution: "resolve-from@npm:4.0.0" - checksum: f4ba0b8494846a5066328ad33ef8ac173801a51739eb4d63408c847da9a2e1c1de1e6cbbf72699211f3d13f8fc1325648b169bd15eb7da35688e30a5fb0e4a7f - languageName: node - linkType: hard - "resolve-from@npm:^5.0.0": version: 5.0.0 resolution: "resolve-from@npm:5.0.0" @@ -4958,7 +3555,7 @@ __metadata: languageName: node linkType: hard -"resolve@npm:^1.10.1, resolve@npm:^1.20.0, resolve@npm:^1.22.0": +"resolve@npm:^1.20.0": version: 1.22.1 resolution: "resolve@npm:1.22.1" dependencies: @@ -4971,7 +3568,7 @@ __metadata: languageName: node linkType: hard -"resolve@patch:resolve@^1.10.1#~builtin, resolve@patch:resolve@^1.20.0#~builtin, resolve@patch:resolve@^1.22.0#~builtin": +"resolve@patch:resolve@^1.20.0#~builtin": version: 1.22.1 resolution: "resolve@patch:resolve@npm%3A1.22.1#~builtin::version=1.22.1&hash=c3c19d" dependencies: @@ -4984,16 +3581,6 @@ __metadata: languageName: node linkType: hard -"restore-cursor@npm:^3.1.0": - version: 3.1.0 - resolution: "restore-cursor@npm:3.1.0" - dependencies: - onetime: ^5.1.0 - signal-exit: ^3.0.2 - checksum: f877dd8741796b909f2a82454ec111afb84eb45890eb49ac947d87991379406b3b83ff9673a46012fca0d7844bb989f45cc5b788254cf1a39b6b5a9659de0630 - languageName: node - linkType: hard - "retry@npm:^0.12.0": version: 0.12.0 resolution: "retry@npm:0.12.0" @@ -5001,20 +3588,6 @@ __metadata: languageName: node linkType: hard -"reusify@npm:^1.0.4": - version: 1.0.4 - resolution: "reusify@npm:1.0.4" - checksum: c3076ebcc22a6bc252cb0b9c77561795256c22b757f40c0d8110b1300723f15ec0fc8685e8d4ea6d7666f36c79ccc793b1939c748bf36f18f542744a4e379fcc - languageName: node - linkType: hard - -"rfdc@npm:^1.3.0": - version: 1.3.0 - resolution: "rfdc@npm:1.3.0" - checksum: fb2ba8512e43519983b4c61bd3fa77c0f410eff6bae68b08614437bc3f35f91362215f7b4a73cbda6f67330b5746ce07db5dd9850ad3edc91271ad6deea0df32 - languageName: node - linkType: hard - "rimraf@npm:^3.0.0, rimraf@npm:^3.0.2": version: 3.0.2 resolution: "rimraf@npm:3.0.2" @@ -5026,21 +3599,32 @@ __metadata: languageName: node linkType: hard -"run-parallel@npm:^1.1.9": - version: 1.2.0 - resolution: "run-parallel@npm:1.2.0" - dependencies: - queue-microtask: ^1.2.2 - checksum: cb4f97ad25a75ebc11a8ef4e33bb962f8af8516bb2001082ceabd8902e15b98f4b84b4f8a9b222e5d57fc3bd1379c483886ed4619367a7680dad65316993021d - languageName: node - linkType: hard - -"rxjs@npm:^7.5.1": - version: 7.8.0 - resolution: "rxjs@npm:7.8.0" +"rome@npm:^11.0.0": + version: 11.0.0 + resolution: "rome@npm:11.0.0" dependencies: - tslib: ^2.1.0 - checksum: 61b4d4fd323c1043d8d6ceb91f24183b28bcf5def4f01ca111511d5c6b66755bc5578587fe714ef5d67cf4c9f2e26f4490d4e1d8cabf9bd5967687835e9866a2 + "@rometools/cli-darwin-arm64": 11.0.0 + "@rometools/cli-darwin-x64": 11.0.0 + "@rometools/cli-linux-arm64": 11.0.0 + "@rometools/cli-linux-x64": 11.0.0 + "@rometools/cli-win32-arm64": 11.0.0 + "@rometools/cli-win32-x64": 11.0.0 + dependenciesMeta: + "@rometools/cli-darwin-arm64": + optional: true + "@rometools/cli-darwin-x64": + optional: true + "@rometools/cli-linux-arm64": + optional: true + "@rometools/cli-linux-x64": + optional: true + "@rometools/cli-win32-arm64": + optional: true + "@rometools/cli-win32-x64": + optional: true + bin: + rome: bin/rome + checksum: 3c92a47c78a66c62f94b6a3a72ead92a20c23326d2d73785ce88c03897b60b8114c285a636acc24bd11039381ded48f8c58c6cc5c4cc46ce7eed092c90d9a054 languageName: node linkType: hard @@ -5051,17 +3635,6 @@ __metadata: languageName: node linkType: hard -"safe-regex-test@npm:^1.0.0": - version: 1.0.0 - resolution: "safe-regex-test@npm:1.0.0" - dependencies: - call-bind: ^1.0.2 - get-intrinsic: ^1.1.3 - is-regex: ^1.1.4 - checksum: bc566d8beb8b43c01b94e67de3f070fd2781685e835959bbbaaec91cc53381145ca91f69bd837ce6ec244817afa0a5e974fc4e40a2957f0aca68ac3add1ddd34 - languageName: node - linkType: hard - "safer-buffer@npm:>= 2.1.2 < 3, safer-buffer@npm:>= 2.1.2 < 3.0.0": version: 2.1.2 resolution: "safer-buffer@npm:2.1.2" @@ -5078,14 +3651,7 @@ __metadata: languageName: node linkType: hard -"semver-compare@npm:^1.0.0": - version: 1.0.0 - resolution: "semver-compare@npm:1.0.0" - checksum: dd1d7e2909744cf2cf71864ac718efc990297f9de2913b68e41a214319e70174b1d1793ac16e31183b128c2b9812541300cb324db8168e6cf6b570703b171c68 - languageName: node - linkType: hard - -"semver@npm:7.x, semver@npm:^7.3.2, semver@npm:^7.3.5, semver@npm:^7.3.7": +"semver@npm:7.x, semver@npm:^7.3.2, semver@npm:^7.3.5": version: 7.3.8 resolution: "semver@npm:7.3.8" dependencies: @@ -5096,7 +3662,7 @@ __metadata: languageName: node linkType: hard -"semver@npm:^6.0.0, semver@npm:^6.1.0, semver@npm:^6.3.0": +"semver@npm:^6.0.0, semver@npm:^6.3.0": version: 6.3.0 resolution: "semver@npm:6.3.0" bin: @@ -5128,25 +3694,14 @@ __metadata: languageName: node linkType: hard -"shiki@npm:^0.10.1": - version: 0.10.1 - resolution: "shiki@npm:0.10.1" +"shiki@npm:^0.11.1": + version: 0.11.1 + resolution: "shiki@npm:0.11.1" dependencies: jsonc-parser: ^3.0.0 vscode-oniguruma: ^1.6.1 - vscode-textmate: 5.2.0 - checksum: fb746f3cb3de7e545e3b10a6cb658d3938f840e4ccc9a3c90ceb7e69a8f89dbb432171faac1e9f02a03f103684dad88ee5e54b5c4964fa6b579fca6e8e26424d - languageName: node - linkType: hard - -"side-channel@npm:^1.0.4": - version: 1.0.4 - resolution: "side-channel@npm:1.0.4" - dependencies: - call-bind: ^1.0.0 - get-intrinsic: ^1.0.2 - object-inspect: ^1.9.0 - checksum: 351e41b947079c10bd0858364f32bb3a7379514c399edb64ab3dce683933483fc63fb5e4efe0a15a2e8a7e3c436b6a91736ddb8d8c6591b0460a24bb4a1ee245 + vscode-textmate: ^6.0.0 + checksum: 2a4ebc3b466816263fc244ae4f67a4ff96aa74d863b9c5e7e4affc50f37fd6d1a781405de0dbf763b777bc33e49a0d441de7ff3fededb8b01e3b8dbb37e2927d languageName: node linkType: hard @@ -5171,28 +3726,6 @@ __metadata: languageName: node linkType: hard -"slice-ansi@npm:^3.0.0": - version: 3.0.0 - resolution: "slice-ansi@npm:3.0.0" - dependencies: - ansi-styles: ^4.0.0 - astral-regex: ^2.0.0 - is-fullwidth-code-point: ^3.0.0 - checksum: 5ec6d022d12e016347e9e3e98a7eb2a592213a43a65f1b61b74d2c78288da0aded781f665807a9f3876b9daa9ad94f64f77d7633a0458876c3a4fdc4eb223f24 - languageName: node - linkType: hard - -"slice-ansi@npm:^4.0.0": - version: 4.0.0 - resolution: "slice-ansi@npm:4.0.0" - dependencies: - ansi-styles: ^4.0.0 - astral-regex: ^2.0.0 - is-fullwidth-code-point: ^3.0.0 - checksum: 4a82d7f085b0e1b070e004941ada3c40d3818563ac44766cca4ceadd2080427d337554f9f99a13aaeb3b4a94d9964d9466c807b3d7b7541d1ec37ee32d308756 - languageName: node - linkType: hard - "smart-buffer@npm:^4.2.0": version: 4.2.0 resolution: "smart-buffer@npm:4.2.0" @@ -5270,13 +3803,6 @@ __metadata: languageName: node linkType: hard -"string-argv@npm:0.3.1": - version: 0.3.1 - resolution: "string-argv@npm:0.3.1" - checksum: efbd0289b599bee808ce80820dfe49c9635610715429c6b7cc50750f0437e3c2f697c81e5c390208c13b5d5d12d904a1546172a88579f6ee5cbaaaa4dc9ec5cf - languageName: node - linkType: hard - "string-length@npm:^4.0.1": version: 4.0.2 resolution: "string-length@npm:4.0.2" @@ -5298,28 +3824,6 @@ __metadata: languageName: node linkType: hard -"string.prototype.trimend@npm:^1.0.6": - version: 1.0.6 - resolution: "string.prototype.trimend@npm:1.0.6" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.4 - es-abstract: ^1.20.4 - checksum: 0fdc34645a639bd35179b5a08227a353b88dc089adf438f46be8a7c197fc3f22f8514c1c9be4629b3cd29c281582730a8cbbad6466c60f76b5f99cf2addb132e - languageName: node - linkType: hard - -"string.prototype.trimstart@npm:^1.0.6": - version: 1.0.6 - resolution: "string.prototype.trimstart@npm:1.0.6" - dependencies: - call-bind: ^1.0.2 - define-properties: ^1.1.4 - es-abstract: ^1.20.4 - checksum: 89080feef416621e6ef1279588994305477a7a91648d9436490d56010a1f7adc39167cddac7ce0b9884b8cdbef086987c4dcb2960209f2af8bac0d23ceff4f41 - languageName: node - linkType: hard - "string_decoder@npm:^1.1.1": version: 1.3.0 resolution: "string_decoder@npm:1.3.0" @@ -5329,17 +3833,6 @@ __metadata: languageName: node linkType: hard -"stringify-object@npm:3.3.0": - version: 3.3.0 - resolution: "stringify-object@npm:3.3.0" - dependencies: - get-own-enumerable-property-symbols: ^3.0.0 - is-obj: ^1.0.1 - is-regexp: ^1.0.0 - checksum: 6827a3f35975cfa8572e8cd3ed4f7b262def260af18655c6fde549334acdac49ddba69f3c861ea5a6e9c5a4990fe4ae870b9c0e6c31019430504c94a83b7a154 - languageName: node - linkType: hard - "strip-ansi@npm:^6.0.0, strip-ansi@npm:^6.0.1": version: 6.0.1 resolution: "strip-ansi@npm:6.0.1" @@ -5349,13 +3842,6 @@ __metadata: languageName: node linkType: hard -"strip-bom@npm:^3.0.0": - version: 3.0.0 - resolution: "strip-bom@npm:3.0.0" - checksum: 8d50ff27b7ebe5ecc78f1fe1e00fcdff7af014e73cf724b46fb81ef889eeb1015fc5184b64e81a2efe002180f3ba431bdd77e300da5c6685d702780fbf0c8d5b - languageName: node - linkType: hard - "strip-bom@npm:^4.0.0": version: 4.0.0 resolution: "strip-bom@npm:4.0.0" @@ -5370,22 +3856,13 @@ __metadata: languageName: node linkType: hard -"strip-json-comments@npm:^3.1.0, strip-json-comments@npm:^3.1.1": +"strip-json-comments@npm:^3.1.1": version: 3.1.1 resolution: "strip-json-comments@npm:3.1.1" checksum: 492f73e27268f9b1c122733f28ecb0e7e8d8a531a6662efbd08e22cccb3f9475e90a1b82cab06a392f6afae6d2de636f977e231296400d0ec5304ba70f166443 languageName: node linkType: hard -"supports-color@npm:8.1.1, supports-color@npm:^8.0.0": - version: 8.1.1 - resolution: "supports-color@npm:8.1.1" - dependencies: - has-flag: ^4.0.0 - checksum: c052193a7e43c6cdc741eb7f378df605636e01ad434badf7324f17fb60c69a880d8d8fcdcb562cf94c2350e57b937d7425ab5b8326c67c2adc48f7c87c1db406 - languageName: node - linkType: hard - "supports-color@npm:^5.3.0": version: 5.5.0 resolution: "supports-color@npm:5.5.0" @@ -5404,6 +3881,15 @@ __metadata: languageName: node linkType: hard +"supports-color@npm:^8.0.0": + version: 8.1.1 + resolution: "supports-color@npm:8.1.1" + dependencies: + has-flag: ^4.0.0 + checksum: c052193a7e43c6cdc741eb7f378df605636e01ad434badf7324f17fb60c69a880d8d8fcdcb562cf94c2350e57b937d7425ab5b8326c67c2adc48f7c87c1db406 + languageName: node + linkType: hard + "supports-hyperlinks@npm:^2.0.0": version: 2.3.0 resolution: "supports-hyperlinks@npm:2.3.0" @@ -5463,13 +3949,6 @@ __metadata: languageName: node linkType: hard -"text-table@npm:^0.2.0": - version: 0.2.0 - resolution: "text-table@npm:0.2.0" - checksum: b6937a38c80c7f84d9c11dd75e49d5c44f71d95e810a3250bd1f1797fc7117c57698204adf676b71497acc205d769d65c16ae8fa10afad832ae1322630aef10a - languageName: node - linkType: hard - "throat@npm:^6.0.1": version: 6.0.1 resolution: "throat@npm:6.0.1" @@ -5477,13 +3956,6 @@ __metadata: languageName: node linkType: hard -"through@npm:^2.3.8": - version: 2.3.8 - resolution: "through@npm:2.3.8" - checksum: a38c3e059853c494af95d50c072b83f8b676a9ba2818dcc5b108ef252230735c54e0185437618596c790bbba8fcdaef5b290405981ffa09dce67b1f1bf190cbd - languageName: node - linkType: hard - "tmpl@npm:1.0.5": version: 1.0.5 resolution: "tmpl@npm:1.0.5" @@ -5599,52 +4071,6 @@ __metadata: languageName: node linkType: hard -"tsconfig-paths@npm:^3.14.1": - version: 3.14.1 - resolution: "tsconfig-paths@npm:3.14.1" - dependencies: - "@types/json5": ^0.0.29 - json5: ^1.0.1 - minimist: ^1.2.6 - strip-bom: ^3.0.0 - checksum: 8afa01c673ebb4782ba53d3a12df97fa837ce524f8ad38ee4e2b2fd57f5ac79abc21c574e9e9eb014d93efe7fe8214001b96233b5c6ea75bd1ea82afe17a4c6d - languageName: node - linkType: hard - -"tslib@npm:^1.8.1": - version: 1.14.1 - resolution: "tslib@npm:1.14.1" - checksum: dbe628ef87f66691d5d2959b3e41b9ca0045c3ee3c7c7b906cc1e328b39f199bb1ad9e671c39025bd56122ac57dfbf7385a94843b1cc07c60a4db74795829acd - languageName: node - linkType: hard - -"tslib@npm:^2.1.0": - version: 2.4.1 - resolution: "tslib@npm:2.4.1" - checksum: 19480d6e0313292bd6505d4efe096a6b31c70e21cf08b5febf4da62e95c265c8f571f7b36fcc3d1a17e068032f59c269fab3459d6cd3ed6949eafecf64315fca - languageName: node - linkType: hard - -"tsutils@npm:^3.21.0": - version: 3.21.0 - resolution: "tsutils@npm:3.21.0" - dependencies: - tslib: ^1.8.1 - peerDependencies: - typescript: ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" - checksum: 1843f4c1b2e0f975e08c4c21caa4af4f7f65a12ac1b81b3b8489366826259323feb3fc7a243123453d2d1a02314205a7634e048d4a8009921da19f99755cdc48 - languageName: node - linkType: hard - -"type-check@npm:^0.4.0, type-check@npm:~0.4.0": - version: 0.4.0 - resolution: "type-check@npm:0.4.0" - dependencies: - prelude-ls: ^1.2.1 - checksum: ec688ebfc9c45d0c30412e41ca9c0cdbd704580eb3a9ccf07b9b576094d7b86a012baebc95681999dd38f4f444afd28504cb3a89f2ef16b31d4ab61a0739025a - languageName: node - linkType: hard - "type-check@npm:~0.3.2": version: 0.3.2 resolution: "type-check@npm:0.3.2" @@ -5661,13 +4087,6 @@ __metadata: languageName: node linkType: hard -"type-fest@npm:^0.20.2": - version: 0.20.2 - resolution: "type-fest@npm:0.20.2" - checksum: 4fb3272df21ad1c552486f8a2f8e115c09a521ad7a8db3d56d53718d0c907b62c6e9141ba5f584af3f6830d0872c521357e512381f24f7c44acae583ad517d73 - languageName: node - linkType: hard - "type-fest@npm:^0.21.3": version: 0.21.3 resolution: "type-fest@npm:0.21.3" @@ -5684,52 +4103,39 @@ __metadata: languageName: node linkType: hard -"typedoc@npm:^0.22.9": - version: 0.22.18 - resolution: "typedoc@npm:0.22.18" +"typedoc@npm:^0.23": + version: 0.23.23 + resolution: "typedoc@npm:0.23.23" dependencies: - glob: ^8.0.3 lunr: ^2.3.9 - marked: ^4.0.16 - minimatch: ^5.1.0 - shiki: ^0.10.1 + marked: ^4.2.4 + minimatch: ^5.1.1 + shiki: ^0.11.1 peerDependencies: - typescript: 4.0.x || 4.1.x || 4.2.x || 4.3.x || 4.4.x || 4.5.x || 4.6.x || 4.7.x + typescript: 4.6.x || 4.7.x || 4.8.x || 4.9.x bin: typedoc: bin/typedoc - checksum: b813d8129682f6ed5a4e96bacaf019e4da1d2744ca89fef850d6bb4c034616567ce67e6a7f5cfc5f00aac573f0b45d44b1427aafa262ab88dce6b460cb9e744c + checksum: 2b64f9c9dc1992ec1bbcc688f6cfc8161481872c485ba9226d1797f572469d02f7798ebe96e3626587a6952af685fa1f4aaa0d9a6137fe9fb3d37f677cb41161 languageName: node linkType: hard -"typescript@npm:4.4.3": - version: 4.4.3 - resolution: "typescript@npm:4.4.3" +"typescript@npm:4.9": + version: 4.9.4 + resolution: "typescript@npm:4.9.4" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 05823f21796d450531a7e4ab299715d38fd9ded0e4ce7400876053f4b5166ca3dde7a68cecfe72d9086039f03c0b6edba36516fb10ed83c5837d9600532ea4c2 + checksum: e782fb9e0031cb258a80000f6c13530288c6d63f1177ed43f770533fdc15740d271554cdae86701c1dd2c83b082cea808b07e97fd68b38a172a83dbf9e0d0ef9 languageName: node linkType: hard -"typescript@patch:typescript@4.4.3#~builtin": - version: 4.4.3 - resolution: "typescript@patch:typescript@npm%3A4.4.3#~builtin::version=4.4.3&hash=bbeadb" +"typescript@patch:typescript@4.9#~builtin": + version: 4.9.4 + resolution: "typescript@patch:typescript@npm%3A4.9.4#~builtin::version=4.9.4&hash=ad5954" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 33a916819907e819430802c50405f18c187448d678696a81545f494a7ec16207f8c15340c945df62109bd1d951091a9f15f3d2eb931a3c889f962c8509017697 - languageName: node - linkType: hard - -"unbox-primitive@npm:^1.0.2": - version: 1.0.2 - resolution: "unbox-primitive@npm:1.0.2" - dependencies: - call-bind: ^1.0.2 - has-bigints: ^1.0.2 - has-symbols: ^1.0.3 - which-boxed-primitive: ^1.0.2 - checksum: b7a1cf5862b5e4b5deb091672ffa579aa274f648410009c81cca63fed3b62b610c4f3b773f912ce545bb4e31edc3138975b5bc777fc6e4817dca51affb6380e9 + checksum: 1caaea6cb7f813e64345190fddc4e6c924d0b698ab81189b503763c4a18f7f5501c69362979d36e19c042d89d936443e768a78b0675690b35eb663d19e0eae71 languageName: node linkType: hard @@ -5772,15 +4178,6 @@ __metadata: languageName: node linkType: hard -"uri-js@npm:^4.2.2": - version: 4.4.1 - resolution: "uri-js@npm:4.4.1" - dependencies: - punycode: ^2.1.0 - checksum: 7167432de6817fe8e9e0c9684f1d2de2bb688c94388f7569f7dbdb1587c9f4ca2a77962f134ec90be0cc4d004c939ff0d05acc9f34a0db39a3c797dada262633 - languageName: node - linkType: hard - "url-parse@npm:^1.5.3": version: 1.5.10 resolution: "url-parse@npm:1.5.10" @@ -5823,10 +4220,10 @@ __metadata: languageName: node linkType: hard -"vscode-textmate@npm:5.2.0": - version: 5.2.0 - resolution: "vscode-textmate@npm:5.2.0" - checksum: 5449b42d451080f6f3649b66948f4b5ee4643c4e88cfe3558a3b31c84c78060cfdd288c4958c1690eaa5cd65d09992fa6b7c3bef9d4aa72b3651054a04624d20 +"vscode-textmate@npm:^6.0.0": + version: 6.0.0 + resolution: "vscode-textmate@npm:6.0.0" + checksum: ff6f17a406c2906586afc14ef01cb122e33acd35312e815abb5c924347a777c6783ce3fe7db8b83f1760ebf843c669843b9390f905b69c433b3395af28e4b483 languageName: node linkType: hard @@ -5898,19 +4295,6 @@ __metadata: languageName: node linkType: hard -"which-boxed-primitive@npm:^1.0.2": - version: 1.0.2 - resolution: "which-boxed-primitive@npm:1.0.2" - dependencies: - is-bigint: ^1.0.1 - is-boolean-object: ^1.1.0 - is-number-object: ^1.0.4 - is-string: ^1.0.5 - is-symbol: ^1.0.3 - checksum: 53ce774c7379071729533922adcca47220228405e1895f26673bbd71bdf7fb09bee38c1d6399395927c6289476b5ae0629863427fd151491b71c4b6cb04f3a5e - languageName: node - linkType: hard - "which@npm:^2.0.1, which@npm:^2.0.2": version: 2.0.2 resolution: "which@npm:2.0.2" @@ -5931,24 +4315,13 @@ __metadata: languageName: node linkType: hard -"word-wrap@npm:^1.2.3, word-wrap@npm:~1.2.3": +"word-wrap@npm:~1.2.3": version: 1.2.3 resolution: "word-wrap@npm:1.2.3" checksum: 30b48f91fcf12106ed3186ae4fa86a6a1842416df425be7b60485de14bec665a54a68e4b5156647dec3a70f25e84d270ca8bc8cd23182ed095f5c7206a938c1f languageName: node linkType: hard -"wrap-ansi@npm:^6.2.0": - version: 6.2.0 - resolution: "wrap-ansi@npm:6.2.0" - dependencies: - ansi-styles: ^4.0.0 - string-width: ^4.1.0 - strip-ansi: ^6.0.0 - checksum: 6cd96a410161ff617b63581a08376f0cb9162375adeb7956e10c8cd397821f7eb2a6de24eb22a0b28401300bf228c86e50617cd568209b5f6775b93c97d2fe3a - languageName: node - linkType: hard - "wrap-ansi@npm:^7.0.0": version: 7.0.0 resolution: "wrap-ansi@npm:7.0.0" @@ -6022,13 +4395,6 @@ __metadata: languageName: node linkType: hard -"yaml@npm:^1.10.0": - version: 1.10.2 - resolution: "yaml@npm:1.10.2" - checksum: ce4ada136e8a78a0b08dc10b4b900936912d15de59905b2bf415b4d33c63df1d555d23acb2a41b23cf9fb5da41c256441afca3d6509de7247daa062fd2c5ea5f - languageName: node - linkType: hard - "yargs-parser@npm:20.x, yargs-parser@npm:^20.2.2": version: 20.2.9 resolution: "yargs-parser@npm:20.2.9" @@ -6057,10 +4423,3 @@ __metadata: checksum: 2c487b0e149e746ef48cda9f8bad10fc83693cd69d7f9dcd8be4214e985de33a29c9e24f3c0d6bcf2288427040a8947406ab27f7af67ee9456e6b84854f02dd6 languageName: node linkType: hard - -"yocto-queue@npm:^0.1.0": - version: 0.1.0 - resolution: "yocto-queue@npm:0.1.0" - checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700 - languageName: node - linkType: hard