@@ -45,7 +45,7 @@ describe("dataframe", () => {
45
45
const actual = expected . clone ( ) ;
46
46
expect ( actual ) . toFrameEqual ( expected ) ;
47
47
} ) ;
48
- test . skip ( "describe" , ( ) => {
48
+ test ( "describe" , ( ) => {
49
49
const actual = pl
50
50
. DataFrame ( {
51
51
a : [ 1 , 2 , 3 ] ,
@@ -56,8 +56,8 @@ describe("dataframe", () => {
56
56
const expected = pl . DataFrame ( {
57
57
describe : [ "mean" , "std" , "min" , "max" , "median" ] ,
58
58
a : [ 2 , 1 , 1 , 3 , 2 ] ,
59
- b : [ null , null , null , null , null ] ,
60
- c : [ null , null , 0 , 1 , null ] ,
59
+ b : [ null , null , "a" , "c" , null ] ,
60
+ c : [ 0.6666666666666666 , 0.5773502588272095 , 0 , 1 , 1 ] ,
61
61
} ) ;
62
62
63
63
expect ( actual ) . toFrameEqual ( expected ) ;
@@ -192,13 +192,22 @@ describe("dataframe", () => {
192
192
expect ( actual ) . toFrameEqual ( expected ) ;
193
193
} ) ;
194
194
} ) ;
195
+ test ( "unnest" , ( ) => {
196
+ const expected = pl . DataFrame ( {
197
+ int : [ 1 , 2 ] ,
198
+ str : [ "a" , "b" ] ,
199
+ bool : [ true , null ] ,
200
+ list : [ [ 1 , 2 ] , [ 3 ] ] ,
201
+ } ) ;
202
+ const actual = expected . toStruct ( "my_struct" ) . toFrame ( ) . unnest ( "my_struct" ) ;
203
+ expect ( actual ) . toFrameEqual ( expected ) ;
204
+ } ) ;
195
205
test ( "DF with nulls" , ( ) => {
196
- const actual = pl
197
- . DataFrame ( [
198
- { foo : 1 , bar : 6.0 , ham : "a" } ,
199
- { foo : null , bar : 0.5 , ham : "b" } ,
200
- { foo : 3 , bar : 7.0 , ham : "c" } ,
201
- ] ) ;
206
+ const actual = pl . DataFrame ( [
207
+ { foo : 1 , bar : 6.0 , ham : "a" } ,
208
+ { foo : null , bar : 0.5 , ham : "b" } ,
209
+ { foo : 3 , bar : 7.0 , ham : "c" } ,
210
+ ] ) ;
202
211
const expected = pl . DataFrame ( {
203
212
foo : [ 1 , null , 3 ] ,
204
213
bar : [ 6.0 , 0.5 , 7.0 ] ,
@@ -284,7 +293,35 @@ describe("dataframe", () => {
284
293
} ) ;
285
294
expect ( actual ) . toFrameEqual ( expected ) ;
286
295
} ) ;
287
- // test.todo("filter");
296
+ test ( "filter" , ( ) => {
297
+ const df = pl . DataFrame ( {
298
+ foo : [ 1 , 2 , 3 ] ,
299
+ bar : [ 6 , 7 , 8 ] ,
300
+ ham : [ "a" , "b" , "c" ] ,
301
+ } ) ;
302
+ // Filter on one condition
303
+ let actual = df . filter ( pl . col ( "foo" ) . lt ( 3 ) ) ;
304
+ let expected = pl . DataFrame ( {
305
+ foo : [ 1 , 2 ] ,
306
+ bar : [ 6 , 7 ] ,
307
+ ham : [ "a" , "b" ] ,
308
+ } ) ;
309
+ expect ( actual ) . toFrameEqual ( expected ) ;
310
+
311
+ // Filter on multiple conditions
312
+ actual = df . filter (
313
+ pl
314
+ . col ( "foo" )
315
+ . lt ( 3 )
316
+ . and ( pl . col ( "ham" ) . eq ( pl . lit ( "a" ) ) ) ,
317
+ ) ;
318
+ expected = pl . DataFrame ( {
319
+ foo : [ 1 ] ,
320
+ bar : [ 6 ] ,
321
+ ham : [ "a" ] ,
322
+ } ) ;
323
+ expect ( actual ) . toFrameEqual ( expected ) ;
324
+ } ) ;
288
325
test ( "findIdxByName" , ( ) => {
289
326
const actual = pl
290
327
. DataFrame ( {
@@ -296,12 +333,12 @@ describe("dataframe", () => {
296
333
const expected = 2 ;
297
334
expect ( actual ) . toEqual ( expected ) ;
298
335
} ) ;
299
- // test("fold:single column", () => {
300
- // const expected = pl.Series([1, 2, 3]);
301
- // const df = pl.DataFrame([expected]);
302
- // const actual = df.fold((a, b) => a.concat(b));
303
- // expect(actual).toSeriesEqual(expected);
304
- // });
336
+ test ( "fold:single column" , ( ) => {
337
+ const expected = pl . Series ( [ 1 , 2 , 3 ] ) ;
338
+ const df = pl . DataFrame ( [ expected ] ) ;
339
+ const actual = df . fold ( ( a , b ) => a . concat ( b ) ) ;
340
+ expect ( actual ) . toSeriesEqual ( expected ) ;
341
+ } ) ;
305
342
// test("fold", () => {
306
343
// const s1 = pl.Series([1, 2, 3]);
307
344
// const s2 = pl.Series([4, 5, 6]);
@@ -611,10 +648,23 @@ describe("dataframe", () => {
611
648
ham : [ "a" , "b" , "c" ] ,
612
649
} )
613
650
. median ( ) ;
614
-
615
651
expect ( actual . row ( 0 ) ) . toEqual ( [ 2 , 7 , null ] ) ;
616
652
} ) ;
617
- test . todo ( "melt" ) ;
653
+ test ( "melt" , ( ) => {
654
+ const df = pl . DataFrame ( {
655
+ id : [ 1 ] ,
656
+ asset_key_1 : [ "123" ] ,
657
+ asset_key_2 : [ "456" ] ,
658
+ asset_key_3 : [ "abc" ] ,
659
+ } ) ;
660
+ const actual = df . melt ( "id" , [ "asset_key_1" , "asset_key_2" , "asset_key_3" ] ) ;
661
+ const expected = pl . DataFrame ( {
662
+ id : [ 1 , 1 , 1 ] ,
663
+ variable : [ "asset_key_1" , "asset_key_2" , "asset_key_3" ] ,
664
+ value : [ "123" , "456" , "abc" ] ,
665
+ } ) ;
666
+ expect ( actual ) . toFrameEqual ( expected ) ;
667
+ } ) ;
618
668
test ( "min:axis:0" , ( ) => {
619
669
const actual = pl
620
670
. DataFrame ( {
@@ -765,7 +815,7 @@ describe("dataframe", () => {
765
815
expect ( fn ) . toThrow ( TypeError ) ;
766
816
} ) ;
767
817
test ( "select:strings" , ( ) => {
768
- const columns = [ "ham" , "foo" ]
818
+ const columns = [ "ham" , "foo" ] ;
769
819
const actual = pl
770
820
. DataFrame ( {
771
821
foo : [ 1 , 2 , 3 , 1 ] ,
@@ -986,7 +1036,7 @@ describe("dataframe", () => {
986
1036
const expected = [ 9 , 8 ] ;
987
1037
expect ( actual ) . toEqual ( expected ) ;
988
1038
} ) ;
989
- test . skip ( "transpose" , ( ) => {
1039
+ test ( "transpose" , ( ) => {
990
1040
const expected = pl . DataFrame ( {
991
1041
column_0 : [ 1 , 1 ] ,
992
1042
column_1 : [ 2 , 2 ] ,
@@ -999,9 +1049,9 @@ describe("dataframe", () => {
999
1049
const actual = df . transpose ( ) ;
1000
1050
expect ( actual ) . toFrameEqual ( expected ) ;
1001
1051
} ) ;
1002
- test . skip ( "transpose:includeHeader" , ( ) => {
1052
+ test ( "transpose:includeHeader" , ( ) => {
1003
1053
const expected = pl . DataFrame ( {
1004
- column : [ "a" , "b" ] ,
1054
+ "" : [ "a" , "b" ] ,
1005
1055
column_0 : [ 1 , 1 ] ,
1006
1056
column_1 : [ 2 , 2 ] ,
1007
1057
column_2 : [ 3 , 3 ] ,
@@ -1013,7 +1063,7 @@ describe("dataframe", () => {
1013
1063
const actual = df . transpose ( { includeHeader : true } ) ;
1014
1064
expect ( actual ) . toFrameEqual ( expected ) ;
1015
1065
} ) ;
1016
- test . skip ( "transpose:columnNames" , ( ) => {
1066
+ test ( "transpose:columnNames" , ( ) => {
1017
1067
const expected = pl . DataFrame ( {
1018
1068
a : [ 1 , 1 ] ,
1019
1069
b : [ 2 , 2 ] ,
@@ -1026,7 +1076,7 @@ describe("dataframe", () => {
1026
1076
const actual = df . transpose ( { includeHeader : false , columnNames : "abc" } ) ;
1027
1077
expect ( actual ) . toFrameEqual ( expected ) ;
1028
1078
} ) ;
1029
- test . skip ( "transpose:columnNames:generator" , ( ) => {
1079
+ test ( "transpose:columnNames:generator" , ( ) => {
1030
1080
const expected = pl . DataFrame ( {
1031
1081
col_0 : [ 1 , 1 ] ,
1032
1082
col_1 : [ 2 , 2 ] ,
@@ -1036,7 +1086,7 @@ describe("dataframe", () => {
1036
1086
const baseName = "col_" ;
1037
1087
let count = 0 ;
1038
1088
while ( true ) {
1039
- let name = `${ baseName } ${ count } ` ;
1089
+ const name = `${ baseName } ${ count } ` ;
1040
1090
yield name ;
1041
1091
count ++ ;
1042
1092
}
@@ -1553,7 +1603,7 @@ describe("io", () => {
1553
1603
callback ( null ) ;
1554
1604
} ,
1555
1605
} ) ;
1556
- df . writeJSON ( writeStream , { format : "lines " } ) ;
1606
+ df . writeJSON ( writeStream , { format : "json " } ) ;
1557
1607
const newDF = pl . readJSON ( body ) . select ( "foo" , "bar" ) ;
1558
1608
expect ( newDF ) . toFrameEqual ( df ) ;
1559
1609
done ( ) ;
@@ -1563,7 +1613,7 @@ describe("io", () => {
1563
1613
pl . Series ( "foo" , [ 1 , 2 , 3 ] , pl . UInt32 ) ,
1564
1614
pl . Series ( "bar" , [ "a" , "b" , "c" ] ) ,
1565
1615
] ) ;
1566
- df . writeJSON ( "./test.json" , { format : "lines " } ) ;
1616
+ df . writeJSON ( "./test.json" , { format : "json " } ) ;
1567
1617
const newDF = pl . readJSON ( "./test.json" ) . select ( "foo" , "bar" ) ;
1568
1618
expect ( newDF ) . toFrameEqual ( df ) ;
1569
1619
fs . rmSync ( "./test.json" ) ;
0 commit comments