Skip to content

Commit

Permalink
Merge branch 'main' of github.com:pola-rs/nodejs-polars into nodejs-p…
Browse files Browse the repository at this point in the history
…olars-v0.16.0
  • Loading branch information
universalmind303 committed Oct 7, 2024
2 parents cc49e3c + 0af68af commit 92b67a2
Show file tree
Hide file tree
Showing 29 changed files with 214 additions and 180 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-08-26
toolchain: nightly-2024-09-19
components: rustfmt, clippy
- name: Install ghp-import
uses: actions/setup-python@v5
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-08-26
toolchain: nightly-2024-09-19
components: rustfmt, clippy
- name: Check yarn version
run: yarn --version
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Install latest Rust nightly
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly-2024-08-26
toolchain: nightly-2024-09-19
components: rustfmt, clippy
- name: Bun version
uses: oven-sh/setup-bun@v1
Expand Down
46 changes: 26 additions & 20 deletions __tests__/dataframe.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import { Stream } from "node:stream";
/* eslint-disable newline-per-chained-call */
import pl from "@polars";
import { Stream } from "stream";
import fs from "fs";
describe("dataframe", () => {
const df = pl.DataFrame([
pl.Series("foo", [1, 2, 9], pl.Int16),
Expand Down Expand Up @@ -338,24 +338,30 @@ describe("dataframe", () => {
const actual = df.fold((a, b) => a.concat(b));
expect(actual).toSeriesEqual(expected);
});
// test("fold", () => {
// const s1 = pl.Series([1, 2, 3]);
// const s2 = pl.Series([4, 5, 6]);
// const s3 = pl.Series([7, 8, 1]);
// const expected = pl.Series("foo", [true, true, false]);
// const df = pl.DataFrame([s1, s2, s3]);
// const actual = df.fold((a, b) => a.lessThan(b)).alias("foo");
// expect(actual).toSeriesEqual(expected);
// });
// test("fold-again", () => {
// const s1 = pl.Series([1, 2, 3]);
// const s2 = pl.Series([4, 5, 6]);
// const s3 = pl.Series([7, 8, 1]);
// const expected = pl.Series("foo", [12, 15, 10]);
// const df = pl.DataFrame([s1, s2, s3]);
// const actual = df.fold((a, b) => a.plus(b)).alias("foo");
// expect(actual).toSeriesEqual(expected);
// });
it.each`
name | actual | expected
${"fold:lessThan"} | ${df.fold((a, b) => a.lessThan(b)).alias("foo")} | ${pl.Series("foo", [true, false, false])}
${"fold:lt"} | ${df.fold((a, b) => a.lt(b)).alias("foo")} | ${pl.Series("foo", [true, false, false])}
${"fold:lessThanEquals"} | ${df.fold((a, b) => a.lessThanEquals(b)).alias("foo")} | ${pl.Series("foo", [true, true, false])}
${"fold:ltEq"} | ${df.fold((a, b) => a.ltEq(b)).alias("foo")} | ${pl.Series("foo", [true, true, false])}
${"fold:neq"} | ${df.fold((a, b) => a.neq(b)).alias("foo")} | ${pl.Series("foo", [true, false, true])}
${"fold:plus"} | ${df.fold((a, b) => a.plus(b)).alias("foo")} | ${pl.Series("foo", [7, 4, 17])}
${"fold:minus"} | ${df.fold((a, b) => a.minus(b)).alias("foo")} | ${pl.Series("foo", [-5, 0, 1])}
${"fold:mul"} | ${df.fold((a, b) => a.mul(b)).alias("foo")} | ${pl.Series("foo", [6, 4, 72])}
`("$# $name expected matches actual", ({ expected, actual }) => {
expect(expected).toSeriesEqual(actual);
});
test("fold:lt", () => {
const s1 = pl.Series([1, 2, 3]);
const s2 = pl.Series([4, 5, 6]);
const s3 = pl.Series([7, 8, 1]);
const df = pl.DataFrame([s1, s2, s3]);
const expected = pl.Series("foo", [true, true, false]);
let actual = df.fold((a, b) => a.lessThan(b)).alias("foo");
expect(actual).toSeriesEqual(expected);
actual = df.fold((a, b) => a.lt(b)).alias("foo");
expect(actual).toSeriesEqual(expected);
});
test("frameEqual:true", () => {
const df = pl.DataFrame({
foo: [1, 2, 3],
Expand Down
6 changes: 3 additions & 3 deletions __tests__/io.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import { Stream } from "node:stream";
import pl from "@polars";
import path from "path";
import { Stream } from "stream";
import fs from "fs";
// eslint-disable-next-line no-undef
const csvpath = path.resolve(__dirname, "./examples/datasets/foods1.csv");
// eslint-disable-next-line no-undef
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lazyframe.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "node:fs";
import pl from "@polars";
import fs from "fs";

describe("lazyframe", () => {
test("columns", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/serde.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import pl from "@polars";
import path from "path";
// eslint-disable-next-line no-undef
const csvpath = path.resolve(__dirname, "./examples/datasets/foods1.csv");
describe("serde", () => {
Expand Down
8 changes: 2 additions & 6 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": false
},
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noParameterAssign": "off",
"useNodejsImportProtocol": "off"
"noParameterAssign": "off"
},
"suspicious": {
"noExplicitAny": "off",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
"precommit": "yarn lint && yarn test"
},
"devDependencies": {
"@biomejs/biome": "=1.8.3",
"@biomejs/biome": "=1.9.2",
"@napi-rs/cli": "^2.18.4",
"@types/chance": "^1.1.6",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.4",
"@types/jest": "^29.5.13",
"@types/node": "^22.5.5",
"chance": "^1.1.12",
"jest": "^29.7.0",
"source-map-support": "^0.5.21",
Expand Down
20 changes: 10 additions & 10 deletions polars/dataframe.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import pli from "./internals/polars_internal";
import { arrayToJsDataFrame } from "./internals/construction";
import { Stream, Writable } from "node:stream";
import { concat } from "./functions";
import {
_GroupBy,
DynamicGroupBy,
type GroupBy,
RollingGroupBy,
_GroupBy,
} from "./groupby";
import { _LazyDataFrame, type LazyDataFrame } from "./lazy/dataframe";
import { concat } from "./functions";
import { arrayToJsDataFrame } from "./internals/construction";
import pli from "./internals/polars_internal";
import { type LazyDataFrame, _LazyDataFrame } from "./lazy/dataframe";
import { Expr } from "./lazy/expr";
import { _Series, Series } from "./series";
import { Stream, Writable } from "stream";
import { Series, _Series } from "./series";
import type {
FillNullStrategy,
JoinOptions,
Expand All @@ -23,13 +23,13 @@ import type {
import { DataType } from "./datatypes";

import {
columnOrColumns,
columnOrColumnsStrict,
type ColumnSelection,
type ColumnsOrExpr,
type ExprOrString,
isSeriesArray,
type ValueOrArray,
columnOrColumns,
columnOrColumnsStrict,
isSeriesArray,
} from "./utils";

import type {
Expand Down
8 changes: 4 additions & 4 deletions polars/functions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type DataFrame, _DataFrame } from "./dataframe";
/* eslint-disable no-redeclare */
import { jsTypeToPolarsType } from "./internals/construction";
import { type Series, _Series } from "./series";
import { type DataFrame, _DataFrame } from "./dataframe";
import { type LazyDataFrame, _LazyDataFrame } from "./lazy/dataframe";
import pli from "./internals/polars_internal";
import { isDataFrameArray, isLazyDataFrameArray, isSeriesArray } from "./utils";
import { type LazyDataFrame, _LazyDataFrame } from "./lazy/dataframe";
import { type Series, _Series } from "./series";
import type { ConcatOptions } from "./types";
import { isDataFrameArray, isLazyDataFrameArray, isSeriesArray } from "./utils";

/**
* _Repeat a single value n times and collect into a Series._
Expand Down
4 changes: 2 additions & 2 deletions polars/groupby.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import util from "node:util";
import { type DataFrame, _DataFrame } from "./dataframe";
import * as utils from "./utils";
import util from "util";
import type { Expr } from "./lazy/expr";
import { col, exclude } from "./lazy/functions";
import * as utils from "./utils";
import type { ColumnsOrExpr, StartBy } from "./utils";

const inspect = Symbol.for("nodejs.util.inspect.custom");
Expand Down
6 changes: 3 additions & 3 deletions polars/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as series from "./series";
import * as df from "./dataframe";
import { DataType, Field as _field } from "./datatypes";
import * as series from "./series";
export { DataType } from "./datatypes";
import * as cfg from "./cfg";
import * as func from "./functions";
import pli from "./internals/polars_internal";
import * as io from "./io";
import * as cfg from "./cfg";
import * as ldf from "./lazy/dataframe";
import pli from "./internals/polars_internal";
export * from "./series";
export * from "./dataframe";
export * from "./functions";
Expand Down
8 changes: 4 additions & 4 deletions polars/internals/construction.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pli from "./polars_internal";
import { DataType, polarsTypeToConstructor } from "../datatypes";
import { isTypedArray } from "util/types";
import { Series } from "../series";
import { isTypedArray } from "node:util/types";
import { _DataFrame } from "../dataframe";
import { DataType, polarsTypeToConstructor } from "../datatypes";
import { FixedSizeList, TimeUnit } from "../datatypes/datatype";
import { Field } from "../datatypes/field";
import { Series } from "../series";
import pli from "./polars_internal";

export const jsTypeToPolarsType = (value: unknown): DataType => {
if (value === null) {
Expand Down
10 changes: 5 additions & 5 deletions polars/io.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type Readable, Stream } from "node:stream";
import { type DataFrame, _DataFrame } from "./dataframe";
import type { DataType } from "./datatypes";
import { concat } from "./functions";
import pli from "./internals/polars_internal";
import { type DataFrame, _DataFrame } from "./dataframe";
import { isPath } from "./utils";
import { type LazyDataFrame, _LazyDataFrame } from "./lazy/dataframe";
import { type Readable, Stream } from "stream";
import { concat } from "./functions";
import type { ScanParquetOptions, RowCount } from "./types";
import type { RowCount, ScanParquetOptions } from "./types";
import { isPath } from "./utils";

export interface ReadCsvOptions {
inferSchemaLength: number | null;
Expand Down
24 changes: 12 additions & 12 deletions polars/lazy/dataframe.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { type DataFrame, _DataFrame } from "../dataframe";
import { Expr, exprToLitOrExpr } from "./expr";
import pli from "../internals/polars_internal";
import {
columnOrColumnsStrict,
type ColumnSelection,
type ColumnsOrExpr,
type ExprOrString,
selectionToExprList,
type ValueOrArray,
} from "../utils";
import { _LazyGroupBy, type LazyGroupBy } from "./groupby";
import type { Series } from "../series";
import type { Deserialize, GroupByOps, Serialize } from "../shared_traits";
import type {
LazyOptions,
LazyJoinOptions,
LazyOptions,
SinkCsvOptions,
SinkParquetOptions,
} from "../types";
import type { Series } from "../series";
import {
type ColumnSelection,
type ColumnsOrExpr,
type ExprOrString,
type ValueOrArray,
columnOrColumnsStrict,
selectionToExprList,
} from "../utils";
import { Expr, exprToLitOrExpr } from "./expr";
import { type LazyGroupBy, _LazyGroupBy } from "./groupby";

const inspect = Symbol.for("nodejs.util.inspect.custom");

Expand Down
18 changes: 9 additions & 9 deletions polars/lazy/expr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ export type { ExprList as ListNamespace } from "./list";
export type { ExprDateTime as DatetimeNamespace } from "./datetime";
export type { ExprStruct as StructNamespace } from "./struct";

import { isRegExp } from "node:util/types";
import type { DataType } from "../../datatypes";
import pli from "../../internals/polars_internal";
import {
type ExprOrString,
selectionToExprList,
INSPECT_SYMBOL,
regexToString,
} from "../../utils";
import { Series } from "../../series";
import type {
Arithmetic,
Comparison,
Cumulative,
Deserialize,
EwmOps,
Rolling,
Round,
Sample,
Serialize,
EwmOps,
} from "../../shared_traits";
import type {
InterpolationMethod,
FillNullStrategy,
InterpolationMethod,
RankMethod,
} from "../../types";
import { isRegExp } from "util/types";
import {
type ExprOrString,
INSPECT_SYMBOL,
regexToString,
selectionToExprList,
} from "../../utils";
/**
* Expressions that can be used in various contexts.
*/
Expand Down
6 changes: 3 additions & 3 deletions polars/lazy/expr/list.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Expr, _Expr, exprToLitOrExpr } from "../expr";
import type { ListFunctions } from "../../shared_traits";
import { Series } from "../../series";
import pli from "../../internals/polars_internal";
import { Series } from "../../series";
import type { ListFunctions } from "../../shared_traits";
import { Expr, _Expr, exprToLitOrExpr } from "../expr";
import { concatList } from "../functions";

/**
Expand Down
2 changes: 1 addition & 1 deletion polars/lazy/expr/string.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StringFunctions } from "../../shared_traits";
import { DataType } from "../../datatypes";
import type { StringFunctions } from "../../shared_traits";
import { regexToString } from "../../utils";
import { Expr, _Expr, exprToLitOrExpr } from "../expr";
import { lit } from "../functions";
Expand Down
2 changes: 1 addition & 1 deletion polars/lazy/expr/struct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _Expr, type Expr } from "../expr";
import { type Expr, _Expr } from "../expr";

/**
* Struct functions
Expand Down
6 changes: 3 additions & 3 deletions polars/lazy/functions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Expr, _Expr, exprToLitOrExpr } from "./expr";
import { DataFrame } from "../dataframe";
import { DataType } from "../datatypes";
import pli from "../internals/polars_internal";
import { Series } from "../series";
import { DataFrame } from "../dataframe";
import { type ExprOrString, range, selectionToExprList } from "../utils";
import pli from "../internals/polars_internal";
import { Expr, _Expr, exprToLitOrExpr } from "./expr";

/**
* __A column in a DataFrame.__
Expand Down
4 changes: 2 additions & 2 deletions polars/lazy/groupby.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Expr } from "./expr";
import { selectionToExprList } from "../utils";
import { _LazyDataFrame, type LazyDataFrame } from "./dataframe";
import { type LazyDataFrame, _LazyDataFrame } from "./dataframe";
import type { Expr } from "./expr";

/** @ignore */
export const _LazyGroupBy = (_lgb: any): LazyGroupBy => {
Expand Down
2 changes: 1 addition & 1 deletion polars/lazy/whenthen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Expr } from "./expr";
import pli from "../internals/polars_internal";
import { Expr } from "./expr";

export interface When {
/** Values to return in case of the predicate being `true`.*/
Expand Down
Loading

0 comments on commit 92b67a2

Please sign in to comment.