Skip to content

Commit 34008d6

Browse files
committed
[groupby.js][s]: obtain groupby column dtype to fix #183
1 parent 8038ee6 commit 34008d6

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

danfojs-node/dist/core/groupby.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ var _series = require("./series");
1414
const utils = new _utils.Utils();
1515

1616
class 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,7 +361,7 @@ 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]);
@@ -370,7 +371,7 @@ class GroupBy {
370371

371372
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
}

0 commit comments

Comments
 (0)