@@ -1727,6 +1727,18 @@ class BaseGrouper(object):
1727
1727
"""
1728
1728
This is an internal Grouper class, which actually holds
1729
1729
the generated groups
1730
+
1731
+ Parameters
1732
+ ----------
1733
+ axis : the axis to group
1734
+ groupings : all the grouping instances to handle in this grouper
1735
+ for example for grouper list to groupby, need to pass the list
1736
+ sort : True/False
1737
+ whether this grouper will give sorted result or not
1738
+ indexer: the indexer created by Grouper
1739
+ some grouper (TimeGrouper eg) will sort its axis and its
1740
+ group_info is also sorted, so need the indexer to reorder
1741
+
1730
1742
"""
1731
1743
1732
1744
def __init__ (self , axis , groupings , sort = True , group_keys = True ,
@@ -2283,6 +2295,35 @@ def generate_bins_generic(values, binner, closed):
2283
2295
2284
2296
class BinGrouper (BaseGrouper ):
2285
2297
2298
+ """
2299
+ This is an internal Grouper class, which actually holds
2300
+ the generated groups. In contrast with BaseGrouper,
2301
+ BinGrouper get the sorted bins and binlabels to compute group_info
2302
+
2303
+ Parameters
2304
+ ----------
2305
+ bins : the split index of binlabels to group the item of axis
2306
+ binlabels : the label list
2307
+ indexer: the indexer created by Grouper
2308
+ some grouper (TimeGrouper eg) will sort its axis and the
2309
+ group_info of BinGrouper is also sorted
2310
+ can use the indexer to reorder as the unsorted axis
2311
+
2312
+ Examples
2313
+ --------
2314
+ bins is [2, 4, 6, 8, 10]
2315
+ binlabels is DatetimeIndex(['2005-01-01', '2005-01-03',
2316
+ '2005-01-05', '2005-01-07', '2005-01-09'],
2317
+ dtype='datetime64[ns]', freq='2D')
2318
+
2319
+ then the group_info is
2320
+ (array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4]), array([0, 1, 2, 3, 4]), 5)
2321
+
2322
+ means the label of each item in axis, the index of label in label
2323
+ list, group number
2324
+
2325
+ """
2326
+
2286
2327
def __init__ (self , bins , binlabels , filter_empty = False , mutated = False ,
2287
2328
indexer = None ):
2288
2329
self .bins = _ensure_int64 (bins )
@@ -2457,7 +2498,8 @@ def __init__(self, index, grouper=None, obj=None, name=None, level=None,
2457
2498
self .grouper , self ._labels , self ._group_index = \
2458
2499
index ._get_grouper_for_level (self .grouper , level )
2459
2500
2460
- # a passed Grouper like
2501
+ # a passed Grouper like, directly get the grouper in the same way
2502
+ # as single grouper groupby, use the group_info to get labels
2461
2503
elif isinstance (self .grouper , Grouper ):
2462
2504
# get the new grouper
2463
2505
_ , grouper , _ = self .grouper ._get_grouper (self .obj )
@@ -2532,6 +2574,7 @@ def ngroups(self):
2532
2574
2533
2575
@cache_readonly
2534
2576
def indices (self ):
2577
+ # for the situation of groupby list of groupers
2535
2578
if isinstance (self .grouper , BaseGrouper ):
2536
2579
return self .grouper .indices
2537
2580
else :
0 commit comments