@@ -202,9 +202,7 @@ def get_data(self, location):
202202
203203 # extract
204204 print ("[reformatting flusurv result...]" )
205- data_out = self ._add_sex_breakdowns_ut (
206- self ._group_by_epiweek (data_in ), location
207- )
205+ data_out = self ._group_by_epiweek (data_in ), location
208206
209207 # return
210208 print (f"[successfully fetched data for { location } ]" )
@@ -325,6 +323,8 @@ def _groupid_to_name(self, ageid, sexid, raceid, fluid):
325323 raise ValueError ("Expect at least three of four group ids to be 0" )
326324 if (ageid , sexid , raceid , fluid ).count (0 ) == 4 :
327325 group = "overall"
326+ # In all cases, if id is not available as a key in the dict, use the
327+ # raw id as the name suffix
328328 elif ageid != 0 :
329329 if ageid == 6 :
330330 # Ageid of 6 used to be used for the "overall" category.
@@ -333,23 +333,13 @@ def _groupid_to_name(self, ageid, sexid, raceid, fluid):
333333 # has gone wrong.
334334 raise ValueError ("Ageid cannot be 6; please check for changes in the API" )
335335 else :
336- age_group = self .metadata .id_to_group ["Age" ][ ageid ]
336+ age_group = self .metadata .id_to_group ["Age" ]. get ( ageid , ageid )
337337 group = "age_" + age_group
338338 elif sexid != 0 :
339- group = "sex_" + self .metadata .id_to_group ["Sex" ][ sexid ]
339+ group = "sex_" + self .metadata .id_to_group ["Sex" ]. get ( sexid , ageid )
340340 elif raceid != 0 :
341- group = "race_" + self .metadata .id_to_group ["Race" ][ raceid ]
341+ group = "race_" + self .metadata .id_to_group ["Race" ]. get ( raceid , ageid )
342342 elif fluid != 0 :
343- group = "flu_" + self .metadata .id_to_group ["Flutype" ][ fluid ]
343+ group = "flu_" + self .metadata .id_to_group ["Flutype" ]. get ( fluid , ageid )
344344
345345 return "rate_" + group
346-
347- def _add_sex_breakdowns_ut (self , data , location ):
348- # UT doesn't have sex breakdowns available at least for 2022-23. Fill
349- # in to avoid downstream errors.
350- if location == "UT" :
351- for epiweek in data .keys ():
352- for group in SEX_GROUPS :
353- if group not in data [epiweek ].keys ():
354- data [epiweek ][group ] = None
355- return (data )
0 commit comments