@@ -133,6 +133,7 @@ class Resampler(BaseGroupBy, PandasObject):
133
133
_timegrouper : TimeGrouper
134
134
binner : DatetimeIndex | TimedeltaIndex | PeriodIndex # depends on subclass
135
135
exclusions : frozenset [Hashable ] = frozenset () # for SelectionMixin compat
136
+ _internal_names_set = set ({"obj" , "ax" })
136
137
137
138
# to the groupby descriptor
138
139
_attributes = [
@@ -153,6 +154,7 @@ def __init__(
153
154
axis : Axis = 0 ,
154
155
kind = None ,
155
156
* ,
157
+ gpr_index : Index ,
156
158
group_keys : bool | lib .NoDefault = lib .no_default ,
157
159
selection = None ,
158
160
) -> None :
@@ -166,7 +168,9 @@ def __init__(
166
168
self .group_keys = group_keys
167
169
self .as_index = True
168
170
169
- self ._timegrouper ._set_grouper (self ._convert_obj (obj ), sort = True )
171
+ self .obj , self .ax = self ._timegrouper ._set_grouper (
172
+ self ._convert_obj (obj ), sort = True , gpr_index = gpr_index
173
+ )
170
174
self .binner , self .grouper = self ._get_binner ()
171
175
self ._selection = selection
172
176
if self ._timegrouper .key is not None :
@@ -195,19 +199,6 @@ def __getattr__(self, attr: str):
195
199
196
200
return object .__getattribute__ (self , attr )
197
201
198
- # error: Signature of "obj" incompatible with supertype "BaseGroupBy"
199
- @property
200
- def obj (self ) -> NDFrame : # type: ignore[override]
201
- # error: Incompatible return value type (got "Optional[Any]",
202
- # expected "NDFrameT")
203
- return self ._timegrouper .obj # type: ignore[return-value]
204
-
205
- @property
206
- def ax (self ):
207
- # we can infer that this is a PeriodIndex/DatetimeIndex/TimedeltaIndex,
208
- # but skipping annotating bc the overrides overwhelming
209
- return self ._timegrouper .ax
210
-
211
202
@property
212
203
def _from_selection (self ) -> bool :
213
204
"""
@@ -1189,6 +1180,9 @@ def __init__(
1189
1180
self ._groupby = groupby
1190
1181
self ._timegrouper = copy .copy (parent ._timegrouper )
1191
1182
1183
+ self .ax = parent .ax
1184
+ self .obj = parent .obj
1185
+
1192
1186
@no_type_check
1193
1187
def _apply (self , f , * args , ** kwargs ):
1194
1188
"""
@@ -1197,7 +1191,7 @@ def _apply(self, f, *args, **kwargs):
1197
1191
"""
1198
1192
1199
1193
def func (x ):
1200
- x = self ._resampler_cls (x , timegrouper = self ._timegrouper )
1194
+ x = self ._resampler_cls (x , timegrouper = self ._timegrouper , gpr_index = self . ax )
1201
1195
1202
1196
if isinstance (f , str ):
1203
1197
return getattr (x , f )(** kwargs )
@@ -1226,8 +1220,7 @@ def _gotitem(self, key, ndim, subset=None):
1226
1220
"""
1227
1221
# create a new object to prevent aliasing
1228
1222
if subset is None :
1229
- # error: "GotItemMixin" has no attribute "obj"
1230
- subset = self .obj # type: ignore[attr-defined]
1223
+ subset = self .obj
1231
1224
1232
1225
# Try to select from a DataFrame, falling back to a Series
1233
1226
try :
@@ -1688,16 +1681,16 @@ def _get_resampler(self, obj: NDFrame, kind=None) -> Resampler:
1688
1681
TypeError if incompatible axis
1689
1682
1690
1683
"""
1691
- self ._set_grouper (obj )
1684
+ _ , ax = self ._set_grouper (obj , gpr_index = None )
1692
1685
1693
- ax = self .ax
1694
1686
if isinstance (ax , DatetimeIndex ):
1695
1687
return DatetimeIndexResampler (
1696
1688
obj ,
1697
1689
timegrouper = self ,
1698
1690
kind = kind ,
1699
1691
axis = self .axis ,
1700
1692
group_keys = self .group_keys ,
1693
+ gpr_index = ax ,
1701
1694
)
1702
1695
elif isinstance (ax , PeriodIndex ) or kind == "period" :
1703
1696
return PeriodIndexResampler (
@@ -1706,10 +1699,15 @@ def _get_resampler(self, obj: NDFrame, kind=None) -> Resampler:
1706
1699
kind = kind ,
1707
1700
axis = self .axis ,
1708
1701
group_keys = self .group_keys ,
1702
+ gpr_index = ax ,
1709
1703
)
1710
1704
elif isinstance (ax , TimedeltaIndex ):
1711
1705
return TimedeltaIndexResampler (
1712
- obj , timegrouper = self , axis = self .axis , group_keys = self .group_keys
1706
+ obj ,
1707
+ timegrouper = self ,
1708
+ axis = self .axis ,
1709
+ group_keys = self .group_keys ,
1710
+ gpr_index = ax ,
1713
1711
)
1714
1712
1715
1713
raise TypeError (
0 commit comments