From b22657afe1dbdff3d93d30f75f579685dffde764 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 3 May 2021 18:55:50 -0700 Subject: [PATCH] TYP: BaseWindowGroupby._grouper --- pandas/core/window/rolling.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 1c85385c587a5..b51875134c614 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -101,6 +101,7 @@ DataFrame, Series, ) + from pandas.core.groupby.ops import BaseGrouper from pandas.core.internals import Block # noqa:F401 @@ -538,18 +539,22 @@ class BaseWindowGroupby(BaseWindow): Provide the groupby windowing facilities. """ + _grouper: BaseGrouper + _as_index: bool _attributes = ["_grouper"] def __init__( self, obj: FrameOrSeries, *args, - _grouper=None, - _as_index=True, + _grouper: BaseGrouper, + _as_index: bool = True, **kwargs, ): - if _grouper is None: - raise ValueError("Must pass a Grouper object.") + from pandas.core.groupby.ops import BaseGrouper + + if not isinstance(_grouper, BaseGrouper): + raise ValueError("Must pass a BaseGrouper object.") self._grouper = _grouper self._as_index = _as_index # GH 32262: It's convention to keep the grouping column in @@ -659,7 +664,9 @@ def _apply_pairwise( # When we evaluate the pairwise=True result, repeat the groupby # labels by the number of columns in the original object groupby_codes = self._grouper.codes - groupby_levels = self._grouper.levels + # error: Incompatible types in assignment (expression has type + # "List[Index]", variable has type "List[Union[ndarray, Index]]") + groupby_levels = self._grouper.levels # type: ignore[assignment] group_indices = self._grouper.indices.values() if group_indices: