@@ -123,6 +123,8 @@ def __init__(
123
123
on : str | Index | None = None ,
124
124
closed : str | None = None ,
125
125
method : str = "single" ,
126
+ * ,
127
+ selection = None ,
126
128
):
127
129
self .obj = obj
128
130
self .on = on
@@ -150,6 +152,8 @@ def __init__(
150
152
f"invalid on specified as { self .on } , "
151
153
"must be a column (of DataFrame), an Index or None"
152
154
)
155
+
156
+ self ._selection = selection
153
157
self .validate ()
154
158
155
159
@property
@@ -242,16 +246,22 @@ def _gotitem(self, key, ndim, subset=None):
242
246
# create a new object to prevent aliasing
243
247
if subset is None :
244
248
subset = self .obj
245
- # TODO: Remove once win_type deprecation is enforced
249
+
250
+ # we need to make a shallow copy of ourselves
251
+ # with the same groupby
246
252
with warnings .catch_warnings ():
253
+ # TODO: Remove once win_type deprecation is enforced
247
254
warnings .filterwarnings ("ignore" , "win_type" , FutureWarning )
248
- self = type (self )(
249
- subset , ** {attr : getattr (self , attr ) for attr in self ._attributes }
250
- )
251
- if subset .ndim == 2 :
252
- if is_scalar (key ) and key in subset or is_list_like (key ):
253
- self ._selection = key
254
- return self
255
+ kwargs = {attr : getattr (self , attr ) for attr in self ._attributes }
256
+
257
+ selection = None
258
+ if subset .ndim == 2 and (
259
+ (is_scalar (key ) and key in subset ) or is_list_like (key )
260
+ ):
261
+ selection = key
262
+
263
+ new_win = type (self )(subset , selection = selection , ** kwargs )
264
+ return new_win
255
265
256
266
def __getattr__ (self , attr : str ):
257
267
if attr in self ._internal_names_set :
0 commit comments