-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
struct.test.ts
52 lines (50 loc) · 1.24 KB
/
struct.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pl from "@polars";
describe("struct", () => {
test("series <--> array round trip", () => {
const data = [
{ utf8: "a", f64: 1 },
{ utf8: "b", f64: 2 },
];
const name = "struct";
const s = pl.Series(name, data);
expect(s.name).toEqual(name);
expect(s.toArray()).toEqual(data);
});
test("pli.struct", () => {
const expected = pl
.DataFrame({
foo: [1],
bar: [2],
})
.toStruct("foo");
const foo = pl.Series("foo", [1]);
const bar = pl.Series("bar", [2]);
const actual = pl.struct([foo, bar]).rename("foo");
expect(actual).toSeriesEqual(expected);
});
test("pli.struct dataframe", () => {
const df = pl.DataFrame({
foo: [1],
bar: [2],
});
const actual = df
.select(pl.struct(pl.cols("foo", "bar")).alias("s"))
.toSeries();
expect(actual).toSeriesEqual(df.toStruct("s"));
});
test("struct toArray", () => {
const actual = pl
.DataFrame({
foo: [1, 10, 100],
bar: [2, null, 200],
})
.toStruct("foobar")
.toArray();
const expected = [
{ foo: 1, bar: 2 },
{ foo: 10, bar: null },
{ foo: 100, bar: 200 },
];
expect(actual).toEqual(expected);
});
});