@@ -1277,7 +1277,7 @@ def _wrap_applied_output(
1277
1277
# numba
1278
1278
1279
1279
@final
1280
- def _numba_prep (self , data ):
1280
+ def _numba_prep (self , data : DataFrame ):
1281
1281
ids , _ , ngroups = self .grouper .group_info
1282
1282
sorted_index = get_group_index_sorter (ids , ngroups )
1283
1283
sorted_ids = algorithms .take_nd (ids , sorted_index , allow_fill = False )
@@ -1337,7 +1337,9 @@ def _numba_agg_general(
1337
1337
return data ._constructor (result , index = index , ** result_kwargs )
1338
1338
1339
1339
@final
1340
- def _transform_with_numba (self , data , func , * args , engine_kwargs = None , ** kwargs ):
1340
+ def _transform_with_numba (
1341
+ self , data : DataFrame , func , * args , engine_kwargs = None , ** kwargs
1342
+ ):
1341
1343
"""
1342
1344
Perform groupby transform routine with the numba engine.
1343
1345
@@ -1363,7 +1365,9 @@ def _transform_with_numba(self, data, func, *args, engine_kwargs=None, **kwargs)
1363
1365
return result .take (np .argsort (sorted_index ), axis = 0 )
1364
1366
1365
1367
@final
1366
- def _aggregate_with_numba (self , data , func , * args , engine_kwargs = None , ** kwargs ):
1368
+ def _aggregate_with_numba (
1369
+ self , data : DataFrame , func , * args , engine_kwargs = None , ** kwargs
1370
+ ):
1367
1371
"""
1368
1372
Perform groupby aggregation routine with the numba engine.
1369
1373
@@ -1529,15 +1533,13 @@ def _agg_general(
1529
1533
npfunc : Callable ,
1530
1534
):
1531
1535
1532
- with self ._group_selection_context ():
1533
- # try a cython aggregation if we can
1534
- result = self ._cython_agg_general (
1535
- how = alias ,
1536
- alt = npfunc ,
1537
- numeric_only = numeric_only ,
1538
- min_count = min_count ,
1539
- )
1540
- return result .__finalize__ (self .obj , method = "groupby" )
1536
+ result = self ._cython_agg_general (
1537
+ how = alias ,
1538
+ alt = npfunc ,
1539
+ numeric_only = numeric_only ,
1540
+ min_count = min_count ,
1541
+ )
1542
+ return result .__finalize__ (self .obj , method = "groupby" )
1541
1543
1542
1544
def _agg_py_fallback (
1543
1545
self , values : ArrayLike , ndim : int , alt : Callable
@@ -1647,9 +1649,7 @@ def _cython_transform(
1647
1649
def _transform (self , func , * args , engine = None , engine_kwargs = None , ** kwargs ):
1648
1650
1649
1651
if maybe_use_numba (engine ):
1650
- # TODO: tests with self._selected_obj.ndim == 1 on DataFrameGroupBy
1651
- with self ._group_selection_context ():
1652
- data = self ._selected_obj
1652
+ data = self ._obj_with_exclusions
1653
1653
df = data if data .ndim == 2 else data .to_frame ()
1654
1654
result = self ._transform_with_numba (
1655
1655
df , func , * args , engine_kwargs = engine_kwargs , ** kwargs
0 commit comments