@@ -2155,6 +2155,68 @@ describe("DataFrame", function () {
21552155 assert . deepEqual ( df . values , expected ) ;
21562156 } ) ;
21572157
2158+ it ( "Replace oldValue supports falsy numbers (0)" , function ( ) {
2159+ const data1 = [ [ 0 , 19 , 84 , 0 ] , [ 65 , 0 , 0 , 37 ] ] ;
2160+ const df = new DataFrame ( data1 ) ;
2161+ const expected = [ [ 1 , 19 , 84 , 1 ] , [ 65 , 1 , 1 , 37 ] ] ;
2162+ const df_rep = df . replace ( 0 , 1 ) as DataFrame ;
2163+ assert . deepEqual ( df_rep . values , expected ) ;
2164+ } ) ;
2165+
2166+ it ( "Replace oldValue does not support NaN" , function ( ) {
2167+ const data1 = [ [ NaN , 19 , 84 , NaN ] , [ 65 , NaN , NaN , 37 ] ] ;
2168+ const df = new DataFrame ( data1 ) ;
2169+ assert . throws ( ( ) => df . replace ( NaN , 1 ) , Error , "Params Error: Param 'oldValue' does not support NaN. Use DataFrame.fillNa() instead." ) ;
2170+ } ) ;
2171+
2172+ it ( "Replace oldValue supports falsy strings" , function ( ) {
2173+ const data1 = [ [ '' , 'hello' , 'world' , '' ] , [ 'foo' , '' , '' , 'bar' ] ] ;
2174+ const df = new DataFrame ( data1 ) ;
2175+ const expected = [ [ 'danfo' , 'hello' , 'world' , 'danfo' ] , [ 'foo' , 'danfo' , 'danfo' , 'bar' ] ] ;
2176+ const df_rep = df . replace ( '' , 'danfo' ) as DataFrame ;
2177+ assert . deepEqual ( df_rep . values , expected ) ;
2178+ } ) ;
2179+
2180+ it ( "Replace oldValue supports falsy booleans" , function ( ) {
2181+ const data1 = [ [ false , 'hello' , 'world' , false ] , [ 'foo' , false , false , 'bar' ] ] ;
2182+ const df = new DataFrame ( data1 ) ;
2183+ const expected = [ [ true , 'hello' , 'world' , true ] , [ 'foo' , true , true , 'bar' ] ] ;
2184+ const df_rep = df . replace ( false , true ) as DataFrame ;
2185+ assert . deepEqual ( df_rep . values , expected ) ;
2186+ } ) ;
2187+
2188+ it ( "Replace newValue supports falsy numbers (0)" , function ( ) {
2189+ const data1 = [ [ 1 , 19 , 84 , 1 ] , [ 65 , 1 , 1 , 37 ] ] ;
2190+ const df = new DataFrame ( data1 ) ;
2191+ const expected = [ [ 0 , 19 , 84 , 0 ] , [ 65 , 0 , 0 , 37 ] ] ;
2192+ const df_rep = df . replace ( 1 , 0 ) as DataFrame ;
2193+ assert . deepEqual ( df_rep . values , expected ) ;
2194+ } ) ;
2195+
2196+ it ( "Replace newValue supports falsy numbers (NaN)" , function ( ) {
2197+ const data1 = [ [ 1 , 19 , 84 , 1 ] , [ 65 , 1 , 1 , 37 ] ] ;
2198+ const df = new DataFrame ( data1 ) ;
2199+ const expected = [ [ NaN , 19 , 84 , NaN ] , [ 65 , NaN , NaN , 37 ] ] ;
2200+ const df_rep = df . replace ( 1 , NaN ) as DataFrame ;
2201+ assert . deepEqual ( df_rep . values , expected ) ;
2202+ } ) ;
2203+
2204+ it ( "Replace newValue supports falsy strings" , function ( ) {
2205+ const data1 = [ [ 'danfo' , 'hello' , 'world' , 'danfo' ] , [ 'foo' , 'danfo' , 'danfo' , 'bar' ] ] ;
2206+ const df = new DataFrame ( data1 ) ;
2207+ const expected = [ [ '' , 'hello' , 'world' , '' ] , [ 'foo' , '' , '' , 'bar' ] ] ;
2208+ const df_rep = df . replace ( 'danfo' , '' ) as DataFrame ;
2209+ assert . deepEqual ( df_rep . values , expected ) ;
2210+ } ) ;
2211+
2212+ it ( "Replace newValue supports falsy booleans" , function ( ) {
2213+ const data1 = [ [ true , 'hello' , 'world' , true ] , [ 'foo' , true , true , 'bar' ] ] ;
2214+ const df = new DataFrame ( data1 ) ;
2215+ const expected = [ [ false , 'hello' , 'world' , false ] , [ 'foo' , false , false , 'bar' ] ] ;
2216+ const df_rep = df . replace ( true , false ) as DataFrame ;
2217+ assert . deepEqual ( df_rep . values , expected ) ;
2218+ } ) ;
2219+
21582220 } ) ;
21592221
21602222 describe ( "sum" , function ( ) {
0 commit comments