1
- from datetime import date
2
1
from typing import (
3
2
Any ,
4
3
Dict ,
24
23
AEpiDataCall ,
25
24
EpidataFieldInfo ,
26
25
EpidataFieldType ,
27
- EpiDataFormatType ,
28
26
EpiDataResponse ,
29
27
EpiRange ,
30
28
EpiRangeParam ,
@@ -87,11 +85,10 @@ def with_session(self, session: Session) -> "EpiDataCall":
87
85
88
86
def _call (
89
87
self ,
90
- format_type : Optional [EpiDataFormatType ] = None ,
91
88
fields : Optional [Sequence [str ]] = None ,
92
89
stream : bool = False ,
93
90
) -> Response :
94
- url , params = self .request_arguments (format_type , fields )
91
+ url , params = self .request_arguments (fields )
95
92
return _request_with_retry (url , params , self ._session , stream )
96
93
97
94
def classic (
@@ -102,7 +99,7 @@ def classic(
102
99
"""Request and parse epidata in CLASSIC message format."""
103
100
self ._verify_parameters ()
104
101
try :
105
- response = self ._call (None , fields )
102
+ response = self ._call (fields )
106
103
r = cast (EpiDataResponse , response .json ())
107
104
epidata = r .get ("epidata" )
108
105
if epidata and isinstance (epidata , list ) and len (epidata ) > 0 and isinstance (epidata [0 ], dict ):
@@ -115,25 +112,11 @@ def __call__(
115
112
self ,
116
113
fields : Optional [Sequence [str ]] = None ,
117
114
disable_date_parsing : Optional [bool ] = False ,
118
- ) -> EpiDataResponse :
119
- """Request and parse epidata in CLASSIC message format."""
120
- return self .classic (fields , disable_date_parsing = disable_date_parsing )
121
-
122
- def json (
123
- self ,
124
- fields : Optional [Sequence [str ]] = None ,
125
- disable_date_parsing : Optional [bool ] = False ,
126
- ) -> List [Mapping [str , Union [str , int , float , date , None ]]]:
127
- """Request and parse epidata in JSON format"""
115
+ ) -> Union [EpiDataResponse , DataFrame ]:
116
+ """Request and parse epidata in df message format."""
128
117
if self .only_supports_classic :
129
- raise OnlySupportsClassicFormatException ()
130
- self ._verify_parameters ()
131
- response = self ._call (EpiDataFormatType .json , fields )
132
- response .raise_for_status ()
133
- return [
134
- self ._parse_row (row , disable_date_parsing = disable_date_parsing )
135
- for row in cast (List [Mapping [str , Union [str , int , float , None ]]], response .json ())
136
- ]
118
+ return self .classic (fields , disable_date_parsing = disable_date_parsing )
119
+ return self .df (fields , disable_date_parsing = disable_date_parsing )
137
120
138
121
def df (
139
122
self ,
@@ -144,7 +127,8 @@ def df(
144
127
if self .only_supports_classic :
145
128
raise OnlySupportsClassicFormatException ()
146
129
self ._verify_parameters ()
147
- rows = self .json (fields , disable_date_parsing = disable_date_parsing )
130
+ json = self .classic (fields , disable_date_parsing = disable_date_parsing )
131
+ rows = json .get ("epidata" , [])
148
132
pred = fields_to_predicate (fields )
149
133
columns : List [str ] = [info .name for info in self .meta if pred (info .name )]
150
134
df = DataFrame (rows , columns = columns or None )
0 commit comments