Skip to content

Commit 53b7fff

Browse files
authored
TYP: BaseWindowGroupby._grouper (#41299)
1 parent 54a2c43 commit 53b7fff

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pandas/core/window/rolling.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
DataFrame,
102102
Series,
103103
)
104+
from pandas.core.groupby.ops import BaseGrouper
104105
from pandas.core.internals import Block # noqa:F401
105106

106107

@@ -538,18 +539,22 @@ class BaseWindowGroupby(BaseWindow):
538539
Provide the groupby windowing facilities.
539540
"""
540541

542+
_grouper: BaseGrouper
543+
_as_index: bool
541544
_attributes = ["_grouper"]
542545

543546
def __init__(
544547
self,
545548
obj: FrameOrSeries,
546549
*args,
547-
_grouper=None,
548-
_as_index=True,
550+
_grouper: BaseGrouper,
551+
_as_index: bool = True,
549552
**kwargs,
550553
):
551-
if _grouper is None:
552-
raise ValueError("Must pass a Grouper object.")
554+
from pandas.core.groupby.ops import BaseGrouper
555+
556+
if not isinstance(_grouper, BaseGrouper):
557+
raise ValueError("Must pass a BaseGrouper object.")
553558
self._grouper = _grouper
554559
self._as_index = _as_index
555560
# GH 32262: It's convention to keep the grouping column in
@@ -659,7 +664,9 @@ def _apply_pairwise(
659664
# When we evaluate the pairwise=True result, repeat the groupby
660665
# labels by the number of columns in the original object
661666
groupby_codes = self._grouper.codes
662-
groupby_levels = self._grouper.levels
667+
# error: Incompatible types in assignment (expression has type
668+
# "List[Index]", variable has type "List[Union[ndarray, Index]]")
669+
groupby_levels = self._grouper.levels # type: ignore[assignment]
663670

664671
group_indices = self._grouper.indices.values()
665672
if group_indices:

0 commit comments

Comments
 (0)