|
21 | 21 | from epiweeks import Week |
22 | 22 | from pandas import DataFrame, CategoricalDtype |
23 | 23 |
|
24 | | -from ._parse import parse_api_date, parse_api_week, fields_to_predicate |
| 24 | +from ._parse import parse_api_date, parse_api_week, parse_api_date_or_week, fields_to_predicate |
25 | 25 |
|
26 | 26 | EpiDateLike = Union[int, str, date, Week] |
27 | 27 | EpiRangeDict = TypedDict("EpiRangeDict", {"from": EpiDateLike, "to": EpiDateLike}) |
@@ -124,6 +124,7 @@ class EpidataFieldType(Enum): |
124 | 124 | epiweek = 4 |
125 | 125 | categorical = 5 |
126 | 126 | bool = 6 |
| 127 | + date_or_epiweek = 7 |
127 | 128 |
|
128 | 129 |
|
129 | 130 | @dataclass |
@@ -235,6 +236,8 @@ def _parse_value( |
235 | 236 | meta = self.meta_by_name.get(key) |
236 | 237 | if not meta or value is None: |
237 | 238 | return value |
| 239 | + if meta.type == EpidataFieldType.date_or_epiweek and not disable_date_parsing: |
| 240 | + return parse_api_date_or_week(value) |
238 | 241 | if meta.type == EpidataFieldType.date and not disable_date_parsing: |
239 | 242 | return parse_api_date(value) |
240 | 243 | if meta.type == EpidataFieldType.epiweek and not disable_date_parsing: |
@@ -270,7 +273,7 @@ def _as_df( |
270 | 273 | data_types[info.name] = CategoricalDtype(categories=info.categories or None, ordered=True) |
271 | 274 | elif info.type == EpidataFieldType.int: |
272 | 275 | data_types[info.name] = int |
273 | | - elif info.type in (EpidataFieldType.date, EpidataFieldType.epiweek): |
| 276 | + elif info.type in (EpidataFieldType.date, EpidataFieldType.epiweek, EpidataFieldType.date_or_epiweek): |
274 | 277 | data_types[info.name] = int if disable_date_parsing else "datetime64" |
275 | 278 | elif info.type == EpidataFieldType.float: |
276 | 279 | data_types[info.name] = float |
|
0 commit comments