forked from fastai/fastai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tabular_data.py
26 lines (21 loc) · 965 Bytes
/
test_tabular_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import pytest
from fastai.tabular import *
from fastai.gen_doc.doctest import this_tests
def test_from_df():
path = Path('data/adult_sample/')
datafile = path/'adult.csv'
assert datafile.exists(), f'We assume test data is in {datafile}'
df = pd.read_csv(datafile,nrows=5)
dep_var = 'salary'
cat_names = ['workclass', 'education', 'marital-status', 'occupation', 'relationship', 'race']
cont_names = ['age', 'fnlwgt', 'education-num']
procs = [FillMissing, Categorify, Normalize]
tablist = TabularList.from_df(df, path=path, cat_names=cat_names, cont_names=cont_names,procs=procs)
this_tests(tablist.from_df)
assert tablist.cat_names == cat_names
assert tablist.cont_names == cont_names
assert tablist.procs == procs
assert (tablist.items == df.index).all()
assert tablist.path == path
# Check correct initialization and `get`; 3rd record without 'NaN'
assert (tablist[3] == df.iloc[3]).all()