@@ -292,7 +292,7 @@ def episode_single(
292292
293293 # Classify events for each segment
294294 ep_per_seg = (
295- segment_data .groupby ("segment" )
295+ segment_data .groupby ("segment" )[[ "gl" ]]
296296 .apply (
297297 lambda x : pd .DataFrame (
298298 {
@@ -302,8 +302,7 @@ def episode_single(
302302 "lv2_hyper" : event_class (x , "hyper" , lv2_hyper , dur_idx , end_idx ),
303303 "ext_hypo" : event_class (x , "hypo" , lv1_hypo , int (120 / dt0 ) + 1 , end_idx ),
304304 }
305- ),
306- include_groups = False ,
305+ )
307306 )
308307 .reset_index ()
309308 .drop (columns = ["level_1" ])
@@ -383,7 +382,7 @@ def event_class(
383382
384383 # Group by event and calculate start/end positions
385384 annotated_grouped = (
386- annotated .groupby ("event" )
385+ annotated .groupby ("event" )[[ "level" ]]
387386 .apply (
388387 lambda x : pd .DataFrame (
389388 {
@@ -399,8 +398,7 @@ def event_class(
399398 ["end" if (not x ["level" ].iloc [0 ] and len (x ) >= end_duration ) else None ] + [None ] * (len (x ) - 1 )
400399 ),
401400 }
402- ),
403- include_groups = False ,
401+ )
404402 )
405403 .reset_index ()
406404 .drop (columns = ["level_1" ])
@@ -462,12 +460,16 @@ def lv1_excl(data: pd.DataFrame) -> np.ndarray:
462460 lv2 = [column for column in data .columns if column .startswith ("lv2" )]
463461 lv2_first = lv2 [0 ]
464462 # Group by segment and lv1
465- grouped = data .groupby (["segment" , lv1_first ])
463+ grouped = data .groupby (["segment" , lv1_first ])[
464+ [
465+ lv1_first ,
466+ lv2_first ,
467+ ]
468+ ]
466469
467470 # Calculate exclusive labels
468471 excl = grouped .apply (
469- lambda x : pd .DataFrame ({"excl" : [0 if (x [lv2_first ].values > 0 ).any () else x [lv1_first ].iloc [0 ]] * len (x )}),
470- include_groups = False ,
472+ lambda x : pd .DataFrame ({"excl" : [0 if (x [lv2_first ].values > 0 ).any () else x [lv1_first ].iloc [0 ]] * len (x )})
471473 )
472474
473475 excl = excl .reset_index ()
0 commit comments