@@ -137,9 +137,9 @@ def df(
137
137
df = DataFrame (rows , columns = columns or None )
138
138
139
139
data_types : Dict [str , Any ] = {}
140
- time_fields : List [str ] = []
140
+ time_fields : List [EpidataFieldInfo ] = []
141
141
for info in self .meta :
142
- if not pred (info .name ) or df [ info . name ]. isnull (). all () :
142
+ if not pred (info .name ):
143
143
continue
144
144
if info .type == EpidataFieldType .bool :
145
145
data_types [info .name ] = bool
@@ -154,17 +154,27 @@ def df(
154
154
EpidataFieldType .epiweek ,
155
155
EpidataFieldType .date_or_epiweek ,
156
156
):
157
- data_types [info .name ] = "Int64 "
158
- time_fields .append (info . name )
157
+ data_types [info .name ] = "string "
158
+ time_fields .append (info )
159
159
elif info .type == EpidataFieldType .float :
160
160
data_types [info .name ] = "Float64"
161
161
else :
162
162
data_types [info .name ] = "string"
163
163
if data_types :
164
164
df = df .astype (data_types )
165
165
if not disable_date_parsing :
166
- for field in time_fields :
167
- df [field ] = to_datetime (df [field ], format = "%Y%m%d" , errors = "ignore" )
166
+ for info in time_fields :
167
+ if info .type == EpidataFieldType .epiweek :
168
+ continue
169
+ try :
170
+ df [info .name ] = to_datetime (df [info .name ], format = "%Y-%m-%d" )
171
+ continue
172
+ except ValueError :
173
+ pass
174
+ try :
175
+ df [info .name ] = to_datetime (df [info .name ], format = "%Y%m%d" )
176
+ except ValueError :
177
+ pass
168
178
return df
169
179
170
180
0 commit comments