Skip to content

Commit a1acdba

Browse files
committed
fix: update tests and df type casting
1 parent b46d128 commit a1acdba

File tree

2 files changed

+407
-428
lines changed

2 files changed

+407
-428
lines changed

epidatpy/request.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ def df(
137137
df = DataFrame(rows, columns=columns or None)
138138

139139
data_types: Dict[str, Any] = {}
140-
time_fields: List[str] = []
140+
time_fields: List[EpidataFieldInfo] = []
141141
for info in self.meta:
142-
if not pred(info.name) or df[info.name].isnull().all():
142+
if not pred(info.name):
143143
continue
144144
if info.type == EpidataFieldType.bool:
145145
data_types[info.name] = bool
@@ -154,17 +154,27 @@ def df(
154154
EpidataFieldType.epiweek,
155155
EpidataFieldType.date_or_epiweek,
156156
):
157-
data_types[info.name] = "Int64"
158-
time_fields.append(info.name)
157+
data_types[info.name] = "string"
158+
time_fields.append(info)
159159
elif info.type == EpidataFieldType.float:
160160
data_types[info.name] = "Float64"
161161
else:
162162
data_types[info.name] = "string"
163163
if data_types:
164164
df = df.astype(data_types)
165165
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
168178
return df
169179

170180

0 commit comments

Comments
 (0)