Skip to content

Commit

Permalink
feat: switch DataFrame generic to its schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Ugzuzg committed Jan 26, 2025
1 parent 1b7a42f commit 49c0a0e
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 87 deletions.
65 changes: 65 additions & 0 deletions __tests__/type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { expectType } from "ts-expect";

import {
DataFrame,
type Float64,
type Int64,
type String as PlString,
type Series,
} from "../polars";

describe("type tests", () => {
it("is cleaned up later", () => {
const a = null as unknown as DataFrame<{
id: Int64;
age: Int64;
name: PlString;
}>;
const b = null as unknown as DataFrame<{
id: Int64;
age: Int64;
fl: Float64;
}>;
expectType<Series<Int64, "age">>(a.getColumn("age"));
expectType<
(Series<Int64, "id"> | Series<Int64, "age"> | Series<PlString, "name">)[]
>(a.getColumns());
expectType<DataFrame<{ id: Int64; age: Int64 }>>(a.drop("name"));
expectType<DataFrame<{ id: Int64 }>>(a.drop(["name", "age"]));
expectType<DataFrame<{ id: Int64 }>>(a.drop("name", "age"));
// expectType<Series<Int64, "age">>(a.age);
expectType<
DataFrame<{
id: Int64;
age: Int64;
age_right: Int64;
name: PlString;
fl: Float64;
}>
>(a.join(b, { on: ["id"] }));
expectType<
DataFrame<{
id: Int64;
age: Int64;
ageRight: Int64;
name: PlString;
fl: Float64;
}>
>(a.join(b, { on: ["id"], suffix: "Right" }));
expectType<
DataFrame<{
id: Int64;
id_right: Int64;
age: Int64;
name: PlString;
fl: Float64;
}>
>(a.join(b, { leftOn: "id", rightOn: ["age"] }));

const c = a.join(b, { on: ["id"], suffix: "Right" });

const d = DataFrame({ a: [1n, 2n], id: [3, 4] })
.join(a, { on: "id" })
.getColumn("id");
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"chance": "^1.1.12",
"jest": "^29.7.0",
"source-map-support": "^0.5.21",
"ts-expect": "^1.3.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typedoc": "^0.27.3",
Expand Down
Loading

0 comments on commit 49c0a0e

Please sign in to comment.