Perform groupby transform routine with the numba engine. This routine mimics the data splitting routine of the DataSplitter class to generate the indices of each group in the sorted data and then passes the data and indices into a Numba jitted function.
(self, func, *args, engine_kwargs=None, **kwargs)
| 1403 | |
| 1404 | @final |
| 1405 | def _transform_with_numba(self, func, *args, engine_kwargs=None, **kwargs): |
| 1406 | """ |
| 1407 | Perform groupby transform routine with the numba engine. |
| 1408 | |
| 1409 | This routine mimics the data splitting routine of the DataSplitter class |
| 1410 | to generate the indices of each group in the sorted data and then passes the |
| 1411 | data and indices into a Numba jitted function. |
| 1412 | """ |
| 1413 | data = self._obj_with_exclusions |
| 1414 | index_sorting = self._grouper.result_ilocs |
| 1415 | df = data if data.ndim == 2 else data.to_frame() |
| 1416 | |
| 1417 | starts, ends, sorted_index, sorted_data = self._numba_prep(df) |
| 1418 | numba_.validate_udf(func) |
| 1419 | args, kwargs = prepare_function_arguments( |
| 1420 | func, args, kwargs, num_required_args=2 |
| 1421 | ) |
| 1422 | numba_transform_func = numba_.generate_numba_transform_func( |
| 1423 | func, **get_jit_arguments(engine_kwargs) |
| 1424 | ) |
| 1425 | result = numba_transform_func( |
| 1426 | sorted_data, |
| 1427 | sorted_index, |
| 1428 | starts, |
| 1429 | ends, |
| 1430 | len(df.columns), |
| 1431 | *args, |
| 1432 | ) |
| 1433 | # result values needs to be resorted to their original positions since we |
| 1434 | # evaluated the data sorted by group |
| 1435 | result = result.take(np.argsort(index_sorting), axis=0) |
| 1436 | index = data.index |
| 1437 | if data.ndim == 1: |
| 1438 | result_kwargs = {"name": data.name} |
| 1439 | result = result.ravel() |
| 1440 | else: |
| 1441 | result_kwargs = {"columns": data.columns} |
| 1442 | return data._constructor(result, index=index, **result_kwargs) |
| 1443 | |
| 1444 | @final |
| 1445 | def _aggregate_with_numba(self, func, *args, engine_kwargs=None, **kwargs): |
no test coverage detected