Datasets:
File size: 1,143 Bytes
993d9a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | """Check official submission format and keys without network access."""
import sys
import numpy as np
import pandas as pd
from inputs import DATA, METRICS, LAST, parquet
def check(path):
d=pd.read_csv(path,dtype={'city_id':str,'metric':str})
if list(d)!=['city_id','year','metric','predicted_value']:
raise ValueError('Submission columns do not match the template')
d.year=pd.to_numeric(d.year,errors='raise')
values=pd.to_numeric(d.predicted_value,errors='raise')
cities=parquet('city_info',['ID','Stn.stDate','Stn.edDate'],date_cols=['Stn.stDate','Stn.edDate'])
ids=set(cities.ID)
years=set(range(LAST+1,LAST+8))
expect={(i,y,m) for i in ids for y in years for m in METRICS}
got=set(d[['city_id','year','metric']].itertuples(index=False,name=None))
if len(d)!=len(expect) or got!=expect or not np.isfinite(values).all():
raise ValueError('Submission has a missing, duplicate, unexpected key or non-finite value')
print(f'OK: {path} has all {len(expect):,} unique forecasts and finite values.')
if __name__=='__main__':check(sys.argv[1] if len(sys.argv)>1 else 'submission.csv')
|