@@ -202,9 +202,7 @@ def get_data(self, location):
202
202
203
203
# extract
204
204
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
208
206
209
207
# return
210
208
print (f"[successfully fetched data for { location } ]" )
@@ -325,6 +323,8 @@ def _groupid_to_name(self, ageid, sexid, raceid, fluid):
325
323
raise ValueError ("Expect at least three of four group ids to be 0" )
326
324
if (ageid , sexid , raceid , fluid ).count (0 ) == 4 :
327
325
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
328
328
elif ageid != 0 :
329
329
if ageid == 6 :
330
330
# Ageid of 6 used to be used for the "overall" category.
@@ -333,23 +333,13 @@ def _groupid_to_name(self, ageid, sexid, raceid, fluid):
333
333
# has gone wrong.
334
334
raise ValueError ("Ageid cannot be 6; please check for changes in the API" )
335
335
else :
336
- age_group = self .metadata .id_to_group ["Age" ][ ageid ]
336
+ age_group = self .metadata .id_to_group ["Age" ]. get ( ageid , ageid )
337
337
group = "age_" + age_group
338
338
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 )
340
340
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 )
342
342
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 )
344
344
345
345
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