1
|
|
|
import unittest |
2
|
|
|
|
3
|
|
|
import numpy as np |
4
|
|
|
import pandas as pd |
5
|
|
|
|
6
|
|
|
from klib.describe import corr_mat |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
class Test_corr_mat(unittest.TestCase): |
10
|
|
|
@classmethod |
11
|
|
|
def setUpClass(cls): |
12
|
|
|
cls.data_corr_df = pd.DataFrame( |
13
|
|
|
[[1, 0, 3, 4, "a"], [3, 4, 5, 6, "b"], [5, 4, 2, 1, "c"]], |
14
|
|
|
columns=["Col1", "Col2", "Col3", "Col4", "Col5"], |
15
|
|
|
) |
16
|
|
|
|
17
|
|
|
cls.data_corr_list = [1, 2, -3, 4, 5] |
18
|
|
|
cls.data_corr_target_series = pd.Series([1, 2, -3, 4, 5], name="Target Series") |
19
|
|
|
cls.data_corr_target_array = np.array([1, 2, -3, 4, 5]) |
20
|
|
|
cls.data_corr_target_list = [1, 2, -3, 4, 5] |
21
|
|
|
|
22
|
|
|
def test_output_type(self): |
23
|
|
|
# Test conversion from pd.io.formats.style.Styler to pd.core.frame.DataFrame |
24
|
|
|
self.assertIsInstance( |
25
|
|
|
type(corr_mat(self.data_corr_df)), type(pd.io.formats.style.Styler) |
26
|
|
|
) |
27
|
|
|
self.assertIsInstance( |
28
|
|
|
type(corr_mat(self.data_corr_list)), type(pd.io.formats.style.Styler) |
29
|
|
|
) |
30
|
|
|
self.assertIsInstance( |
31
|
|
|
type(corr_mat(self.data_corr_df, target="Col1")), |
32
|
|
|
type(pd.io.formats.style.Styler), |
33
|
|
|
) |
34
|
|
|
self.assertIsInstance( |
35
|
|
|
type(corr_mat(self.data_corr_df, target=self.data_corr_target_series)), |
36
|
|
|
type(pd.io.formats.style.Styler), |
37
|
|
|
) |
38
|
|
|
self.assertIsInstance( |
39
|
|
|
type(corr_mat(self.data_corr_df, target=self.data_corr_target_array)), |
40
|
|
|
type(pd.io.formats.style.Styler), |
41
|
|
|
) |
42
|
|
|
self.assertIsInstance( |
43
|
|
|
type(corr_mat(self.data_corr_df, target=self.data_corr_target_list)), |
44
|
|
|
type(pd.io.formats.style.Styler), |
45
|
|
|
) |
46
|
|
|
|
47
|
|
|
self.assertIsInstance( |
48
|
|
|
type(corr_mat(self.data_corr_df, colored=False)), type(pd.DataFrame) |
49
|
|
|
) |
50
|
|
|
self.assertIsInstance( |
51
|
|
|
type(corr_mat(self.data_corr_list, colored=False)), type(pd.DataFrame) |
52
|
|
|
) |
53
|
|
|
self.assertIsInstance( |
54
|
|
|
type(corr_mat(self.data_corr_df, target="Col1", colored=False)), |
55
|
|
|
type(pd.DataFrame), |
56
|
|
|
) |
57
|
|
|
self.assertIsInstance( |
58
|
|
|
type( |
59
|
|
|
corr_mat( |
60
|
|
|
self.data_corr_df, |
61
|
|
|
target=self.data_corr_target_series, |
62
|
|
|
colored=False, |
63
|
|
|
) |
64
|
|
|
), |
65
|
|
|
type(pd.DataFrame), |
66
|
|
|
) |
67
|
|
|
self.assertIsInstance( |
68
|
|
|
type( |
69
|
|
|
corr_mat( |
70
|
|
|
self.data_corr_df, target=self.data_corr_target_array, colored=False |
71
|
|
|
) |
72
|
|
|
), |
73
|
|
|
type(pd.DataFrame), |
74
|
|
|
) |
75
|
|
|
self.assertIsInstance( |
76
|
|
|
type( |
77
|
|
|
corr_mat( |
78
|
|
|
self.data_corr_df, target=self.data_corr_target_list, colored=False |
79
|
|
|
) |
80
|
|
|
), |
81
|
|
|
type(pd.DataFrame), |
82
|
|
|
) |
83
|
|
|
|
84
|
|
|
def test_output_shape(self): |
85
|
|
|
# Test for output dimensions |
86
|
|
|
self.assertEqual( |
87
|
|
|
corr_mat(self.data_corr_df).data.shape[0], |
88
|
|
|
corr_mat(self.data_corr_df).data.shape[1], |
89
|
|
|
) |
90
|
|
|
self.assertEqual( |
91
|
|
|
corr_mat(self.data_corr_list).data.shape[0], |
92
|
|
|
corr_mat(self.data_corr_list).data.shape[1], |
93
|
|
|
) |
94
|
|
|
self.assertEqual( |
95
|
|
|
corr_mat(self.data_corr_df, target="Col1", colored=False).shape, (3, 1) |
96
|
|
|
) |
97
|
|
|
self.assertEqual( |
98
|
|
|
corr_mat( |
99
|
|
|
self.data_corr_df, target=self.data_corr_target_series, colored=False |
100
|
|
|
).shape, |
101
|
|
|
(4, 1), |
102
|
|
|
) |
103
|
|
|
self.assertEqual( |
104
|
|
|
corr_mat( |
105
|
|
|
self.data_corr_df, target=self.data_corr_target_array, colored=False |
106
|
|
|
).shape, |
107
|
|
|
(4, 1), |
108
|
|
|
) |
109
|
|
|
self.assertEqual( |
110
|
|
|
corr_mat( |
111
|
|
|
self.data_corr_df, target=self.data_corr_target_list, colored=False |
112
|
|
|
).shape, |
113
|
|
|
(4, 1), |
114
|
|
|
) |
115
|
|
|
|