Skip to content

Commit

Permalink
dtype handling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rzats committed Jul 15, 2024
1 parent 722c8df commit 78d3532
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 3 deletions.
2 changes: 1 addition & 1 deletion epidatpy/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def _as_df(
elif info.type == EpidataFieldType.float:
data_types[info.name] = float
else:
data_types[info.name] = str
data_types[info.name] = "string"
if data_types:
df = df.astype(data_types)
return df
129 changes: 127 additions & 2 deletions tests/test_epidata_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ def test_pvt_cdc() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['num1'].dtype) == 'int64'
assert str(data['num2'].dtype) == 'int64'
assert str(data['num3'].dtype) == 'int64'
assert str(data['num4'].dtype) == 'int64'
assert str(data['num5'].dtype) == 'int64'
assert str(data['num6'].dtype) == 'int64'
assert str(data['num7'].dtype) == 'int64'
assert str(data['num8'].dtype) == 'int64'
assert str(data['total'].dtype) == 'int64'

def test_pub_covid_hosp_facility_lookup() -> None:
apicall = Epidata.pub_covid_hosp_facility_lookup(state="fl")
Expand All @@ -33,13 +43,35 @@ def test_pub_covid_hosp_facility_lookup() -> None:
apicall = Epidata.pub_covid_hosp_facility_lookup(city="southlake")
data = apicall.df()
assert len(data) > 0
assert str(data['hospital_pk'].dtype) == 'string'
assert str(data['state'].dtype) == 'string'
assert str(data['ccn'].dtype) == 'string'
assert str(data['hospital_name'].dtype) == 'string'
assert str(data['address'].dtype) == 'string'
assert str(data['city'].dtype) == 'string'
assert str(data['zip'].dtype) == 'string'
assert str(data['hospital_subtype'].dtype) == 'string'
assert str(data['fip_code'].dtype) == 'float64'
assert str(data['is_metro_micro'].dtype) == 'int64'

def test_pub_covid_hosp_facility() -> None:
apicall = Epidata.pub_covid_hosp_facility(
hospital_pks = "100075",
collection_weeks = EpiRange(20200101, 20200501))
data = apicall.df()
assert len(data) > 0
assert str(data['hospital_pk'].dtype) == 'string'
assert str(data['state'].dtype) == 'string'
assert str(data['ccn'].dtype) == 'string'
assert str(data['hospital_name'].dtype) == 'string'
assert str(data['address'].dtype) == 'string'
assert str(data['city'].dtype) == 'string'
assert str(data['zip'].dtype) == 'string'
assert str(data['hospital_subtype'].dtype) == 'string'
assert str(data['fips_code'].dtype) == 'string'
assert str(data['publication_date'].dtype) == 'datetime64[ns]'
assert str(data['collection_week'].dtype) == 'datetime64[ns]'
assert str(data['is_metro_micro'].dtype) == 'bool'

apicall = Epidata.pub_covid_hosp_facility(
hospital_pks = "100075",
Expand All @@ -53,13 +85,28 @@ def test_pub_covid_hosp_state_timeseries() -> None:
dates = EpiRange(20200101, 20200501))
data = apicall.df()
assert len(data) > 0
assert str(data['state'].dtype) == 'string'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['date'].dtype) == 'datetime64[ns]'

def test_pub_covidcast_meta() -> None:
apicall = Epidata.pub_covidcast_meta()
data = apicall.df()
assert len(data) > 0
assert str(data['data_source'].dtype) == 'string'
assert str(data['signal'].dtype) == 'string'
assert str(data['time_type'].dtype) == 'category'
assert str(data['min_time'].dtype) == 'datetime64[ns]'
assert str(data['max_time'].dtype) == 'datetime64[ns]'
assert str(data['num_locations'].dtype) == 'int64'
assert str(data['min_value'].dtype) == 'float64'
assert str(data['max_value'].dtype) == 'float64'
assert str(data['mean_value'].dtype) == 'float64'
assert str(data['stdev_value'].dtype) == 'float64'
assert str(data['last_update'].dtype) == 'int64'
assert str(data['max_issue'].dtype) == 'datetime64[ns]'
assert str(data['min_lag'].dtype) == 'int64'
assert str(data['max_lag'].dtype) == 'int64'

