Skip to content

Commit 2d433c4

Browse files
committed
TYP: Add type hint for BaseGrouper in groupby._Groupby
1 parent 797732a commit 2d433c4

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

pandas/core/groupby/groupby.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class providing the base-class of operations.
4949
from pandas.core.frame import DataFrame
5050
from pandas.core.generic import NDFrame
5151
from pandas.core.groupby import base
52+
from pandas.core.groupby import ops
5253
from pandas.core.index import CategoricalIndex, Index, MultiIndex
5354
from pandas.core.series import Series
5455
from pandas.core.sorting import get_group_index_sorter
@@ -345,7 +346,7 @@ def __init__(
345346
keys=None,
346347
axis: int = 0,
347348
level=None,
348-
grouper=None,
349+
grouper: 'Optional[ops.BaseGrouper]' = None,
349350
exclusions=None,
350351
selection=None,
351352
as_index: bool = True,
@@ -2480,7 +2481,7 @@ def get_groupby(
24802481
by=None,
24812482
axis: int = 0,
24822483
level=None,
2483-
grouper=None,
2484+
grouper: 'Optional[ops.BaseGrouper]' = None,
24842485
exclusions=None,
24852486
selection=None,
24862487
as_index: bool = True,

pandas/core/groupby/grouper.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import pandas.core.common as com
2828
from pandas.core.frame import DataFrame
2929
from pandas.core.groupby.categorical import recode_for_groupby, recode_from_groupby
30-
from pandas.core.groupby.ops import BaseGrouper
30+
from pandas.core.groupby import ops
3131
from pandas.core.index import CategoricalIndex, Index, MultiIndex
3232
from pandas.core.series import Series
3333

@@ -392,7 +392,7 @@ def ngroups(self) -> int:
392392
@cache_readonly
393393
def indices(self):
394394
# we have a list of groupers
395-
if isinstance(self.grouper, BaseGrouper):
395+
if isinstance(self.grouper, ops.BaseGrouper):
396396
return self.grouper.indices
397397

398398
values = ensure_categorical(self.grouper)
@@ -419,7 +419,7 @@ def group_index(self) -> Index:
419419
def _make_codes(self) -> None:
420420
if self._codes is None or self._group_index is None:
421421
# we have a list of groupers
422-
if isinstance(self.grouper, BaseGrouper):
422+
if isinstance(self.grouper, ops.BaseGrouper):
423423
codes = self.grouper.codes_info
424424
uniques = self.grouper.result_index
425425
else:
@@ -442,7 +442,7 @@ def get_grouper(
442442
observed: bool = False,
443443
mutated: bool = False,
444444
validate: bool = True,
445-
) -> Tuple[BaseGrouper, List[Hashable], FrameOrSeries]:
445+
) -> 'Tuple[ops.BaseGrouper, List[Hashable], FrameOrSeries]':
446446
"""
447447
Create and return a BaseGrouper, which is an internal
448448
mapping of how to create the grouper indexers.
@@ -524,7 +524,7 @@ def get_grouper(
524524
return grouper, [key.key], obj
525525

526526
# already have a BaseGrouper, just return it
527-
elif isinstance(key, BaseGrouper):
527+
elif isinstance(key, ops.BaseGrouper):
528528
return key, [], obj
529529

530530
# In the future, a tuple key will always mean an actual key,
@@ -671,7 +671,7 @@ def is_in_obj(gpr) -> bool:
671671
groupings.append(Grouping(Index([], dtype="int"), np.array([], dtype=np.intp)))
672672

673673
# create the internals grouper
674-
grouper = BaseGrouper(group_axis, groupings, sort=sort, mutated=mutated)
674+
grouper = ops.BaseGrouper(group_axis, groupings, sort=sort, mutated=mutated)
675675
return grouper, exclusions, obj
676676

677677

0 commit comments

Comments
 (0)