-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_combined_evaluation_result.py
62 lines (52 loc) · 1.47 KB
/
test_combined_evaluation_result.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pandas as pd
import numpy as np
from nose.tools import assert_equal
from numpy.testing import assert_almost_equal
from combine_evaluation_results import combine
def test_combine():
columns = [1, 2]
index = ['a', 'b']
def make_data(multiplier):
return pd.DataFrame(np.ones((2, 2)) * multiplier,
columns=columns,
index=index
)
r1 = {'m1': make_data(2),
'm2': make_data(0)}
r2 = {'m1': make_data(1),
'm2': make_data(2)}
r = combine([r1, r2])
assert_equal(['m1', 'm2'], r.keys())
assert_almost_equal(
np.ones((2, 2)) * 1.5,
r['m1'].as_matrix()
)
assert_almost_equal(
np.ones((2, 2)) * 1.,
r['m2'].as_matrix()
)
def test_combine_with_nan():
columns = [1, 2]
index = ['a', 'b']
def make_data(multiplier):
return pd.DataFrame(np.ones((2, 2)) * multiplier,
columns=columns,
index=index
)
d = make_data(2)
d[2]['a'] = np.nan
r1 = {'m1': d,
'm2': make_data(0)}
r2 = {'m1': make_data(1),
'm2': make_data(2)}
r = combine([r1, r2])
assert_equal(['m1', 'm2'], r.keys())
assert_almost_equal(
np.asarray([[1.5, 1], [1.5, 1.5]]),
# np.ones((2, 2)) * 1.5,
r['m1'].as_matrix()
)
assert_almost_equal(
np.ones((2, 2)) * 1.,
r['m2'].as_matrix()
)