def test_pub_covidcast() -> None:
apicall = Epidata.pub_covidcast(
Expand All @@ -80,9 +127,20 @@ def test_pub_covidcast() -> None:
geo_values = "*",
time_values = EpiRange(20200601, 20200801))
data = apicall.df()
print(data.dtypes)

assert str(data['source'].dtype) == 'string'
assert str(data['signal'].dtype) == 'string'
assert str(data['geo_type'].dtype) == 'category'
assert str(data['geo_value'].dtype) == 'string'
assert str(data['time_type'].dtype) == 'category'
assert str(data['time_value'].dtype) == 'datetime64[ns]'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert len(data) > 0
assert str(data['lag'].dtype) == 'int64'
assert str(data['value'].dtype) == 'float64'
assert str(data['missing_value'].dtype) == 'int64'
assert str(data['missing_stderr'].dtype) == 'int64'
assert str(data['missing_sample_size'].dtype) == 'int64'

def test_pub_delphi() -> None:
apicall = Epidata.pub_delphi(
Expand All @@ -99,7 +157,10 @@ def test_pub_dengue_nowcast() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['value'].dtype) == 'float64'
assert str(data['std'].dtype) == 'float64'

def test_pvt_dengue_sensors() -> None:
apicall = Epidata.pvt_dengue_sensors(
Expand All @@ -110,7 +171,9 @@ def test_pvt_dengue_sensors() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['value'].dtype) == 'float64'

def test_pub_ecdc_ili() -> None:
apicall = Epidata.pub_ecdc_ili(
Expand All @@ -130,8 +193,17 @@ def test_pub_flusurv() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['release_date'].dtype) == 'string'
assert str(data['location'].dtype) == 'string'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['lag'].dtype) == 'int64'
assert str(data['rage_age_0'].dtype) == 'float64'
assert str(data['rage_age_1'].dtype) == 'float64'
assert str(data['rage_age_2'].dtype) == 'float64'
assert str(data['rage_age_3'].dtype) == 'float64'
assert str(data['rage_age_4'].dtype) == 'float64'
assert str(data['rage_overall'].dtype) == 'float64'

def test_pub_fluview_clinical() -> None:
apicall = Epidata.pub_fluview_clinical(
Expand All @@ -141,15 +213,24 @@ def test_pub_fluview_clinical() -> None:
data = apicall.df()
assert len(data) > 0
assert str(data['release_date'].dtype) == 'datetime64[ns]'
assert str(data['region'].dtype) == 'string'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['lag'].dtype) == 'int64'
assert str(data['total_specimens'].dtype) == 'int64'
assert str(data['total_a'].dtype) == 'int64'
assert str(data['total_b'].dtype) == 'int64'
assert str(data['percent_positive'].dtype) == 'float64'
assert str(data['percent_a'].dtype) == 'float64'
assert str(data['percent_b'].dtype) == 'float64'

def test_pub_fluview_meta() -> None:
apicall = Epidata.pub_fluview_meta()
data = apicall.df()
assert len(data) > 0
assert str(data['latest_update'].dtype) == 'datetime64[ns]'
assert str(data['latest_issue'].dtype) == 'datetime64[ns]'
assert str(data['table_rows'].dtype) == 'int64'

def test_pub_fluview() -> None:
apicall = Epidata.pub_fluview(
Expand All @@ -159,8 +240,14 @@ def test_pub_fluview() -> None:
data = apicall.df()
assert len(data) > 0
assert str(data['release_date'].dtype) == 'datetime64[ns]'
assert str(data['region'].dtype) == 'string'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['lag'].dtype) == 'int64'
assert str(data['num_ili'].dtype) == 'int64'
assert str(data['num_patients'].dtype) == 'int64'
assert str(data['wili'].dtype) == 'float64'
assert str(data['ili'].dtype) == 'float64'

