@@ -2999,4 +2999,60 @@ describe("DataFrame", function () {
29992999 } ) ;
30003000
30013001 } ) ;
3002+
3003+ describe ( "DateTime datetime is supported" , function ( ) {
3004+ it ( "DateTime datetime is supported" , function ( ) {
3005+ let data = [ [ "Alice" , 2 , new Date ( 2029 , 1 , 1 ) ] ,
3006+ [ "Bob" , 5 , new Date ( 2019 , 1 , 2 ) ] ,
3007+ [ "Charlie" , 30 , new Date ( 2019 , 1 , 3 ) ] ,
3008+ [ "Dennis" , 89 , new Date ( 2019 , 1 , 4 ) ] ] ;
3009+
3010+ let columns = [ "Name" , "Count" , "Date" ] ;
3011+
3012+ let df = new dfd . DataFrame ( data , { columns : columns } ) ;
3013+ assert . deepEqual ( df . dtypes , [ "string" , "int32" , "datetime" ] ) ;
3014+
3015+ const dateValues = [ new Date ( 2029 , 1 , 1 ) , new Date ( 2019 , 1 , 2 ) , new Date ( 2019 , 1 , 3 ) , new Date ( 2019 , 1 , 4 ) ] ;
3016+ assert . deepEqual ( df [ "Date" ] . values , dateValues ) ;
3017+ } ) ;
3018+
3019+ it ( "datetime column properties can be accessed" , function ( ) {
3020+ let data = [ [ "Alice" , 2 , new Date ( "2029-01-01 01:00:00" ) ] ,
3021+ [ "Bob" , 5 , new Date ( "2019-01-02" ) ] ,
3022+ [ "Charlie" , 30 , new Date ( "2020-01-03 01:00:20" ) ] ,
3023+ [ "Dennis" , 89 , new Date ( "2022-02-04 02:16:00" ) ] ] ;
3024+
3025+ let columns = [ "Name" , "Count" , "Date" ] ;
3026+
3027+ let df = new dfd . DataFrame ( data , { columns : columns } ) ;
3028+
3029+ assert . deepEqual ( df [ "Date" ] . dt . year ( ) . values , [ 2029 , 2019 , 2020 , 2022 ] ) ;
3030+ assert . deepEqual ( df [ "Date" ] . dt . month ( ) . values , [ 0 , 0 , 0 , 1 ] ) ;
3031+ assert . deepEqual ( df [ "Date" ] . dt . dayOfMonth ( ) . values , [ 1 , 2 , 3 , 4 ] ) ;
3032+ assert . deepEqual ( df [ "Date" ] . dt . hours ( ) . values , [ 1 , 0 , 1 , 2 ] ) ;
3033+ assert . deepEqual ( df [ "Date" ] . dt . minutes ( ) . values , [ 0 , 0 , 0 , 16 ] ) ;
3034+ assert . deepEqual ( df [ "Date" ] . dt . seconds ( ) . values , [ 0 , 0 , 20 , 0 ] ) ;
3035+
3036+ } ) ;
3037+
3038+ it ( "datetime column created from dtype passed" , function ( ) {
3039+ let data = [ [ "Alice" , 2 , "2029-01-01 01:00:00" ] ,
3040+ [ "Bob" , 5 , "2019-01-02" ] ,
3041+ [ "Charlie" , 30 , "2020-01-03 01:00:20" ] ,
3042+ [ "Dennis" , 89 , "2022-02-04 02:16:00" ] ] ;
3043+
3044+ let columns = [ "Name" , "Count" , "Date" ] ;
3045+ let dtypes = [ "string" , "int32" , "datetime" ] ;
3046+
3047+ let df = new dfd . DataFrame ( data , { columns, dtypes } ) ;
3048+
3049+ assert . deepEqual ( df [ "Date" ] . dt . year ( ) . values , [ 2029 , 2019 , 2020 , 2022 ] ) ;
3050+ assert . deepEqual ( df [ "Date" ] . dt . month ( ) . values , [ 0 , 0 , 0 , 1 ] ) ;
3051+ assert . deepEqual ( df [ "Date" ] . dt . dayOfMonth ( ) . values , [ 1 , 2 , 3 , 4 ] ) ;
3052+ assert . deepEqual ( df [ "Date" ] . dt . hours ( ) . values , [ 1 , 0 , 1 , 2 ] ) ;
3053+ assert . deepEqual ( df [ "Date" ] . dt . minutes ( ) . values , [ 0 , 0 , 0 , 16 ] ) ;
3054+ assert . deepEqual ( df [ "Date" ] . dt . seconds ( ) . values , [ 0 , 0 , 20 , 0 ] ) ;
3055+
3056+ } ) ;
3057+ } ) ;
30023058} ) ;
0 commit comments