Datasets:
Download code/check_local.py from sanvicpatel/protostar-climate-ensemble: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/datasets/sanvicpatel/protostar-climate-ensemble/resolve/main/code/check_local.py
- Command line
-
hf download hf://datasets/sanvicpatel/protostar-climate-ensemble/code/check_local.py
-
curl -L -o check_local.py https://huggingface.co/datasets/sanvicpatel/protostar-climate-ensemble/resolve/main/code/check_local.py
1.14 kB
| """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') | |