@@ -117,8 +117,9 @@ def covid19(country = None,
117117 write_src_cache (src , end , vintage )
118118 # cast columns
119119 df ['date' ] = df ['date' ].apply (lambda x : datetime .datetime .strptime (x , "%Y-%m-%d" ))
120- df ['iso_numeric' ] = df ['iso_numeric' ].apply (lambda x : float (x ))
121-
120+ try : df ['iso_numeric' ] = df ['iso_numeric' ].apply (lambda x : float (x ))
121+ except : pass
122+
122123 write_cache (df , level , end , raw , vintage )
123124
124125 # src
@@ -134,10 +135,19 @@ def covid19(country = None,
134135 # no idea why, but I found solution to mute it as follows
135136 with warnings .catch_warnings ():
136137 warnings .simplefilter (action = 'ignore' , category = FutureWarning )
137- df = df [(df ['iso_alpha_3' ].isin (country )) |
138- (df ['iso_alpha_2' ].isin (country )) |
139- (df ['iso_numeric' ].isin (country )) |
140- (df ['administrative_area_level_1' ].map (lambda s : s .upper ()).isin (country )) ]
138+
139+ country_filter = df ['administrative_area_level_1' ].map (lambda s : s .upper ()).isin (country )
140+ for feature in ["iso_alpha_2" ,"iso_alpha_3" ,"iso_numeric" ]:
141+ try :
142+ country_filter = country_filter | df [feature ].isin (country )
143+ except KeyError :
144+ pass
145+ df = df [country_filter ]
146+
147+ #df = df[(df['iso_alpha_3'].isin(country)) |
148+ # (df['iso_alpha_2'].isin(country)) |
149+ # (df['iso_numeric'].isin(country)) |
150+ # (df['administrative_area_level_1'].map(lambda s: s.upper()).isin(country)) ]
141151 if start is not None :
142152 df = df [df ['date' ] >= start ]
143153 if end is not None :
@@ -146,7 +156,7 @@ def covid19(country = None,
146156 # detect empty
147157 if df .empty :
148158 warnings .warn ("no data for given settings" , category = ResourceWarning )
149- return None
159+ return None , None
150160 # sort
151161 df = df .sort_values (by = ["id" ,"date" ])
152162
0 commit comments