Download cog/tests/test_predict.py from lee101/mojo-tabular: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/lee101/mojo-tabular/resolve/main/cog/tests/test_predict.py
- Command line
-
hf download hf://lee101/mojo-tabular/cog/tests/test_predict.py
-
curl -L -o test_predict.py https://huggingface.co/lee101/mojo-tabular/resolve/main/cog/tests/test_predict.py
1.24 kB
| import json, sys, unittest | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| import pandas as pd | |
| from predict import Predictor | |
| DATA = Path('/nvme0n1-disk/cache/foundry/tabular') | |
| class T(unittest.TestCase): | |
| def setUpClass(cls): | |
| cls.p = Predictor() | |
| cls.p.setup() | |
| def test_all_models(self): | |
| for name, target in [('adult', 'class'), ('credit-g', 'class'), ('bank-marketing', 'Class'), | |
| ('phoneme', 'Class'), ('diabetes', 'class')]: | |
| f = DATA / f'{name}.parquet' | |
| if not f.exists(): | |
| self.skipTest('dataset cache absent') | |
| df = pd.read_parquet(f).drop(columns=[target]).head(5) | |
| rows = df.astype(object).where(df.notna(), None).to_json(orient='records') | |
| out = json.loads(self.p.predict(name, rows)) | |
| self.assertEqual(len(out), 5) | |
| self.assertTrue(all(0 <= x <= 1 for x in out)) | |
| def test_errors(self): | |
| with self.assertRaises(ValueError): | |
| self.p.predict('nope', '[]') | |
| with self.assertRaises(ValueError): | |
| self.p.predict('adult', '[{"age": 1}]') | |
| if __name__ == '__main__': | |
| unittest.main() | |