Skip to content

Commit a0514ee

Browse files
committed
feat: type cross join
1 parent 49c0a0e commit a0514ee

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

__tests__/type.test.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,15 @@ describe("type tests", () => {
5555
fl: Float64;
5656
}>
5757
>(a.join(b, { leftOn: "id", rightOn: ["age"] }));
58-
59-
const c = a.join(b, { on: ["id"], suffix: "Right" });
60-
61-
const d = DataFrame({ a: [1n, 2n], id: [3, 4] })
62-
.join(a, { on: "id" })
63-
.getColumn("id");
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" }));
6468
});
6569
});

polars/dataframe.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,25 @@ type JoinSchemas<
206206
[K_SUFFIXED in keyof S1 &
207207
Exclude<
208208
keyof S2,
209-
Opt extends Pick<JoinOptions, "on">
210-
? ExtractJoinKeys<Opt["on"]>
211-
: Opt extends Pick<JoinOptions, "leftOn" | "rightOn">
212-
? ExtractJoinKeys<Opt["rightOn"]>
213-
: never
209+
Opt extends { how: "cross" }
210+
? never
211+
: Opt extends Pick<JoinOptions, "on">
212+
? ExtractJoinKeys<Opt["on"]>
213+
: Opt extends Pick<JoinOptions, "leftOn" | "rightOn">
214+
? ExtractJoinKeys<Opt["rightOn"]>
215+
: never
214216
> as `${K_SUFFIXED extends string ? K_SUFFIXED : never}${ExtractSuffix<Opt>}`]: K_SUFFIXED extends string
215217
? S2[K_SUFFIXED]
216218
: never;
217219
}
218220
>;
219221

220-
type JoinDataFrames<T1, T2, Opt extends JoinOptions> = T1 extends DataFrame<
221-
infer T1Schema
222-
>
223-
? T2 extends DataFrame<infer T2Schema>
224-
? DataFrame<JoinSchemas<T1Schema, T2Schema, Opt>>
225-
: never
226-
: never;
222+
type JoinDataFrames<T1, T2, Opt extends JoinOptions> =
223+
T1 extends DataFrame<infer T1Schema>
224+
? T2 extends DataFrame<infer T2Schema>
225+
? DataFrame<JoinSchemas<T1Schema, T2Schema, Opt>>
226+
: never
227+
: never;
227228

228229
/**
229230
* A DataFrame is a two-dimensional data structure that represents data as a table

0 commit comments

Comments
 (0)