@@ -249,7 +249,7 @@ def _npv_group(group, disc):
249249 dropna = False ,
250250 as_index = False ,
251251 group_keys = False ,
252- observed = False ,
252+ observed = True ,
253253 )["risk" ].transform (_npv_group , risk_disc )
254254 df = df .reset_index ()
255255 return df
@@ -280,11 +280,14 @@ def _generic_metrics(
280280 # Notably for per_group_aai being None:
281281 try :
282282 tmp = pd .concat (tmp )
283+ if len (tmp ) == 0 :
284+ return None
283285 except ValueError as e :
284286 if str (e ) == "All objects passed were None" :
285287 return None
286288 else :
287289 raise e
290+
288291 else :
289292 tmp = tmp .set_index (["date" , "group" , "measure" , "metric" ])
290293 if "coord_id" in tmp .columns :
@@ -511,7 +514,7 @@ def identify_continuous_periods(group, time_unit):
511514 df_sorted = df .sort_values (by = cls ._grouper + ["date" ])
512515 # Apply the function to identify continuous periods
513516 df_periods = df_sorted .groupby (
514- grouper , dropna = False , group_keys = False , observed = False
517+ grouper , dropna = False , group_keys = False , observed = True
515518 ).apply (identify_continuous_periods , time_unit )
516519
517520 if isinstance (colname , str ):
@@ -525,7 +528,7 @@ def identify_continuous_periods(group, time_unit):
525528 agg_dict [col ] = pd .NamedAgg (column = col , aggfunc = "sum" )
526529 # Group by the identified periods and calculate start and end dates
527530 df_periods = (
528- df_periods .groupby (grouper + ["period_id" ], dropna = False , observed = False )
531+ df_periods .groupby (grouper + ["period_id" ], dropna = False , observed = True )
529532 .agg (** agg_dict )
530533 .reset_index ()
531534 )
0 commit comments