def test_standard_scale(self): df = self.df_norm.copy() df = (df - df.min()) / (df.max() - df.min()) kws = self.default_kws.copy() kws['standard_scale'] = 1 cg = mat.ClusterGrid(self.df_norm, **kws) pdt.assert_frame_equal(cg.data2d, df)
def test_z_score(self): df = self.df_norm.copy() df = (df - df.mean()) / df.std() kws = self.default_kws.copy() kws['z_score'] = 1 cg = mat.ClusterGrid(self.df_norm, **kws) pdt.assert_frame_equal(cg.data2d, df)
def test_colors_input(self): kws = self.default_kws.copy() kws['row_colors'] = self.row_colors kws['col_colors'] = self.col_colors cg = mat.ClusterGrid(self.df_norm, **kws) npt.assert_array_equal(cg.row_colors, self.row_colors) npt.assert_array_equal(cg.col_colors, self.col_colors) assert len(cg.fig.axes) == 6
def test_required_scipy_errors(): x = np.random.normal(0, 1, (10, 10)) with pytest.raises(RuntimeError): mat.clustermap(x) with pytest.raises(RuntimeError): mat.ClusterGrid(x) with pytest.raises(RuntimeError): mat.dendrogram(x)
def test_nested_colors_input(self): kws = self.default_kws.copy() row_colors = [self.row_colors, self.row_colors] col_colors = [self.col_colors, self.col_colors] kws['row_colors'] = row_colors kws['col_colors'] = col_colors cm = mat.ClusterGrid(self.df_norm, **kws) npt.assert_array_equal(cm.row_colors, row_colors) npt.assert_array_equal(cm.col_colors, col_colors) assert len(cm.fig.axes) == 6
def test_pivot_input(self): df_norm = self.df_norm.copy() df_norm.index.name = 'numbers' df_long = pd.melt(df_norm.reset_index(), var_name='letters', id_vars='numbers') kws = self.default_kws.copy() kws['pivot_kws'] = dict(index='numbers', columns='letters', values='value') cg = mat.ClusterGrid(df_long, **kws) pdt.assert_frame_equal(cg.data2d, df_norm)
def test_categorical_colors_input(self): kws = self.default_kws.copy() row_colors = pd.Series(self.row_colors, dtype="category") col_colors = pd.Series(self.col_colors, dtype="category", index=self.df_norm.columns) kws['row_colors'] = row_colors kws['col_colors'] = col_colors exp_row_colors = list(map(mpl.colors.to_rgb, row_colors)) exp_col_colors = list(map(mpl.colors.to_rgb, col_colors)) cg = mat.ClusterGrid(self.df_norm, **kws) npt.assert_array_equal(cg.row_colors, exp_row_colors) npt.assert_array_equal(cg.col_colors, exp_col_colors) assert len(cg.fig.axes) == 6
def test_savefig(self): # Not sure if this is the right way to test.... cg = mat.ClusterGrid(self.df_norm, **self.default_kws) cg.plot(**self.default_plot_kws) cg.savefig(tempfile.NamedTemporaryFile(), format='png')
def test_z_score_standard_scale(self): kws = self.default_kws.copy() kws['z_score'] = True kws['standard_scale'] = True with pytest.raises(ValueError): mat.ClusterGrid(self.df_norm, **kws)
def test_corr_df_input(self): df = self.df_norm.corr() cg = mat.ClusterGrid(df, **self.default_kws) cg.plot(**self.default_plot_kws) diag = cg.data2d.values[np.diag_indices_from(cg.data2d)] npt.assert_array_almost_equal(diag, np.ones(cg.data2d.shape[0]))
def test_df_input(self): cg = mat.ClusterGrid(self.df_norm, **self.default_kws) pdt.assert_frame_equal(cg.data, self.df_norm)
def test_ndarray_input(self): cg = mat.ClusterGrid(self.x_norm, **self.default_kws) pdt.assert_frame_equal(cg.data, pd.DataFrame(self.x_norm)) assert len(cg.fig.axes) == 4 assert cg.ax_row_colors is None assert cg.ax_col_colors is None