Skip to content

Commit

Permalink
fix: DataFrame date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dshemetov committed Jul 13, 2024
1 parent 03bc328 commit 9177e01
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions epidatpy/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
cast,
)

from pandas import CategoricalDtype, DataFrame, Series
from pandas import CategoricalDtype, DataFrame, Series, to_datetime
from requests import Response, Session
from requests.auth import HTTPBasicAuth
from tenacity import retry, stop_after_attempt
Expand Down Expand Up @@ -137,6 +137,7 @@ def df(
df = DataFrame(rows, columns=columns or None)

data_types: Dict[str, Any] = {}
time_fields: List[str] = []
for info in self.meta:
if not pred(info.name) or df[info.name].isnull().all():
continue
Expand All @@ -153,13 +154,17 @@ def df(
EpidataFieldType.epiweek,
EpidataFieldType.date_or_epiweek,
):
data_types[info.name] = "Int64" if disable_date_parsing else "datetime64[ns]"
data_types[info.name] = "Int64"
time_fields.append(info.name)
elif info.type == EpidataFieldType.float:
data_types[info.name] = "Float64"
else:
data_types[info.name] = "string"
if data_types:
df = df.astype(data_types)
if not disable_date_parsing:
for field in time_fields:
df[field] = to_datetime(df[field], format="%Y%m%d", errors="ignore")
return df


Expand Down

0 comments on commit 9177e01

Please sign in to comment.