-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
150 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
doctor_visits/tests/comparison/write_csv/20200204_state_smoothed_cli.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
geo_id,val,se,direction,sample_size | ||
ak,0.569287,NA,NA,NA | ||
al,0.328228,NA,NA,NA | ||
ar,0.370763,NA,NA,NA | ||
az,0.530073,NA,NA,NA | ||
ca,0.351530,NA,NA,NA | ||
co,0.401868,NA,NA,NA | ||
ct,0.601417,NA,NA,NA | ||
dc,0.878253,NA,NA,NA | ||
de,0.324467,NA,NA,NA | ||
fl,0.479217,NA,NA,NA | ||
ga,0.475930,NA,NA,NA | ||
hi,0.393773,NA,NA,NA | ||
ia,0.481491,NA,NA,NA | ||
id,0.445713,NA,NA,NA | ||
il,0.380958,NA,NA,NA | ||
in,0.357658,NA,NA,NA | ||
ks,0.365005,NA,NA,NA | ||
ky,0.368104,NA,NA,NA | ||
la,0.405224,NA,NA,NA | ||
ma,0.347109,NA,NA,NA | ||
md,0.478480,NA,NA,NA | ||
me,0.292373,NA,NA,NA | ||
mi,0.432469,NA,NA,NA | ||
mn,0.436532,NA,NA,NA | ||
mo,0.354799,NA,NA,NA | ||
ms,0.385404,NA,NA,NA | ||
mt,0.363729,NA,NA,NA | ||
nc,0.502467,NA,NA,NA | ||
nd,0.384162,NA,NA,NA | ||
ne,0.504449,NA,NA,NA | ||
nh,0.406304,NA,NA,NA | ||
nj,0.350642,NA,NA,NA | ||
nm,0.336862,NA,NA,NA | ||
nv,0.590539,NA,NA,NA | ||
ny,0.369274,NA,NA,NA | ||
oh,0.402905,NA,NA,NA | ||
ok,0.339027,NA,NA,NA | ||
or,0.421793,NA,NA,NA | ||
pa,0.342980,NA,NA,NA | ||
ri,0.353920,NA,NA,NA | ||
sc,0.321687,NA,NA,NA | ||
sd,0.508804,NA,NA,NA | ||
tn,0.454150,NA,NA,NA | ||
tx,0.358389,NA,NA,NA | ||
ut,0.488488,NA,NA,NA | ||
va,0.371326,NA,NA,NA | ||
vt,0.307760,NA,NA,NA | ||
wa,0.440772,NA,NA,NA | ||
wi,0.373994,NA,NA,NA | ||
wv,0.317498,NA,NA,NA | ||
wy,0.346961,NA,NA,NA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,60 @@ | ||
"""Tests for update_sensor.py.""" | ||
from datetime import datetime | ||
import logging | ||
import os | ||
from pathlib import Path | ||
import pandas as pd | ||
|
||
from delphi_doctor_visits.process_data import csv_to_df | ||
from delphi_doctor_visits.process_data import csv_to_df, write_to_csv, format_outname | ||
|
||
TEST_LOGGER = logging.getLogger() | ||
|
||
class TestProcessData: | ||
geo = "state", | ||
startdate = datetime(2020, 2, 4) | ||
enddate = datetime(2020, 2, 5) | ||
dropdate = datetime(2020, 2,6) | ||
geo = "state" | ||
se = False | ||
weekday = False | ||
prefix = "wip_XXXXX" | ||
filepath = "./test_data" | ||
compare_path = "./comparison" | ||
|
||
def test_csv_to_df(self): | ||
actual = csv_to_df( | ||
filepath="./test_data/SYNEDI_AGG_OUTPATIENT_07022020_1455CDT.csv.gz", | ||
startdate=datetime(2020, 2, 4), | ||
enddate=datetime(2020, 2, 5), | ||
dropdate=datetime(2020, 2,6), | ||
filepath=f"{self.filepath}/SYNEDI_AGG_OUTPATIENT_07022020_1455CDT.csv.gz", | ||
startdate=self.startdate, | ||
enddate=self.enddate, | ||
dropdate=self.dropdate, | ||
logger=TEST_LOGGER, | ||
) | ||
|
||
comparison = pd.read_pickle("./comparison/process_data/main_after_date_SYNEDI_AGG_OUTPATIENT_07022020_1455CDT.pkl") | ||
comparison = pd.read_pickle(f"{self.compare_path}/process_data/main_after_date_SYNEDI_AGG_OUTPATIENT_07022020_1455CDT.pkl") | ||
pd.testing.assert_frame_equal(actual.reset_index(drop=True), comparison) | ||
|
||
|
||
def test_write_to_csv(self): | ||
output_df = pd.read_csv(f"{self.compare_path}/update_sensor/all.csv", parse_dates=["date"]) | ||
|
||
write_to_csv( | ||
output_df=output_df, | ||
prefix=self.prefix, | ||
geo_id=self.geo, | ||
se=self.se, | ||
weekday=self.weekday, | ||
logger=TEST_LOGGER, | ||
output_path=self.filepath | ||
) | ||
|
||
outname = format_outname(self.prefix, self.se, self.weekday) | ||
|
||
files = list(Path(self.filepath).glob(f"*{outname}.csv")) | ||
|
||
for f in files: | ||
filename = f.name | ||
actual = pd.read_csv(f) | ||
comparison = pd.read_csv(f"{self.compare_path}/write_csv/{filename}") | ||
pd.testing.assert_frame_equal(actual, comparison) | ||
os.remove(f) | ||
|