Skip to content

Commit cd29f5c

Browse files
committed
more changes
1 parent 2c1a71e commit cd29f5c

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

pandas/core/groupby/grouper.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
split-apply-combine paradigm.
44
"""
55

6-
from typing import Tuple
6+
from typing import Optional, Tuple
77
import warnings
88

99
import numpy as np
1010

11+
from pandas._typing import FrameOrSeries
1112
from pandas.util._decorators import cache_readonly
1213

1314
from pandas.core.dtypes.common import (
@@ -228,7 +229,7 @@ class Grouping:
228229
----------
229230
index : Index
230231
grouper :
231-
obj :
232+
obj Union[DataFrame, Series]:
232233
name :
233234
level :
234235
observed : bool, default False
@@ -247,16 +248,15 @@ class Grouping:
247248

248249
def __init__(
249250
self,
250-
index,
251+
index: Index,
251252
grouper=None,
252-
obj=None,
253+
obj: Optional[FrameOrSeries] = None,
253254
name=None,
254255
level=None,
255-
sort=True,
256-
observed=False,
257-
in_axis=False,
256+
sort: bool = True,
257+
observed: bool = False,
258+
in_axis: bool = False,
258259
):
259-
260260
self.name = name
261261
self.level = level
262262
self.grouper = _convert_grouper(index, grouper)
@@ -306,7 +306,7 @@ def __init__(
306306
self.grouper = grouper._get_grouper()
307307

308308
else:
309-
if self.grouper is None and self.name is not None:
309+
if self.grouper is None and self.name is not None and self.obj is not None:
310310
self.grouper = self.obj[self.name]
311311

312312
elif isinstance(self.grouper, (list, tuple)):
@@ -676,7 +676,7 @@ def _is_label_like(val):
676676
return isinstance(val, (str, tuple)) or (val is not None and is_scalar(val))
677677

678678

679-
def _convert_grouper(axis, grouper):
679+
def _convert_grouper(axis: Index, grouper):
680680
if isinstance(grouper, dict):
681681
return grouper.get
682682
elif isinstance(grouper, Series):

pandas/core/groupby/ops.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import collections
10-
from typing import List, Optional, Type
10+
from typing import List, Optional, Type, Sequence
1111

1212
import numpy as np
1313

@@ -41,7 +41,7 @@
4141
import pandas.core.common as com
4242
from pandas.core.frame import DataFrame
4343
from pandas.core.generic import NDFrame
44-
from pandas.core.groupby import base
44+
from pandas.core.groupby import base, grouper
4545
from pandas.core.index import Index, MultiIndex, ensure_index
4646
from pandas.core.series import Series
4747
from pandas.core.sorting import (
@@ -62,13 +62,13 @@ class BaseGrouper:
6262
Parameters
6363
----------
6464
axis : Index
65-
groupings : array of grouping
65+
groupings : Sequence[Grouping]
6666
all the grouping instances to handle in this grouper
6767
for example for grouper list to groupby, need to pass the list
68-
sort : boolean, default True
68+
sort : bool, default True
6969
whether this grouper will give sorted result or not
70-
group_keys : boolean, default True
71-
mutated : boolean, default False
70+
group_keys : bool, default True
71+
mutated : bool, default False
7272
indexer : intp array, optional
7373
the indexer created by Grouper
7474
some groupers (TimeGrouper) will sort its axis and its
@@ -77,18 +77,18 @@ class BaseGrouper:
7777
"""
7878

7979
def __init__(
80-
self,
81-
axis: Index,
82-
groupings,
83-
sort=True,
84-
group_keys=True,
85-
mutated=False,
86-
indexer=None,
87-
):
80+
self,
81+
axis: Index,
82+
groupings: 'Sequence[grouper.Grouping]',
83+
sort: bool = True,
84+
group_keys: bool = True,
85+
mutated : bool = False,
86+
indexer: Optional[np.ndarray] = None):
8887
assert isinstance(axis, Index), axis
88+
8989
self._filter_empty_groups = self.compressed = len(groupings) != 1
9090
self.axis = axis
91-
self.groupings = groupings
91+
self.groupings = groupings # type: Sequence[grouper.Grouping]
9292
self.sort = sort
9393
self.group_keys = group_keys
9494
self.mutated = mutated

0 commit comments

Comments
 (0)