Skip to content

Commit 432f984

Browse files
committed
[groupby.js][s]: obtain groupby column dtype to fix #183
1 parent a54f618 commit 432f984

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

danfojs-node/src/core/groupby.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ const utils = new Utils;
1212
* @param {column_name} Array of all column name in the dataframe.
1313
*/
1414
export class GroupBy {
15-
constructor(col_dict, key_col, data, column_name) {
15+
constructor(col_dict, key_col, data, column_name, col_dtype) {
1616

1717
this.key_col = key_col;
1818
this.col_dict = col_dict;
1919
this.data = data;
2020
this.column_name = column_name;
2121
this.data_tensors = {}; //store the tensor version of the groupby data
22+
this.col_dtype = col_dtype;
2223

2324
}
2425

@@ -150,7 +151,8 @@ export class GroupBy {
150151
null,
151152
this.key_col,
152153
null,
153-
col_names
154+
col_names,
155+
this.col_dtype
154156
);
155157

156158
gp.group_col = group_col;
@@ -367,8 +369,8 @@ export class GroupBy {
367369

368370
if (typeof key_data[j] === "undefined" ){
369371
key_data[j] = [];
370-
key_data[j][0] = isNaN(parseInt(key_1)) ? key_1 : parseInt(key_1);
371-
key_data[j][1] = isNaN(parseInt(key_2)) ? key_2 : parseInt(key_2);
372+
key_data[j][0] = this.col_dtype[0] === "string" ? key_1 : parseInt(key_1);
373+
key_data[j][1] = this.col_dtype[1] === "string" ? key_2 : parseInt(key_2);
372374
key_data[j].push(col_data[j]);
373375
} else {
374376
key_data[j].push(col_data[j]);
@@ -378,8 +380,8 @@ export class GroupBy {
378380
df_data.push(...key_data);
379381

380382
} else {
381-
key_data[0] = isNaN(parseInt(key_1)) ? key_1 : parseInt(key_1);
382-
key_data[1] = isNaN(parseInt(key_2)) ? key_2 : parseInt(key_2);
383+
key_data[0] = this.col_dtype[0] === "string" ? key_1 : parseInt(key_1);
384+
key_data[1] = this.col_dtype[1] === "string" ? key_2 : parseInt(key_2);
383385
key_data.push(...k_data);
384386
df_data.push(key_data);
385387
}
@@ -413,19 +415,17 @@ export class GroupBy {
413415

414416
if (typeof key_data[j] === "undefined" ){
415417
key_data[j] = [];
416-
key_data[j][0] = isNaN(parseInt(key_1)) ? key_1 : parseInt(key_1);
418+
key_data[j][0] = this.col_dtype[0] === "string" ? key_1 : parseInt(key_1);
417419
key_data[j].push(col_data[j]);
418420
} else {
419421
key_data[j].push(col_data[j]);
420-
// console.log("key_data", key_data);
421422
}
422423
}
423-
// df_data.push(...key_data);
424424
}
425425
df_data.push(...key_data);
426426

427427
} else {
428-
key_data[0] = isNaN(parseInt(key_1)) ? key_1 : parseInt(key_1);
428+
key_data[0] = this.col_dtype[0] === "string" ? key_1 : parseInt(key_1);
429429
key_data.push(...key_val);
430430
df_data.push(key_data);
431431
}

0 commit comments

Comments
 (0)