@@ -23,6 +23,13 @@ describe("from lists", () => {
23
23
const actual = pl . Series ( expected ) . toArray ( ) ;
24
24
expect ( actual ) . toEqual ( expected ) ;
25
25
} ) ;
26
+ test ( "fromArray" , ( ) => {
27
+ const actual = pl . Series . from ( "foo" , [ 1 , 2 , 3 ] ) ;
28
+ const expected = pl . Series ( "foo" , [ 1 , 2 , 3 ] ) ;
29
+ expect ( actual ) . toSeriesEqual ( expected ) ;
30
+ const actual2 = pl . Series . from ( [ 1 , 2 , 3 ] ) ;
31
+ expect ( actual2 ) . toSeriesEqual ( expected ) ;
32
+ } ) ;
26
33
} ) ;
27
34
describe ( "typedArrays" , ( ) => {
28
35
test ( "int8" , ( ) => {
@@ -246,20 +253,12 @@ describe("series", () => {
246
253
} ) ;
247
254
} ) ;
248
255
} ) ;
249
- describe ( "series" , ( ) => {
256
+ describe ( "series functions " , ( ) => {
250
257
const numSeries = ( ) => pl . Series ( "foo" , [ 1 , 2 , 3 ] , pl . Int32 ) ;
251
258
const fltSeries = ( ) => pl . Series ( "float" , [ 1 , 2 , 3 ] , pl . Float64 ) ;
252
259
const boolSeries = ( ) => pl . Series ( "bool" , [ true , false , false ] ) ;
253
260
const other = ( ) => pl . Series ( "bar" , [ 3 , 4 , 5 ] , pl . Int32 ) ;
254
-
255
261
const chance = new Chance ( ) ;
256
-
257
- // test("to/fromBinary round trip", () => {
258
- // const s = pl.Series("serde", [1, 2, 3, 4, 5, 2]);
259
- // const buf = s.toBinary();
260
- // const actual = pl.Series.fromBinary(buf);
261
- // expect(s).toStrictEqual(actual);
262
- // });
263
262
it . each `
264
263
series | getter
265
264
${ numSeries ( ) } | ${ "dtype" }
@@ -297,6 +296,7 @@ describe("series", () => {
297
296
${ numSeries ( ) } | ${ "diff" } | ${ [ 1 , "drop" ] }
298
297
${ numSeries ( ) } | ${ "dot" } | ${ [ other ( ) ] }
299
298
${ numSeries ( ) } | ${ "dropNulls" } | ${ [ ] }
299
+ ${ numSeries ( ) } | ${ "explode" } | ${ [ ] }
300
300
${ numSeries ( ) } | ${ "fillNull" } | ${ [ "zero" ] }
301
301
${ numSeries ( ) } | ${ "fillNull" } | ${ [ { strategy : "zero" } ] }
302
302
${ numSeries ( ) } | ${ "filter" } | ${ [ boolSeries ( ) ] }
@@ -390,6 +390,7 @@ describe("series", () => {
390
390
${ numSeries ( ) } | ${ "rollingSum" } | ${ [ 1 , [ 0.11 ] ] }
391
391
${ numSeries ( ) } | ${ "rollingSum" } | ${ [ 1 , [ 0.11 ] , 1 ] }
392
392
${ numSeries ( ) } | ${ "rollingSum" } | ${ [ 1 , [ 0.23 ] , 1 , true ] }
393
+ ${ numSeries ( ) } | ${ "rollingStd" } | ${ [ 1 , [ 0.23 ] , 1 , true ] }
393
394
${ numSeries ( ) } | ${ "rollingVar" } | ${ [ { windowSize : 1 } ] }
394
395
${ numSeries ( ) } | ${ "rollingVar" } | ${ [ { windowSize : 1 , weights : [ 0.33 ] } ] }
395
396
${ numSeries ( ) } | ${ "rollingVar" } | ${ [ { windowSize : 1 , weights : [ 0.11 ] , minPeriods : 1 } ] }
@@ -418,6 +419,7 @@ describe("series", () => {
418
419
${ numSeries ( ) } | ${ "shift" } | ${ [ 1 ] }
419
420
${ numSeries ( ) } | ${ "shiftAndFill" } | ${ [ 1 , 2 ] }
420
421
${ numSeries ( ) } | ${ "shiftAndFill" } | ${ [ { periods : 1 , fillValue : 2 } ] }
422
+ ${ numSeries ( ) } | ${ "shrinkToFit" } | ${ [ 1 , 2 ] }
421
423
${ numSeries ( ) } | ${ "skew" } | ${ [ ] }
422
424
${ numSeries ( ) } | ${ "skew" } | ${ [ true ] }
423
425
${ numSeries ( ) } | ${ "skew" } | ${ [ false ] }
@@ -482,6 +484,7 @@ describe("series", () => {
482
484
${ "dropNulls" } | ${ pl . Series ( [ 1 , null , 2 ] ) . dropNulls ( ) } | ${ pl . Series ( [ 1 , 2 ] ) }
483
485
${ "dropNulls" } | ${ pl . Series ( [ 1 , undefined , 2 ] ) . dropNulls ( ) } | ${ pl . Series ( [ 1 , 2 ] ) }
484
486
${ "dropNulls" } | ${ pl . Series ( [ "a" , null , "f" ] ) . dropNulls ( ) } | ${ pl . Series ( [ "a" , "f" ] ) }
487
+ ${ "explode" } | ${ pl . Series . from ( "foo" , [ [ 1n , 2n ] , [ 3n , 4n ] , [ null ] , [ ] ] ) . explode ( ) } | ${ pl . Series ( [ 1 , 2 , 3 , 4 , null , null ] ) }
485
488
${ "fillNull:zero" } | ${ pl . Series ( [ 1 , null , 2 ] ) . fillNull ( "zero" ) } | ${ pl . Series ( [ 1 , 0 , 2 ] ) }
486
489
${ "fillNull:one" } | ${ pl . Series ( [ 1 , null , 2 ] ) . fillNull ( "one" ) } | ${ pl . Series ( [ 1 , 1 , 2 ] ) }
487
490
${ "fillNull:max" } | ${ pl . Series ( [ 1 , null , 5 ] ) . fillNull ( "max" ) } | ${ pl . Series ( [ 1 , 5 , 5 ] ) }
@@ -504,6 +507,7 @@ describe("series", () => {
504
507
${ "isDateTime" } | ${ pl . Series ( [ new Date ( Date . now ( ) ) ] ) . isDateTime ( ) } | ${ true }
505
508
${ "isDuplicated" } | ${ pl . Series ( [ 1 , 3 , 3 ] ) . isDuplicated ( ) } | ${ pl . Series ( [ false , true , true ] ) }
506
509
${ "isFinite" } | ${ pl . Series ( [ 1.0 , 3.1 ] ) . isFinite ( ) } | ${ pl . Series ( [ true , true ] ) }
510
+ ${ "isFinite" } | ${ pl . Series ( [ 1 , 1 / 0 ] ) . isFinite ( ) } | ${ pl . Series ( [ true , false ] ) }
507
511
${ "isInfinite" } | ${ pl . Series ( [ 1.0 , 2 ] ) . isInfinite ( ) } | ${ pl . Series ( [ false , false ] ) }
508
512
${ "isNotNull" } | ${ pl . Series ( [ 1 , null , undefined , 2 ] ) . isNotNull ( ) } | ${ pl . Series ( [ true , false , false , true ] ) }
509
513
${ "isNull" } | ${ pl . Series ( [ 1 , null , undefined , 2 ] ) . isNull ( ) } | ${ pl . Series ( [ false , true , true , false ] ) }
@@ -531,6 +535,8 @@ describe("series", () => {
531
535
${ "rollingSum" } | ${ pl . Series ( [ 1 , 2 , 3 , 2 , 1 ] ) . rollingSum ( 2 ) } | ${ pl . Series ( "" , [ null , 3 , 5 , 5 , 3 ] , pl . Float64 ) }
532
536
${ "rollingMean" } | ${ pl . Series ( [ 1 , 2 , 3 , 2 , 1 ] ) . rollingMean ( 2 ) } | ${ pl . Series ( "" , [ null , 1.5 , 2.5 , 2.5 , 1.5 ] , pl . Float64 ) }
533
537
${ "rollingVar" } | ${ pl . Series ( [ 1 , 2 , 3 , 2 , 1 ] ) . rollingVar ( 2 ) [ 1 ] } | ${ 0.5 }
538
+ ${ "rollingStd" } | ${ pl . Series ( [ 1 , 2 , 3 , 2 , 1 ] ) . rollingStd ( 2 ) . round ( 2 ) [ 1 ] } | ${ 0.71 }
539
+ ${ "rollingSkew" } | ${ pl . Series ( [ 1 , 2 , 3 , 2 , 1 ] ) . rollingSkew ( 2 ) . round ( 2 ) [ 1 ] } | ${ 0 }
534
540
${ "rollingMedian" } | ${ pl . Series ( [ 1 , 2 , 3 , 3 , 2 , 10 , 8 ] ) . rollingMedian ( { windowSize : 2 } ) } | ${ pl . Series ( [ null , 1.5 , 2.5 , 3 , 2.5 , 6 , 9 ] ) }
535
541
${ "rollingQuantile" } | ${ pl . Series ( [ 1 , 2 , 3 , 3 , 2 , 10 , 8 ] ) . rollingQuantile ( { windowSize : 2 , quantile : 0.5 } ) } | ${ pl . Series ( [ null , 2 , 3 , 3 , 3 , 10 , 10 ] ) }
536
542
${ "sample:n" } | ${ pl . Series ( [ 1 , 2 , 3 , 4 , 5 ] ) . sample ( 2 ) . len ( ) } | ${ 2 }
@@ -554,6 +560,7 @@ describe("series", () => {
554
560
${ "unique" } | ${ pl . Series ( [ 1 , 2 , 3 , 3 ] ) . unique ( ) . sort ( ) } | ${ pl . Series ( [ 1 , 2 , 3 ] ) }
555
561
${ "cumCount" } | ${ pl . Series ( [ 1 , 2 , 3 , 3 ] ) . cumCount ( ) } | ${ pl . Series ( [ 1 , 2 , 3 , 4 ] ) }
556
562
${ "shiftAndFill" } | ${ pl . Series ( "foo" , [ 1 , 2 , 3 ] ) . shiftAndFill ( 1 , 99 ) } | ${ pl . Series ( "foo" , [ 99 , 1 , 2 ] ) }
563
+ ${ "shrinkToFit" } | ${ pl . Series ( "foo" , [ 1 , 2 , 3 ] ) . shrinkToFit ( ) } | ${ pl . Series ( "foo" , [ 1 , 2 , 3 ] ) }
557
564
${ "bitand" } | ${ pl . Series ( "bit" , [ 1 , 2 , 3 ] , pl . Int32 ) . bitand ( pl . Series ( "bit" , [ 0 , 1 , 1 ] , pl . Int32 ) ) } | ${ pl . Series ( "bit" , [ 0 , 0 , 1 ] ) }
558
565
${ "bitor" } | ${ pl . Series ( "bit" , [ 1 , 2 , 3 ] , pl . Int32 ) . bitor ( pl . Series ( "bit" , [ 0 , 1 , 1 ] , pl . Int32 ) ) } | ${ pl . Series ( "bit" , [ 1 , 3 , 3 ] ) }
559
566
${ "bitxor" } | ${ pl . Series ( "bit" , [ 1 , 2 , 3 ] , pl . Int32 ) . bitxor ( pl . Series ( "bit" , [ 0 , 1 , 1 ] , pl . Int32 ) ) } | ${ pl . Series ( "bit" , [ 1 , 3 , 2 ] ) }
@@ -710,6 +717,12 @@ describe("series", () => {
710
717
new Uint8Array ( [ 1 , 2 , 3 , 5 ] ) ,
711
718
) ;
712
719
} ) ;
720
+ test ( "values()" , ( ) => {
721
+ const s = pl . Series . from ( "foo" , [ 1 , 2 , 3 ] ) ;
722
+ const actual = s . values ( ) . next ( ) ;
723
+ const expected = { done : false , value : 1 } ;
724
+ expect ( actual ) . toEqual ( expected ) ;
725
+ } ) ;
713
726
test ( "toDummies" , ( ) => {
714
727
const s = pl . Series ( "a" , [ 1 , 2 , 3 ] ) ;
715
728
{
@@ -721,7 +734,7 @@ describe("series", () => {
721
734
expect ( actual ) . toFrameEqual ( expected ) ;
722
735
}
723
736
{
724
- const actual = s . toDummies ( ":" , true ) ;
737
+ const actual = s . toDummies ( ":" , true , false ) ;
725
738
const expected = pl . DataFrame (
726
739
{ "a:2.0" : [ 0 , 1 , 0 ] , "a:3.0" : [ 0 , 0 , 1 ] } ,
727
740
{ schema : { "a:2.0" : pl . UInt8 , "a:3.0" : pl . UInt8 } } ,
@@ -731,6 +744,50 @@ describe("series", () => {
731
744
} ) ;
732
745
} ) ;
733
746
describe ( "comparators & math" , ( ) => {
747
+ test ( "add/plus/series" , ( ) => {
748
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
749
+ const expected = pl . Series ( [ 2 , 4 , 6 ] ) ;
750
+ expect ( s . add ( s ) ) . toSeriesEqual ( expected ) ;
751
+ expect ( s . plus ( s ) ) . toSeriesEqual ( expected ) ;
752
+ } ) ;
753
+ test ( "minus/series" , ( ) => {
754
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
755
+ expect ( s . plus ( s ) . minus ( s ) ) . toSeriesEqual ( s ) ;
756
+ expect ( s . add ( s ) . sub ( s ) ) . toSeriesEqual ( s ) ;
757
+ } ) ;
758
+ test ( "eq/series" , ( ) => {
759
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
760
+ const s2 = pl . Series ( [ 1 , 3 , 3 ] ) ;
761
+ const expected = pl . Series ( [ true , false , true ] ) ;
762
+ expect ( s . eq ( s2 ) ) . toSeriesEqual ( expected ) ;
763
+ expect ( s . equals ( s2 ) ) . toSeriesEqual ( expected ) ;
764
+ } ) ;
765
+ test ( "gt/series" , ( ) => {
766
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
767
+ const s2 = pl . Series ( [ 2 , 2 , 4 ] ) ;
768
+ const expected = pl . Series ( [ true , false , true ] ) ;
769
+ expect ( s2 . gt ( s ) ) . toSeriesEqual ( expected ) ;
770
+ expect ( s2 . greaterThan ( s ) ) . toSeriesEqual ( expected ) ;
771
+ } ) ;
772
+ test ( "gteq/series" , ( ) => {
773
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
774
+ const s2 = pl . Series ( [ 2 , 2 , 4 ] ) ;
775
+ const expected = pl . Series ( [ true , true , true ] ) ;
776
+ expect ( s2 . gtEq ( s ) ) . toSeriesEqual ( expected ) ;
777
+ expect ( s2 . greaterThanEquals ( s ) ) . toSeriesEqual ( expected ) ;
778
+ } ) ;
779
+ test ( "rem/modulo/series" , ( ) => {
780
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
781
+ const s2 = pl . Series ( [ 2 , 3 , 4 ] ) ;
782
+ expect ( s . rem ( s2 ) ) . toSeriesEqual ( s ) ;
783
+ expect ( s . modulo ( s2 ) ) . toSeriesEqual ( s ) ;
784
+ } ) ;
785
+ test ( "div/series" , ( ) => {
786
+ const s = pl . Series ( [ 1 , 2 , 3 ] ) ;
787
+ const expected = pl . Series ( [ 2 , 2 , 2 ] ) ;
788
+ expect ( s . plus ( s ) . div ( s ) ) . toSeriesEqual ( expected ) ;
789
+ expect ( s . plus ( s ) . divideBy ( s ) ) . toSeriesEqual ( expected ) ;
790
+ } ) ;
734
791
test ( "add/plus" , ( ) => {
735
792
const s = pl . Series ( [ 1 , 2 ] ) ;
736
793
const expected = pl . Series ( [ 2 , 3 ] ) ;
@@ -802,6 +859,10 @@ describe("comparators & math", () => {
802
859
const expected = pl . Series ( [ true , false ] ) ;
803
860
expect ( s . ltEq ( 1 ) ) . toSeriesEqual ( expected ) ;
804
861
expect ( s . lessThanEquals ( 1 ) ) . toSeriesEqual ( expected ) ;
862
+ let fn = ( ) => s . ltEq ( "1" ) ;
863
+ expect ( fn ) . toThrow ( "Not a number nor a series" ) ;
864
+ fn = ( ) => s . lessThanEquals ( "1" ) ;
865
+ expect ( fn ) . toThrow ( "Not a number nor a series" ) ;
805
866
} ) ;
806
867
} ) ;
807
868
describe ( "StringFunctions" , ( ) => {
@@ -922,21 +983,13 @@ describe("series struct", () => {
922
983
} ) ;
923
984
describe ( "generics" , ( ) => {
924
985
const series = pl . Series ( [ 1 , 2 , 3 ] ) ;
925
-
926
986
test ( "dtype" , ( ) => {
927
987
expect ( series . dtype ) . toStrictEqual ( DataType . Float64 ) ;
928
988
} ) ;
929
989
test ( "to array" , ( ) => {
930
990
const arr = series . toArray ( ) ;
931
991
expect < number [ ] > ( arr ) . toStrictEqual ( [ 1 , 2 , 3 ] ) ;
932
-
933
992
const arr2 = [ ...series ] ;
934
993
expect < number [ ] > ( arr2 ) . toStrictEqual ( [ 1 , 2 , 3 ] ) ;
935
994
} ) ;
936
- test . skip ( "to object" , ( ) => {
937
- const obj = series . toObject ( ) ;
938
- expect < { name : string ; datatype : "Float64" ; values : number [ ] } > (
939
- obj ,
940
- ) . toMatchObject ( { name : "" , datatype : "Float64" , values : [ 1 , 2 , 3 ] } ) ;
941
- } ) ;
942
995
} ) ;
0 commit comments