|
1 | 1 | import { DataFrame } from "./frame"; |
2 | 2 | import { Utils } from "./utils"; |
3 | 3 | import { Series } from "./series"; |
| 4 | +import { concat } from "./concat"; |
4 | 5 | const utils = new Utils; |
5 | 6 |
|
6 | 7 | /** |
@@ -267,9 +268,15 @@ export class GroupBy { |
267 | 268 | function concatPathAndNode(path, node, col_dtype) { |
268 | 269 | if (Array.isArray(node)) { |
269 | 270 | if (Array.isArray(node[0])) { |
270 | | - const transposed_node = node[0].map((_, colIndex) => node.map((row) => row[colIndex])); |
271 | | - for (const n_array of transposed_node) |
272 | | - df_data.push(path.concat(n_array)); |
| 271 | + if (ops != "apply" ) { |
| 272 | + const transposed_node = node[0].map((_, colIndex) => node.map((row) => row[colIndex])); |
| 273 | + for (const n_array of transposed_node) |
| 274 | + df_data.push(path.concat(n_array)); |
| 275 | + } else { |
| 276 | + for (const n_array of node) |
| 277 | + df_data.push(path.concat(n_array)); |
| 278 | + } |
| 279 | + |
273 | 280 | } else |
274 | 281 | df_data.push(path.concat(node)); |
275 | 282 | } else { |
@@ -310,13 +317,20 @@ export class GroupBy { |
310 | 317 | function recursiveCount(sub_df_data, sub_count_group) { |
311 | 318 | for (const [ key, value ] of Object.entries(sub_df_data)) { |
312 | 319 | if (Array.isArray(value)) { |
313 | | - sub_count_group[key] = value.map(( callable_value ) => { |
314 | | - const callable_rslt = callable(callable_value); |
315 | | - if ((callable_rslt instanceof DataFrame) || (callable_rslt instanceof Series)) |
316 | | - return callable_rslt.values; |
317 | | - else |
318 | | - return callable_rslt; |
319 | | - }); |
| 320 | + let callable_value; |
| 321 | + if (value.length > 1) { |
| 322 | + callable_value = concat({ df_list: value, axis: 1 }); |
| 323 | + } else { |
| 324 | + callable_value = value[0]; |
| 325 | + } |
| 326 | + const callable_rslt = callable(callable_value); |
| 327 | + if (callable_rslt instanceof DataFrame) { |
| 328 | + column = callable_rslt.columns; |
| 329 | + sub_count_group[key] = callable_rslt.values; |
| 330 | + } else if (callable_rslt instanceof Series) { |
| 331 | + sub_count_group[key] = callable_rslt.values; |
| 332 | + } else |
| 333 | + sub_count_group = callable_rslt; |
320 | 334 | } else { |
321 | 335 | sub_count_group[key] = {}; |
322 | 336 | recursiveCount(value, sub_count_group[key]); |
|
0 commit comments