def test_pub_gft() -> None:
apicall = Epidata.pub_gft(
Expand All @@ -169,7 +256,9 @@ def test_pub_gft() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['num'].dtype) == 'int64'

def test_pvt_ght() -> None:
apicall = Epidata.pvt_ght(
Expand All @@ -180,7 +269,9 @@ def test_pvt_ght() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['value'].dtype) == 'float64'

def test_pub_kcdc_ili() -> None:
apicall = Epidata.pub_kcdc_ili(
Expand All @@ -190,8 +281,11 @@ def test_pub_kcdc_ili() -> None:
data = apicall.df()
assert len(data) > 0
assert str(data['release_date'].dtype) == 'datetime64[ns]'
assert str(data['region'].dtype) == 'string'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['lag'].dtype) == 'int64'
assert str(data['ili'].dtype) == 'float64'

def test_pvt_meta_norostat() -> None:
apicall = Epidata.pvt_meta_norostat(
Expand All @@ -212,7 +306,9 @@ def test_pub_nidss_dengue() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['count'].dtype) == 'int64'

def test_pub_nidss_flu() -> None:
apicall = Epidata.pub_nidss_flu(
Expand All @@ -222,8 +318,12 @@ def test_pub_nidss_flu() -> None:
data = apicall.df()
assert len(data) > 0
assert str(data['release_date'].dtype) == 'datetime64[ns]'
assert str(data['region'].dtype) == 'string'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['lag'].dtype) == 'int64'
assert str(data['visits'].dtype) == 'int64'
assert str(data['ili'].dtype) == 'float64'

def test_pvt_norostat() -> None:
apicall = Epidata.pvt_norostat(
Expand All @@ -244,7 +344,10 @@ def test_pub_nowcast() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['value'].dtype) == 'float64'
assert str(data['std'].dtype) == 'float64'

def test_pub_paho_dengue() -> None:
apicall = Epidata.pub_paho_dengue(
Expand All @@ -254,8 +357,16 @@ def test_pub_paho_dengue() -> None:
data = apicall.df()
assert len(data) > 0
assert str(data['release_date'].dtype) == 'datetime64[ns]'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['region'].dtype) == 'string'
assert str(data['serotype'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['issue'].dtype) == 'datetime64[ns]'
assert str(data['lag'].dtype) == 'int64'
assert str(data['total_pop'].dtype) == 'int64'
assert str(data['num_dengue'].dtype) == 'int64'
assert str(data['num_severe'].dtype) == 'int64'
assert str(data['num_deaths'].dtype) == 'int64'
assert str(data['incidence_rate'].dtype) == 'float64'

def test_pvt_quidel() -> None:
apicall = Epidata.pvt_quidel(
Expand All @@ -265,7 +376,9 @@ def test_pvt_quidel() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['value'].dtype) == 'float64'

def test_pvt_sensors() -> None:
apicall = Epidata.pvt_sensors(
Expand All @@ -276,7 +389,10 @@ def test_pvt_sensors() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['name'].dtype) == 'string'
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['value'].dtype) == 'float64'

def test_pvt_twitter() -> None:
apicall = Epidata.pvt_twitter(
Expand All @@ -287,7 +403,11 @@ def test_pvt_twitter() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['location'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['num'].dtype) == 'int64'
assert str(data['total'].dtype) == 'int64'
assert str(data['percent'].dtype) == 'float64'

def test_pub_wiki() -> None:
apicall = Epidata.pub_wiki(
Expand All @@ -297,4 +417,9 @@ def test_pub_wiki() -> None:
)
data = apicall.df()
assert len(data) > 0
assert str(data['article'].dtype) == 'string'
assert str(data['epiweek'].dtype) == 'datetime64[ns]'
assert str(data['count'].dtype) == 'int64'
assert str(data['total'].dtype) == 'int64'
assert str(data['hour'].dtype) == 'int64'
assert str(data['value'].dtype) == 'float64'

0 comments on commit 78d3532

Please sign in to comment.