@@ -283,11 +283,11 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
283
283
return self .obj ._constructor (
284
284
[],
285
285
name = self .obj .name ,
286
- index = self .grouper .result_index ,
286
+ index = self ._grouper .result_index ,
287
287
dtype = obj .dtype ,
288
288
)
289
289
290
- if self .grouper .nkeys > 1 :
290
+ if self ._grouper .nkeys > 1 :
291
291
return self ._python_agg_general (func , * args , ** kwargs )
292
292
293
293
try :
@@ -309,7 +309,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
309
309
)
310
310
311
311
# result is a dict whose keys are the elements of result_index
312
- result = Series (result , index = self .grouper .result_index )
312
+ result = Series (result , index = self ._grouper .result_index )
313
313
result = self ._wrap_aggregated_output (result )
314
314
return result
315
315
@@ -324,7 +324,7 @@ def _python_agg_general(self, func, *args, **kwargs):
324
324
f = lambda x : func (x , * args , ** kwargs )
325
325
326
326
obj = self ._obj_with_exclusions
327
- result = self .grouper .agg_series (obj , f )
327
+ result = self ._grouper .agg_series (obj , f )
328
328
res = obj ._constructor (result , name = obj .name )
329
329
return self ._wrap_aggregated_output (res )
330
330
@@ -404,7 +404,7 @@ def _wrap_applied_output(
404
404
# GH#47787 see test_group_on_empty_multiindex
405
405
res_index = data .index
406
406
else :
407
- res_index = self .grouper .result_index
407
+ res_index = self ._grouper .result_index
408
408
409
409
return self .obj ._constructor (
410
410
[],
@@ -416,7 +416,7 @@ def _wrap_applied_output(
416
416
417
417
if isinstance (values [0 ], dict ):
418
418
# GH #823 #24880
419
- index = self .grouper .result_index
419
+ index = self ._grouper .result_index
420
420
res_df = self .obj ._constructor_expanddim (values , index = index )
421
421
res_df = self ._reindex_output (res_df )
422
422
# if self.observed is False,
@@ -439,7 +439,7 @@ def _wrap_applied_output(
439
439
else :
440
440
# GH #6265 #24880
441
441
result = self .obj ._constructor (
442
- data = values , index = self .grouper .result_index , name = self .obj .name
442
+ data = values , index = self ._grouper .result_index , name = self .obj .name
443
443
)
444
444
if not self .as_index :
445
445
result = self ._insert_inaxis_grouper (result )
@@ -452,7 +452,7 @@ def _aggregate_named(self, func, *args, **kwargs):
452
452
result = {}
453
453
initialized = False
454
454
455
- for name , group in self .grouper .get_iterator (
455
+ for name , group in self ._grouper .get_iterator (
456
456
self ._obj_with_exclusions , axis = self .axis
457
457
):
458
458
# needed for pandas/tests/groupby/test_groupby.py::test_basic_aggregations
@@ -526,7 +526,7 @@ def _cython_transform(
526
526
obj = self ._obj_with_exclusions
527
527
528
528
try :
529
- result = self .grouper ._cython_operation (
529
+ result = self ._grouper ._cython_operation (
530
530
"transform" , obj ._values , how , axis , ** kwargs
531
531
)
532
532
except NotImplementedError as err :
@@ -549,7 +549,7 @@ def _transform_general(
549
549
klass = type (self .obj )
550
550
551
551
results = []
552
- for name , group in self .grouper .get_iterator (
552
+ for name , group in self ._grouper .get_iterator (
553
553
self ._obj_with_exclusions , axis = self .axis
554
554
):
555
555
# this setattr is needed for test_transform_lambda_with_datetimetz
@@ -621,7 +621,7 @@ def true_and_notna(x) -> bool:
621
621
try :
622
622
indices = [
623
623
self ._get_index (name )
624
- for name , group in self .grouper .get_iterator (
624
+ for name , group in self ._grouper .get_iterator (
625
625
self ._obj_with_exclusions , axis = self .axis
626
626
)
627
627
if true_and_notna (group )
@@ -673,11 +673,11 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
673
673
2023-02-01 1
674
674
Freq: MS, dtype: int64
675
675
"""
676
- ids , _ , ngroups = self .grouper .group_info
676
+ ids , _ , ngroups = self ._grouper .group_info
677
677
val = self .obj ._values
678
678
codes , uniques = algorithms .factorize (val , use_na_sentinel = dropna , sort = False )
679
679
680
- if self .grouper .has_dropped_na :
680
+ if self ._grouper .has_dropped_na :
681
681
mask = ids >= 0
682
682
ids = ids [mask ]
683
683
codes = codes [mask ]
@@ -699,7 +699,7 @@ def nunique(self, dropna: bool = True) -> Series | DataFrame:
699
699
res = np .bincount (ids [~ mask ], minlength = ngroups )
700
700
res = ensure_int64 (res )
701
701
702
- ri = self .grouper .result_index
702
+ ri = self ._grouper .result_index
703
703
result : Series | DataFrame = self .obj ._constructor (
704
704
res , index = ri , name = self .obj .name
705
705
)
@@ -734,10 +734,10 @@ def value_counts(
734
734
from pandas .core .reshape .merge import get_join_indexers
735
735
from pandas .core .reshape .tile import cut
736
736
737
- ids , _ , _ = self .grouper .group_info
737
+ ids , _ , _ = self ._grouper .group_info
738
738
val = self .obj ._values
739
739
740
- index_names = self .grouper .names + [self .obj .name ]
740
+ index_names = self ._grouper .names + [self .obj .name ]
741
741
742
742
if isinstance (val .dtype , CategoricalDtype ) or (
743
743
bins is not None and not np .iterable (bins )
@@ -804,9 +804,9 @@ def value_counts(
804
804
rep = partial (np .repeat , repeats = np .add .reduceat (inc , idx ))
805
805
806
806
# multi-index components
807
- codes = self .grouper . _reconstructed_codes
807
+ codes = self ._grouper . reconstructed_codes
808
808
codes = [rep (level_codes ) for level_codes in codes ] + [llab (lab , inc )]
809
- levels = [ping ._group_index for ping in self .grouper .groupings ] + [lev ]
809
+ levels = [ping ._group_index for ping in self ._grouper .groupings ] + [lev ]
810
810
811
811
if dropna :
812
812
mask = codes [- 1 ] != - 1
@@ -1461,7 +1461,7 @@ def aggregate(self, func=None, *args, engine=None, engine_kwargs=None, **kwargs)
1461
1461
func , * args , engine_kwargs = engine_kwargs , ** kwargs
1462
1462
)
1463
1463
# grouper specific aggregations
1464
- if self .grouper .nkeys > 1 :
1464
+ if self ._grouper .nkeys > 1 :
1465
1465
# test_groupby_as_index_series_scalar gets here with 'not self.as_index'
1466
1466
return self ._python_agg_general (func , * args , ** kwargs )
1467
1467
elif args or kwargs :
@@ -1529,25 +1529,25 @@ def _python_agg_general(self, func, *args, **kwargs):
1529
1529
1530
1530
output : dict [int , ArrayLike ] = {}
1531
1531
for idx , (name , ser ) in enumerate (obj .items ()):
1532
- result = self .grouper .agg_series (ser , f )
1532
+ result = self ._grouper .agg_series (ser , f )
1533
1533
output [idx ] = result
1534
1534
1535
1535
res = self .obj ._constructor (output )
1536
1536
res .columns = obj .columns .copy (deep = False )
1537
1537
return self ._wrap_aggregated_output (res )
1538
1538
1539
1539
def _aggregate_frame (self , func , * args , ** kwargs ) -> DataFrame :
1540
- if self .grouper .nkeys != 1 :
1540
+ if self ._grouper .nkeys != 1 :
1541
1541
raise AssertionError ("Number of keys must be 1" )
1542
1542
1543
1543
obj = self ._obj_with_exclusions
1544
1544
1545
1545
result : dict [Hashable , NDFrame | np .ndarray ] = {}
1546
- for name , grp_df in self .grouper .get_iterator (obj , self .axis ):
1546
+ for name , grp_df in self ._grouper .get_iterator (obj , self .axis ):
1547
1547
fres = func (grp_df , * args , ** kwargs )
1548
1548
result [name ] = fres
1549
1549
1550
- result_index = self .grouper .result_index
1550
+ result_index = self ._grouper .result_index
1551
1551
other_ax = obj .axes [1 - self .axis ]
1552
1552
out = self .obj ._constructor (result , index = other_ax , columns = result_index )
1553
1553
if self .axis == 0 :
@@ -1567,7 +1567,7 @@ def _wrap_applied_output(
1567
1567
# GH#47787 see test_group_on_empty_multiindex
1568
1568
res_index = data .index
1569
1569
else :
1570
- res_index = self .grouper .result_index
1570
+ res_index = self ._grouper .result_index
1571
1571
1572
1572
result = self .obj ._constructor (index = res_index , columns = data .columns )
1573
1573
result = result .astype (data .dtypes , copy = False )
@@ -1587,7 +1587,7 @@ def _wrap_applied_output(
1587
1587
is_transform = is_transform ,
1588
1588
)
1589
1589
1590
- key_index = self .grouper .result_index if self .as_index else None
1590
+ key_index = self ._grouper .result_index if self .as_index else None
1591
1591
1592
1592
if isinstance (first_not_none , (np .ndarray , Index )):
1593
1593
# GH#1738: values is list of arrays of unequal lengths
@@ -1693,7 +1693,7 @@ def _cython_transform(
1693
1693
)
1694
1694
1695
1695
def arr_func (bvalues : ArrayLike ) -> ArrayLike :
1696
- return self .grouper ._cython_operation (
1696
+ return self ._grouper ._cython_operation (
1697
1697
"transform" , bvalues , how , 1 , ** kwargs
1698
1698
)
1699
1699
@@ -1715,7 +1715,7 @@ def _transform_general(self, func, engine, engine_kwargs, *args, **kwargs):
1715
1715
1716
1716
applied = []
1717
1717
obj = self ._obj_with_exclusions
1718
- gen = self .grouper .get_iterator (obj , axis = self .axis )
1718
+ gen = self ._grouper .get_iterator (obj , axis = self .axis )
1719
1719
fast_path , slow_path = self ._define_paths (func , * args , ** kwargs )
1720
1720
1721
1721
# Determine whether to use slow or fast path by evaluating on the first group.
@@ -1909,7 +1909,7 @@ def filter(self, func, dropna: bool = True, *args, **kwargs):
1909
1909
indices = []
1910
1910
1911
1911
obj = self ._selected_obj
1912
- gen = self .grouper .get_iterator (obj , axis = self .axis )
1912
+ gen = self ._grouper .get_iterator (obj , axis = self .axis )
1913
1913
1914
1914
for name , group in gen :
1915
1915
# 2023-02-27 no tests are broken this pinning, but it is documented in the
@@ -1971,7 +1971,7 @@ def _gotitem(self, key, ndim: int, subset=None):
1971
1971
self .keys ,
1972
1972
axis = self .axis ,
1973
1973
level = self .level ,
1974
- grouper = self .grouper ,
1974
+ grouper = self ._grouper ,
1975
1975
exclusions = self .exclusions ,
1976
1976
selection = key ,
1977
1977
as_index = self .as_index ,
@@ -1987,7 +1987,7 @@ def _gotitem(self, key, ndim: int, subset=None):
1987
1987
subset ,
1988
1988
self .keys ,
1989
1989
level = self .level ,
1990
- grouper = self .grouper ,
1990
+ grouper = self ._grouper ,
1991
1991
exclusions = self .exclusions ,
1992
1992
selection = key ,
1993
1993
as_index = self .as_index ,
@@ -2024,7 +2024,7 @@ def _apply_to_column_groupbys(self, func) -> DataFrame:
2024
2024
SeriesGroupBy (
2025
2025
obj .iloc [:, i ],
2026
2026
selection = colname ,
2027
- grouper = self .grouper ,
2027
+ grouper = self ._grouper ,
2028
2028
exclusions = self .exclusions ,
2029
2029
observed = self .observed ,
2030
2030
)
@@ -2034,7 +2034,7 @@ def _apply_to_column_groupbys(self, func) -> DataFrame:
2034
2034
2035
2035
if not len (results ):
2036
2036
# concat would raise
2037
- res_df = DataFrame ([], columns = columns , index = self .grouper .result_index )
2037
+ res_df = DataFrame ([], columns = columns , index = self ._grouper .result_index )
2038
2038
else :
2039
2039
res_df = concat (results , keys = columns , axis = 1 )
2040
2040
0 commit comments