@@ -14,12 +14,13 @@ var _series = require("./series");
1414const utils = new _utils . Utils ( ) ;
1515
1616class GroupBy {
17- constructor ( col_dict , key_col , data , column_name ) {
17+ constructor ( col_dict , key_col , data , column_name , col_dtype ) {
1818 this . key_col = key_col ;
1919 this . col_dict = col_dict ;
2020 this . data = data ;
2121 this . column_name = column_name ;
2222 this . data_tensors = { } ;
23+ this . col_dtype = col_dtype ;
2324 }
2425
2526 group ( ) {
@@ -118,7 +119,7 @@ class GroupBy {
118119 }
119120 }
120121
121- const gp = new GroupBy ( null , this . key_col , null , col_names ) ;
122+ const gp = new GroupBy ( null , this . key_col , null , col_names , this . col_dtype ) ;
122123 gp . group_col = group_col ;
123124 gp . group_col_name = col_names ;
124125 return gp ;
@@ -315,8 +316,8 @@ class GroupBy {
315316 for ( let j = 0 ; j < col_data . length ; j ++ ) {
316317 if ( typeof key_data [ j ] === "undefined" ) {
317318 key_data [ j ] = [ ] ;
318- key_data [ j ] [ 0 ] = isNaN ( parseInt ( key_1 ) ) ? key_1 : parseInt ( key_1 ) ;
319- key_data [ j ] [ 1 ] = isNaN ( parseInt ( key_2 ) ) ? key_2 : parseInt ( key_2 ) ;
319+ key_data [ j ] [ 0 ] = this . col_dtype [ 0 ] === "string" ? key_1 : parseInt ( key_1 ) ;
320+ key_data [ j ] [ 1 ] = this . col_dtype [ 1 ] === "string" ? key_2 : parseInt ( key_2 ) ;
320321 key_data [ j ] . push ( col_data [ j ] ) ;
321322 } else {
322323 key_data [ j ] . push ( col_data [ j ] ) ;
@@ -326,8 +327,8 @@ class GroupBy {
326327
327328 df_data . push ( ...key_data ) ;
328329 } else {
329- key_data [ 0 ] = isNaN ( parseInt ( key_1 ) ) ? key_1 : parseInt ( key_1 ) ;
330- key_data [ 1 ] = isNaN ( parseInt ( key_2 ) ) ? key_2 : parseInt ( key_2 ) ;
330+ key_data [ 0 ] = this . col_dtype [ 0 ] === "string" ? key_1 : parseInt ( key_1 ) ;
331+ key_data [ 1 ] = this . col_dtype [ 1 ] === "string" ? key_2 : parseInt ( key_2 ) ;
331332 key_data . push ( ...k_data ) ;
332333 df_data . push ( key_data ) ;
333334 }
@@ -360,17 +361,17 @@ class GroupBy {
360361 for ( let j = 0 ; j < col_data . length ; j ++ ) {
361362 if ( typeof key_data [ j ] === "undefined" ) {
362363 key_data [ j ] = [ ] ;
363- key_data [ j ] [ 0 ] = isNaN ( parseInt ( key_1 ) ) ? key_1 : parseInt ( key_1 ) ;
364+ key_data [ j ] [ 0 ] = this . col_dtype [ 0 ] === "string" ? key_1 : parseInt ( key_1 ) ;
364365 key_data [ j ] . push ( col_data [ j ] ) ;
365366 } else {
366367 key_data [ j ] . push ( col_data [ j ] ) ;
367368 }
368369 }
369-
370- df_data . push ( ...key_data ) ;
371370 }
371+
372+ df_data . push ( ...key_data ) ;
372373 } else {
373- key_data [ 0 ] = isNaN ( parseInt ( key_1 ) ) ? key_1 : parseInt ( key_1 ) ;
374+ key_data [ 0 ] = this . col_dtype [ 0 ] === "string" ? key_1 : parseInt ( key_1 ) ;
374375 key_data . push ( ...key_val ) ;
375376 df_data . push ( key_data ) ;
376377 }
@@ -408,10 +409,11 @@ class GroupBy {
408409 let count_group = { } ;
409410
410411 if ( this . key_col . length == 2 ) {
411- for ( let key in this . data_tensors ) {
412+ for ( let key in df_data ) {
412413 count_group [ key ] = { } ;
413414
414- for ( let key2 in this . data_tensors [ key ] ) {
415+ for ( let key2 in df_data [ key ] ) {
416+ let index ;
415417 count_group [ key ] [ key2 ] = [ ] ;
416418
417419 for ( let i = 0 ; i < df_data [ key ] [ key2 ] . length ; i ++ ) {
0 commit comments