@@ -668,9 +668,9 @@ describe("DataFrame", function () {
668668 describe ( "describe" , function ( ) {
669669 it ( "Returns descriptive statistics of columns in a DataFrame created from an array" , function ( ) {
670670 let data = [ [ 0 , 2 , 4 , "a" ] ,
671- [ 360 , 180 , 360 , "b" ] ,
672- [ 2 , 4 , 6 , "c" ] ]
673-
671+ [ 360 , 180 , 360 , "b" ] ,
672+ [ 2 , 4 , 6 , "c" ] ]
673+
674674 let df = new DataFrame ( data )
675675 let res = [ [ 3 , 3 , 3 ] , [ 120.666664 , 62 , 123.333336 ] ,
676676 [ 207.271159 , 102.19589 , 204.961785 ] ,
@@ -919,6 +919,39 @@ describe("DataFrame", function () {
919919
920920 assert . throws ( function ( ) { df . query ( { "column" : "D" , "is" : ">=" , "to" : 5 } ) } , Error , "column D does not exist" ) ;
921921 } ) ;
922+ it ( "Confirms that query index are updated" , function ( ) {
923+
924+ let data = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] , [ 39 , 89 , 78 ] ]
925+ let cols = [ "A" , "B" , "C" ]
926+ let df = new DataFrame ( data , { columns : cols } )
927+ let df_query = df . query ( { "column" : "B" , "is" : ">=" , "to" : 5 } )
928+ assert . deepEqual ( df_query . index , [ 1 , 2 , 3 ] )
929+ } ) ;
930+ it ( "Confirms that columns data are updated inplace" , function ( ) {
931+
932+ let data = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] , [ 39 , 89 , 78 ] ]
933+ let cols = [ "A" , "B" , "C" ]
934+ let df = new DataFrame ( data , { columns : cols } )
935+ df . query ( { "column" : "B" , "is" : ">=" , "to" : 5 , inplace : true } )
936+ assert . deepEqual ( df . col_data , [ [ 4 , 20 , 39 ] , [ 5 , 30 , 89 ] , [ 6 , 40 , 78 ] ] )
937+ } ) ;
938+ it ( "Confirms that query happens inplace" , function ( ) {
939+
940+ let data = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] , [ 39 , 89 , 78 ] ]
941+ let cols = [ "A" , "B" , "C" ]
942+ let df = new DataFrame ( data , { columns : cols } )
943+ df . query ( { "column" : "B" , "is" : ">=" , "to" : 5 , inplace : true } )
944+ let query_data = [ [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] , [ 39 , 89 , 78 ] ]
945+ assert . deepEqual ( df . values , query_data )
946+ } ) ;
947+ it ( "Confirms that query happens inplace and index are updated" , function ( ) {
948+
949+ let data = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 30 , 40 ] , [ 39 , 89 , 78 ] ]
950+ let cols = [ "A" , "B" , "C" ]
951+ let df = new DataFrame ( data , { columns : cols } )
952+ df . query ( { "column" : "B" , "is" : ">=" , "to" : 5 , inplace : true } )
953+ assert . deepEqual ( df . index , [ 1 , 2 , 3 ] )
954+ } ) ;
922955
923956 } ) ;
924957
@@ -1346,9 +1379,9 @@ describe("DataFrame", function () {
13461379
13471380 it ( "Fills only a specified column" , function ( ) {
13481381 let data = [ [ 1 , 2 , 3 ] ,
1349- [ 4 , 5 , 6 ] ,
1350- [ 20 , NaN , 40 ] ,
1351- [ 39 , NaN , 78 ] ]
1382+ [ 4 , 5 , 6 ] ,
1383+ [ 20 , NaN , 40 ] ,
1384+ [ 39 , NaN , 78 ] ]
13521385 let cols = [ "A" , "B" , "C" ]
13531386 let df = new DataFrame ( data , { columns : cols } )
13541387 let new_vals = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 20 , 2 , 40 ] , [ 39 , 2 , 78 ] ]
@@ -1421,8 +1454,8 @@ describe("DataFrame", function () {
14211454
14221455 it ( "Returns string and float columns in a DataFrame" , function ( ) {
14231456 let data = [ [ 30 , 1 , 2 , "boy" ] ,
1424- [ 3.2 , 4 , 30 , "girl" ] ,
1425- [ 5.09 , 6 , 7 , "cat" ] ]
1457+ [ 3.2 , 4 , 30 , "girl" ] ,
1458+ [ 5.09 , 6 , 7 , "cat" ] ]
14261459 let column = [ "A" , "B" , "C" , "D" ]
14271460 let df = new DataFrame ( data , { columns : column } )
14281461 let df_sub = df . select_dtypes ( [ 'string' , 'float32' ] )
@@ -1431,8 +1464,8 @@ describe("DataFrame", function () {
14311464
14321465 it ( "Returns int and float columns in a DataFrame" , function ( ) {
14331466 let data = [ [ 30 , 1 , 2 , "boy" ] ,
1434- [ 3.2 , 4 , 30 , "girl" ] ,
1435- [ 5.09 , 6 , 7 , "cat" ] ]
1467+ [ 3.2 , 4 , 30 , "girl" ] ,
1468+ [ 5.09 , 6 , 7 , "cat" ] ]
14361469 let column = [ "A" , "B" , "C" , "D" ]
14371470 let df = new DataFrame ( data , { columns : column } )
14381471 let df_sub = df . select_dtypes ( [ 'int32' , 'float32' ] )
@@ -1935,10 +1968,12 @@ describe("DataFrame", function () {
19351968
19361969 describe ( "rename" , function ( ) {
19371970 it ( "Rename columns along axis 1" , function ( ) {
1938- let data = { "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1939- "B" : [ 34 , - 4 , 5 , 6 ] ,
1940- "C" : [ 20 , 20 , 30 , 30 ] ,
1941- "D" : [ "a" , "b" , "c" , "c" ] }
1971+ let data = {
1972+ "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1973+ "B" : [ 34 , - 4 , 5 , 6 ] ,
1974+ "C" : [ 20 , 20 , 30 , 30 ] ,
1975+ "D" : [ "a" , "b" , "c" , "c" ]
1976+ }
19421977
19431978 let ndframe = new DataFrame ( data )
19441979 let df = ndframe . rename ( { mapper : { "A" : "a1" , "B" : "b1" } } )
@@ -1947,10 +1982,12 @@ describe("DataFrame", function () {
19471982
19481983 } )
19491984 it ( "confirms original column name is not modified along axis 1" , function ( ) {
1950- let data = { "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1951- "B" : [ 34 , - 4 , 5 , 6 ] ,
1952- "C" : [ 20 , 20 , 30 , 30 ] ,
1953- "D" : [ "a" , "b" , "c" , "c" ] }
1985+ let data = {
1986+ "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1987+ "B" : [ 34 , - 4 , 5 , 6 ] ,
1988+ "C" : [ 20 , 20 , 30 , 30 ] ,
1989+ "D" : [ "a" , "b" , "c" , "c" ]
1990+ }
19541991
19551992 let ndframe = new DataFrame ( data )
19561993 let df = ndframe . rename ( { mapper : { "A" : "a1" , "B" : "b1" } } )
@@ -1959,10 +1996,12 @@ describe("DataFrame", function () {
19591996
19601997 } )
19611998 it ( "Rename columns along axis 1 inplace" , function ( ) {
1962- let data = { "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1963- "B" : [ 34 , - 4 , 5 , 6 ] ,
1964- "C" : [ 20 , 20 , 30 , 30 ] ,
1965- "D" : [ "a" , "b" , "c" , "c" ] }
1999+ let data = {
2000+ "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
2001+ "B" : [ 34 , - 4 , 5 , 6 ] ,
2002+ "C" : [ 20 , 20 , 30 , 30 ] ,
2003+ "D" : [ "a" , "b" , "c" , "c" ]
2004+ }
19662005
19672006 let df = new DataFrame ( data )
19682007 df . rename ( { mapper : { "A" : "a1" , "B" : "b1" } , inplace : true } )
@@ -1971,10 +2010,12 @@ describe("DataFrame", function () {
19712010
19722011 } )
19732012 it ( "Rename string index along axis 0" , function ( ) {
1974- let data = { "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1975- "B" : [ 34 , - 4 , 5 , 6 ] ,
1976- "C" : [ 20 , 20 , 30 , 30 ] ,
1977- "D" : [ "a" , "b" , "c" , "c" ] }
2013+ let data = {
2014+ "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
2015+ "B" : [ 34 , - 4 , 5 , 6 ] ,
2016+ "C" : [ 20 , 20 , 30 , 30 ] ,
2017+ "D" : [ "a" , "b" , "c" , "c" ]
2018+ }
19782019
19792020 let ndframe = new DataFrame ( data , { index : [ "a" , "b" , "c" , "d" ] } )
19802021 let df = ndframe . rename ( { mapper : { "a" : 0 , "b" : 1 } , axis : 0 } )
@@ -1983,10 +2024,12 @@ describe("DataFrame", function () {
19832024
19842025 } )
19852026 it ( "Rename string index along axis 0 inplace" , function ( ) {
1986- let data = { "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
1987- "B" : [ 34 , - 4 , 5 , 6 ] ,
1988- "C" : [ 20 , 20 , 30 , 30 ] ,
1989- "D" : [ "a" , "b" , "c" , "c" ] }
2027+ let data = {
2028+ "A" : [ - 20 , 30 , 47.3 , - 20 ] ,
2029+ "B" : [ 34 , - 4 , 5 , 6 ] ,
2030+ "C" : [ 20 , 20 , 30 , 30 ] ,
2031+ "D" : [ "a" , "b" , "c" , "c" ]
2032+ }
19902033
19912034 let df = new DataFrame ( data , { index : [ "a" , "b" , "c" , "d" ] } )
19922035 df . rename ( { mapper : { "a" : 0 , "b" : 1 } , axis : 0 , inplace : true } )
0 commit comments