Skip to content

Commit d83120a

Browse files
committed
feat: switch DataFrame generic to its schema
1 parent 1b7a42f commit d83120a

File tree

6 files changed

+350
-170
lines changed

6 files changed

+350
-170
lines changed

__tests__/type.test.ts

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { expectType } from "ts-expect";
2+
3+
import {
4+
DataFrame,
5+
type Float64,
6+
type Int64,
7+
type String as PlString,
8+
type Series,
9+
} from "../polars";
10+
11+
describe("type tests", () => {
12+
it("is cleaned up later", () => {
13+
const a = null as unknown as DataFrame<{
14+
id: Int64;
15+
age: Int64;
16+
name: PlString;
17+
}>;
18+
const b = null as unknown as DataFrame<{
19+
id: Int64;
20+
age: Int64;
21+
fl: Float64;
22+
}>;
23+
expectType<Series<Int64, "age">>(a.getColumn("age"));
24+
expectType<
25+
(Series<Int64, "id"> | Series<Int64, "age"> | Series<PlString, "name">)[]
26+
>(a.getColumns());
27+
expectType<DataFrame<{ id: Int64; age: Int64 }>>(a.drop("name"));
28+
expectType<DataFrame<{ id: Int64 }>>(a.drop(["name", "age"]));
29+
expectType<DataFrame<{ id: Int64 }>>(a.drop("name", "age"));
30+
// expectType<Series<Int64, "age">>(a.age);
31+
expectType<
32+
DataFrame<{
33+
id: Int64;
34+
age: Int64;
35+
age_right: Int64;
36+
name: PlString;
37+
fl: Float64;
38+
}>
39+
>(a.join(b, { on: ["id"] }));
40+
expectType<
41+
DataFrame<{
42+
id: Int64;
43+
age: Int64;
44+
ageRight: Int64;
45+
name: PlString;
46+
fl: Float64;
47+
}>
48+
>(a.join(b, { on: ["id"], suffix: "Right" }));
49+
expectType<
50+
DataFrame<{
51+
id: Int64;
52+
id_right: Int64;
53+
age: Int64;
54+
name: PlString;
55+
fl: Float64;
56+
}>
57+
>(a.join(b, { leftOn: "id", rightOn: ["age"] }));
58+
expectType<
59+
DataFrame<{
60+
id: Int64;
61+
id_right: Int64;
62+
age: Int64;
63+
age_right: Int64;
64+
name: PlString;
65+
fl: Float64;
66+
}>
67+
>(a.join(b, { how: "cross" }));
68+
});
69+
70+
it("folds", () => {
71+
const df = DataFrame({
72+
a: [2, 1, 3],
73+
b: [1, 2, 3],
74+
c: [1.0, 2.0, 3.0],
75+
});
76+
expectType<Series<Float64, string>>(df.fold((s1, s2) => s1.plus(s2)));
77+
});
78+
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"chance": "^1.1.12",
6363
"jest": "^29.7.0",
6464
"source-map-support": "^0.5.21",
65+
"ts-expect": "^1.3.0",
6566
"ts-jest": "^29.2.5",
6667
"ts-node": "^10.9.2",
6768
"typedoc": "^0.27.3",

0 commit comments

Comments
 (0)