Skip to content

Commit 30bdcab

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

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pandas/core/groupby/groupby.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class providing the base-class of operations.
4848
from pandas.core.construction import extract_array
4949
from pandas.core.frame import DataFrame
5050
from pandas.core.generic import NDFrame
51-
from pandas.core.groupby import base
51+
from pandas.core.groupby import base, ops
5252
from pandas.core.index import CategoricalIndex, Index, MultiIndex
5353
from pandas.core.series import Series
5454
from pandas.core.sorting import get_group_index_sorter
@@ -345,7 +345,7 @@ def __init__(
345345
keys=None,
346346
axis: int = 0,
347347
level=None,
348-
grouper=None,
348+
grouper: "Optional[ops.BaseGrouper]" = None,
349349
exclusions=None,
350350
selection=None,
351351
as_index: bool = True,
@@ -2480,7 +2480,7 @@ def get_groupby(
24802480
by=None,
24812481
axis: int = 0,
24822482
level=None,
2483-
grouper=None,
2483+
grouper: "Optional[ops.BaseGrouper]" = None,
24842484
exclusions=None,
24852485
selection=None,
24862486
as_index: bool = True,

pandas/core/groupby/grouper.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
from pandas.core.arrays import Categorical, ExtensionArray
2727
import pandas.core.common as com
2828
from pandas.core.frame import DataFrame
29+
from pandas.core.groupby import ops
2930
from pandas.core.groupby.categorical import recode_for_groupby, recode_from_groupby
30-
from pandas.core.groupby.ops import BaseGrouper
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)