@@ -247,36 +247,60 @@ def get_detections_data(base_url,headers,update_date):
247247def expand_detections_columns (new_data ):
248248 # add extra columns - percent positivities
249249 if "adv_positive_tests" in new_data .columns and "adv_tests" in new_data .columns :
250- new_data ["adv_pct_positive" ] = new_data ["adv_positive_tests" ]/ new_data ["adv_tests" ]* 100
250+ new_data ["adv_pct_positive" ] = np .divide (new_data ["adv_positive_tests" ], new_data ["adv_tests" ],
251+ out = np .zeros_like (new_data ["adv_positive_tests" ],dtype = float ),
252+ where = new_data ["adv_tests" ]!= 0 )* 100
251253
252254 if "evrv_positive_tests" in new_data .columns and "evrv_tests" in new_data .columns :
253- new_data ["evrv_pct_positive" ] = new_data ["evrv_positive_tests" ]/ new_data ["evrv_tests" ]* 100
255+ new_data ["evrv_pct_positive" ] = np .divide (new_data ["evrv_positive_tests" ], new_data ["evrv_tests" ],
256+ out = np .zeros_like (new_data ["evrv_positive_tests" ],dtype = float ),
257+ where = new_data ["evrv_tests" ]!= 0 )* 100
254258
255259 if "flu_positive_tests" in new_data .columns and "flu_tests" in new_data .columns :
256- new_data ["flu_pct_positive" ] = new_data ["flu_positive_tests" ]/ new_data ["flu_tests" ]* 100
260+ new_data ["flu_pct_positive" ] = np .divide (new_data ["flu_positive_tests" ], new_data ["flu_tests" ],
261+ out = np .zeros_like (new_data ["flu_positive_tests" ],dtype = float ),
262+ where = new_data ["flu_tests" ]!= 0 )* 100
257263
258264 if "sarscov2_positive_tests" in new_data .columns and "sarscov2_tests" in new_data .columns :
259- new_data ["sarscov2_pct_positive" ] = new_data ["sarscov2_positive_tests" ]/ new_data ["sarscov2_tests" ]* 100
265+ new_data ["sarscov2_pct_positive" ] = np .divide (new_data ["sarscov2_positive_tests" ], new_data ["sarscov2_tests" ],
266+ out = np .zeros_like (new_data ["sarscov2_positive_tests" ],dtype = float ),
267+ where = new_data ["sarscov2_tests" ]!= 0 )* 100
260268
261269 if "flua_positive_tests" in new_data .columns and "flub_positive_tests" in new_data .columns :
262270 new_data ["flua_tests" ] = new_data ["flu_tests" ]
263271 new_data ["flub_tests" ] = new_data ["flu_tests" ]
264- new_data ["flua_pct_positive" ] = new_data ["flua_positive_tests" ]/ new_data ["flu_tests" ]* 100
272+
273+ new_data ["flua_pct_positive" ] = np .divide (new_data ["flua_positive_tests" ], new_data ["flu_tests" ],
274+ out = np .zeros_like (new_data ["flua_positive_tests" ],dtype = float ),
275+ where = new_data ["flu_tests" ]!= 0 )* 100
276+
265277 new_data ["flub_pct_positive" ] = new_data ["flub_positive_tests" ]/ new_data ["flu_tests" ]* 100
278+ new_data ["flub_pct_positive" ] = np .divide (new_data ["flub_positive_tests" ], new_data ["flu_tests" ],
279+ out = np .zeros_like (new_data ["flub_positive_tests" ],dtype = float ),
280+ where = new_data ["flu_tests" ]!= 0 )* 100
266281
267282 if "hcov_positive_tests" in new_data .columns and "hcov_tests" in new_data .columns :
268- new_data ["hcov_pct_positive" ] = new_data ["hcov_positive_tests" ]/ new_data ["hcov_tests" ]* 100
283+ new_data ["hcov_pct_positive" ] = np .divide (new_data ["hcov_positive_tests" ], new_data ["hcov_tests" ],
284+ out = np .zeros_like (new_data ["hcov_positive_tests" ],dtype = float ),
285+ where = new_data ["hcov_tests" ]!= 0 )* 100
269286
270287 if "hmpv_positive_tests" in new_data .columns and "hmpv_tests" in new_data .columns :
271- new_data ["hmpv_pct_positive" ] = new_data ["hmpv_positive_tests" ]/ new_data ["hmpv_tests" ]* 100
288+ new_data ["hmpv_pct_positive" ] = np .divide (new_data ["hmpv_positive_tests" ], new_data ["hmpv_tests" ],
289+ out = np .zeros_like (new_data ["hmpv_positive_tests" ],dtype = float ),
290+ where = new_data ["hmpv_tests" ]!= 0 )* 100
272291
273292 if "rsv_positive_tests" in new_data .columns and "rsv_tests" in new_data .columns :
274- new_data ["rsv_pct_positive" ] = new_data ["rsv_positive_tests" ]/ new_data ["rsv_tests" ]* 100
293+ new_data ["rsv_pct_positive" ] = np .divide (new_data ["rsv_positive_tests" ], new_data ["rsv_tests" ],
294+ out = np .zeros_like (new_data ["rsv_positive_tests" ],dtype = float ),
295+ where = new_data ["rsv_tests" ]!= 0 )* 100
275296
276297 if "hpiv1_positive_tests" in new_data .columns and "hpiv_tests" in new_data .columns :
277298 new_data ["hpiv_positive_tests" ] = new_data ["hpiv1_positive_tests" ] + new_data ["hpiv2_positive_tests" ]+ new_data ["hpiv3_positive_tests" ]+ new_data ["hpiv4_positive_tests" ]+ new_data ["hpivother_positive_tests" ]
278- new_data ["hpiv_pct_positive" ] = new_data ["hpiv_positive_tests" ]/ new_data ["hpiv_tests" ]* 100
279299
300+ new_data ["hpiv_pct_positive" ] = np .divide (new_data ["hpiv_positive_tests" ], new_data ["hpiv_tests" ],
301+ out = np .zeros_like (new_data ["hpiv_positive_tests" ],dtype = float ),
302+ where = new_data ["hpiv_tests" ]!= 0 )* 100
303+
280304 return (new_data .set_index (['epiweek' , 'time_value' , 'issue' , 'geo_type' , 'geo_value' ]))
281305
282306def duplicate_provincial_detections (data ):
@@ -301,9 +325,12 @@ def combine_tables(data_dict):
301325 num_tables = len (data_dict )
302326 if (num_tables == 2 ):
303327 positive = data_dict ["positive" ]
328+ positive = positive .reset_index ()
329+
304330 detections = data_dict ["respiratory_detection" ]
331+ detections = detections .reset_index ()
332+
305333 detections = expand_detections_columns (detections )
306-
307334 positive = positive .drop (['geo_type' ], axis = 1 )
308335 positive ['geo_type' ] = [create_geo_types (g ,'lab' ) for g in positive ['geo_value' ]]
309336 positive = positive .set_index (['epiweek' , 'time_value' , 'issue' , 'geo_type' , 'geo_value' ])
0 commit comments