1212* limitations under the License.
1313*/
1414
15- import * as tf from "@tensorflow/tfjs" ;
15+ import { tensor } from "@tensorflow/tfjs" ;
1616import Ndframe from "./generic" ;
1717import { Series } from "./series" ;
1818import { Utils } from "./utils" ;
@@ -183,7 +183,7 @@ export class DataFrame extends Ndframe {
183183 index : new_index
184184 } ) ;
185185 } else {
186- this . row_data_tensor = tf . tensor ( new_data ) ;
186+ this . row_data_tensor = tensor ( new_data ) ;
187187 this . data = new_data ;
188188 this . __set_index ( new_index ) ;
189189 }
@@ -916,7 +916,7 @@ export class DataFrame extends Ndframe {
916916 }
917917
918918 values . map ( ( arr ) => {
919- let temp_sum = tf . tensor ( arr ) . sum ( ) . arraySync ( ) ;
919+ let temp_sum = tensor ( arr ) . sum ( ) . arraySync ( ) ;
920920 val_sums . push ( Number ( temp_sum . toFixed ( 5 ) ) ) ;
921921 } ) ;
922922
@@ -940,7 +940,7 @@ export class DataFrame extends Ndframe {
940940 abs ( ) {
941941 let data = this . values ;
942942
943- let tensor_data = tf . tensor ( data ) ;
943+ let tensor_data = tensor ( data ) ;
944944 let abs_data = tensor_data . abs ( ) . arraySync ( ) ;
945945 let df = new DataFrame ( utils . __round ( abs_data , 2 , false ) , {
946946 columns : this . column_names ,
@@ -1406,7 +1406,7 @@ export class DataFrame extends Ndframe {
14061406 }
14071407
14081408 for ( let i = 0 ; i < df_data . length ; i ++ ) {
1409- let value = tf . tensor ( df_data [ i ] ) ;
1409+ let value = tensor ( df_data [ i ] ) ;
14101410 let callable_data ;
14111411 try {
14121412 callable_data = callable ( value ) . arraySync ( ) ;
@@ -1659,18 +1659,18 @@ export class DataFrame extends Ndframe {
16591659 `Shape Error: Operands could not be broadcast together with shapes ${ this . shape } and ${ val . values . length } .`
16601660 ) ;
16611661 }
1662- other = tf . tensor ( val . values ) ;
1662+ other = tensor ( val . values ) ;
16631663 } else {
16641664 if ( val . values . length != this . shape [ 1 ] ) {
16651665 throw Error (
16661666 `Shape Error: Operands could not be broadcast together with shapes ${ this . shape } and ${ val . values . length } .`
16671667 ) ;
16681668 }
1669- other = tf . tensor ( val . values ) ;
1669+ other = tensor ( val . values ) ;
16701670 }
16711671 } else if ( Array . isArray ( val ) ) {
16721672 //Array of Array
1673- other = tf . tensor ( val ) ;
1673+ other = tensor ( val ) ;
16741674 } else {
16751675 //DataFrame
16761676 other = val . row_data_tensor ;
@@ -1679,22 +1679,22 @@ export class DataFrame extends Ndframe {
16791679
16801680 switch ( logical_type ) {
16811681 case "lt" :
1682- int_vals = tf . tensor ( this . values ) . less ( other ) . arraySync ( ) ;
1682+ int_vals = tensor ( this . values ) . less ( other ) . arraySync ( ) ;
16831683 break ;
16841684 case "gt" :
1685- int_vals = tf . tensor ( this . values ) . greater ( other ) . arraySync ( ) ;
1685+ int_vals = tensor ( this . values ) . greater ( other ) . arraySync ( ) ;
16861686 break ;
16871687 case "le" :
1688- int_vals = tf . tensor ( this . values ) . lessEqual ( other ) . arraySync ( ) ;
1688+ int_vals = tensor ( this . values ) . lessEqual ( other ) . arraySync ( ) ;
16891689 break ;
16901690 case "ge" :
1691- int_vals = tf . tensor ( this . values ) . greaterEqual ( other ) . arraySync ( ) ;
1691+ int_vals = tensor ( this . values ) . greaterEqual ( other ) . arraySync ( ) ;
16921692 break ;
16931693 case "ne" :
1694- int_vals = tf . tensor ( this . values ) . notEqual ( other ) . arraySync ( ) ;
1694+ int_vals = tensor ( this . values ) . notEqual ( other ) . arraySync ( ) ;
16951695 break ;
16961696 case "eq" :
1697- int_vals = tf . tensor ( this . values ) . equal ( other ) . arraySync ( ) ;
1697+ int_vals = tensor ( this . values ) . equal ( other ) . arraySync ( ) ;
16981698 break ;
16991699 }
17001700 let bool_vals = utils . __map_int_to_bool ( int_vals , 2 ) ;
@@ -1754,7 +1754,7 @@ export class DataFrame extends Ndframe {
17541754
17551755 this_tensor = tensors [ 0 ] . row_data_tensor ; //tensorflow uses 1 for rows axis and 0 for column axis
17561756 if ( tensors [ 1 ] . series ) {
1757- other_tensor = tf . tensor ( tensors [ 1 ] . values , [
1757+ other_tensor = tensor ( tensors [ 1 ] . values , [
17581758 1 ,
17591759 tensors [ 1 ] . values . length
17601760 ] ) ;
@@ -1771,7 +1771,7 @@ export class DataFrame extends Ndframe {
17711771
17721772 this_tensor = tensors [ 0 ] . row_data_tensor ;
17731773 if ( tensors [ 1 ] . series ) {
1774- other_tensor = tf . tensor ( tensors [ 1 ] . values , [
1774+ other_tensor = tensor ( tensors [ 1 ] . values , [
17751775 tensors [ 1 ] . values . length ,
17761776 1
17771777 ] ) ;
@@ -2153,7 +2153,7 @@ export class DataFrame extends Ndframe {
21532153 let val = sorted_val [ row_i ] ;
21542154 let index = null ;
21552155
2156- if ( duplicate_obj . hasOwnProperty ( val ) ) {
2156+ if ( val in duplicate_obj ) {
21572157 index = duplicate_obj [ val ] [ "index" ] [ 0 ] ;
21582158 duplicate_obj [ val ] [ "index" ] . splice ( 0 , 1 ) ;
21592159 } else {
0 commit comments