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 d83120a
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 170 deletions.
78 changes: 78 additions & 0 deletions __tests__/type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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"] }));
expectType<
DataFrame<{
id: Int64;
id_right: Int64;
age: Int64;
age_right: Int64;
name: PlString;
fl: Float64;
}>
>(a.join(b, { how: "cross" }));
});

it("folds", () => {
const df = DataFrame({
a: [2, 1, 3],
b: [1, 2, 3],
c: [1.0, 2.0, 3.0],
});
expectType<Series<Float64, string>>(df.fold((s1, s2) => s1.plus(s2)));
});
});
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 d83120a

Please sign in to comment.