|
1
|
|
|
import numpy as np |
|
2
|
|
|
import pandas as pd |
|
3
|
|
|
import unittest |
|
4
|
|
|
from ..describe import corr_mat |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class Test_corr_mat(unittest.TestCase): |
|
8
|
|
|
|
|
9
|
|
|
@classmethod |
|
10
|
|
|
def setUpClass(cls): |
|
11
|
|
|
cls.data_corr_df = pd.DataFrame([[1, 0, 3, 4, 'a'], |
|
12
|
|
|
[3, 4, 5, 6, 'b'], |
|
13
|
|
|
[5, 4, 2, 1, 'c']], |
|
14
|
|
|
columns=['Col1', 'Col2', 'Col3', 'Col4', 'Col5']) |
|
15
|
|
|
|
|
16
|
|
|
cls.data_corr_list = [1, 2, -3, 4, 5] |
|
17
|
|
|
cls.data_corr_target_series = pd.Series([1, 2, -3, 4, 5], name='Target Series') |
|
18
|
|
|
cls.data_corr_target_array = np.array([1, 2, -3, 4, 5]) |
|
19
|
|
|
cls.data_corr_target_list = [1, 2, -3, 4, 5] |
|
20
|
|
|
|
|
21
|
|
|
def test_output_type(self): |
|
22
|
|
|
# Test conversion from pd.io.formats.style.Styler to pd.core.frame.DataFrame |
|
23
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df)), type(pd.io.formats.style.Styler)) |
|
24
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_list)), type(pd.io.formats.style.Styler)) |
|
25
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df, target='Col1')), type(pd.io.formats.style.Styler)) |
|
26
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df, target=self.data_corr_target_series)), |
|
27
|
|
|
type(pd.io.formats.style.Styler)) |
|
28
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df, target=self.data_corr_target_array)), |
|
29
|
|
|
type(pd.io.formats.style.Styler)) |
|
30
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df, target=self.data_corr_target_list)), |
|
31
|
|
|
type(pd.io.formats.style.Styler)) |
|
32
|
|
|
|
|
33
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df, colored=False)), type(pd.DataFrame)) |
|
34
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_list, colored=False)), type(pd.DataFrame)) |
|
35
|
|
|
self.assertIsInstance(type(corr_mat(self.data_corr_df, target='Col1', colored=False)), type(pd.DataFrame)) |
|
36
|
|
|
self.assertIsInstance( |
|
37
|
|
|
type(corr_mat(self.data_corr_df, target=self.data_corr_target_series, colored=False)), type(pd.DataFrame)) |
|
38
|
|
|
self.assertIsInstance( |
|
39
|
|
|
type(corr_mat(self.data_corr_df, target=self.data_corr_target_array, colored=False)), type(pd.DataFrame)) |
|
40
|
|
|
self.assertIsInstance( |
|
41
|
|
|
type(corr_mat(self.data_corr_df, target=self.data_corr_target_list, colored=False)), type(pd.DataFrame)) |
|
42
|
|
|
|
|
43
|
|
|
def test_output_shape(self): |
|
44
|
|
|
# Test for output dimensions |
|
45
|
|
|
self.assertEqual(corr_mat(self.data_corr_df).data.shape[0], corr_mat(self.data_corr_df).data.shape[1]) |
|
46
|
|
|
self.assertEqual(corr_mat(self.data_corr_list).data.shape[0], corr_mat(self.data_corr_list).data.shape[1]) |
|
47
|
|
|
self.assertEqual(corr_mat(self.data_corr_df, target='Col1', colored=False).shape, (3, 1)) |
|
48
|
|
|
self.assertEqual(corr_mat(self.data_corr_df, target=self.data_corr_target_series, colored=False).shape, (4, 1)) |
|
49
|
|
|
self.assertEqual(corr_mat(self.data_corr_df, target=self.data_corr_target_array, colored=False).shape, (4, 1)) |
|
50
|
|
|
self.assertEqual(corr_mat(self.data_corr_df, target=self.data_corr_target_list, colored=False).shape, (4, 1)) |
|
51
|
|
|
|