def test_establish_variables_dataframe_named_axes(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) pdt.assert_frame_equal(p.high_dimensional_data, self.data) assert p.sample_label == 'Samples' assert p.feature_label == "Features"
def test__maybe_make_grouper_single_groupby(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) test_grouper = p._maybe_make_grouper('o', None, str) true_grouper = pd.Series(['o']*self.matrix.shape[0], index=self.data.index) pdt.assert_series_equal(test_grouper, true_grouper)
def test__maybe_make_grouper_single_groupby(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) test_grouper = p._maybe_make_grouper('o', None, str) true_grouper = pd.Series(['o'] * self.matrix.shape[0], index=self.data.index) pdt.assert_series_equal(test_grouper, true_grouper)
def test_establish_colors_hue_order(self): # Option 2. hue_order is specified but nothing else is from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['hue_order'] = self.order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws)
def test_establish_colors_all_none(self): # Option 1. All parameters are set to default values from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**self.color_kws) assert p.n_colors == 1 assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def test_establish_variables_matrix(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.matrix) assert isinstance(p.high_dimensional_data, pd.DataFrame) pdt.assert_frame_equal(p.high_dimensional_data, pd.DataFrame(self.matrix)) assert p.sample_label is None assert p.feature_label is None
def test_establish_reducer_use_existing(self): from cupcake.smush.base import SmushPlotterBase pca_kws = {} n_components = 2 reducer = PCA(n_components=n_components, **pca_kws) p = SmushPlotterBase() p.establish_reducer(reducer) assert isinstance(p.reducer, type(reducer)) pdt.assert_dict_equal(p.reducer.get_params(), reducer.get_params())
def test_establish_colors_hue(self): # Option 3. "hue" is specified but nothing else is from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['hue'] = self.groupby p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == 2 assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def establish_colors_palette(self): # Option 5. "palette" is specified but nothing else is from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['palette'] = self.palette p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == self.nrow assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def establish_colors_color(self): # Option 9. "color" is specified from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['color'] = self.color p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == 1 assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def establish_colors_color_palette(self, hue, hue_order): # Option 13-16. "color", and "palette" are specified but incompatible from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['color'] = self.color color_kws['palette'] = self.palette color_kws['hue'] = hue color_kws['hue_order'] = hue_order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws)
def test_establish_symbols_defaults(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**self.symbol_kws) pdt.assert_series_equal(p.symbol, pd.Series(['o']*self.nrow, index=self.data.index)) pdt.assert_series_equal(p.linewidth, pd.Series([1]*self.nrow, index=self.data.index)) pdt.assert_series_equal(p.edgecolor, pd.Series(['k']*self.nrow, index=self.data.index)) assert not p.text
def test_establish_symbols_text_true(self): from cupcake.smush.base import SmushPlotterBase symbol_kws = self.symbol_kws.copy() symbol_kws['text'] = True p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**symbol_kws) pdt.assert_series_equal(p.symbol, pd.Series(map(str, list(range(self.nrow))), index=self.data.index)) assert p.text
def establish_colors_palette_hue(self): # Option 7. "palette" and "hue" are specified from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['palette'] = self.palette color_kws['hue'] = self.groupby p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == 2 assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def test__maybe_make_grouper_multiple_groupbys(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) half = int(self.nrow/2.) groupby = pd.Series((['B'] * half) + (['A'] * half)) order = ['A', 'B'] test_grouper = p._maybe_make_grouper(groupby, order, str) true_grouper = pd.Series(pd.Categorical(groupby, categories=order, ordered=True), index=self.data.index) pdt.assert_series_equal(test_grouper, true_grouper)
def test_establish_symbols_text_series_ordered(self): from cupcake.smush.base import SmushPlotterBase symbol_kws = self.symbol_kws.copy() symbol_kws['text'] = self.groupby symbol_kws['text_order'] = self.order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**symbol_kws) symbol = pd.Series(pd.Categorical(self.groupby, ordered=True, categories=self.order), index=self.data.index) pdt.assert_series_equal(p.symbol, symbol) assert p.text
def establish_colors_color_hue_hue_order(self): # Option 12. "color", "hue", and "hue_order" are specified from cupcake.smush.base import SmushPlotterBase color_kws = self.color_kws.copy() color_kws['color'] = self.color color_kws['hue'] = self.groupby color_kws['hue_order'] = self.order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == 2 assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def establish_colors_palette_hue_order_incorrect_length(self): # Option 6b. "palette" and "hue_order" are specified, but hue_order # isn't correct length from cupcake.smush.base import SmushPlotterBase # Reverse the index order hue_order = self.data.index[::-1] hue_order = hue_order[:self.half] color_kws = self.color_kws.copy() color_kws['palette'] = self.palette color_kws['hue_order'] = hue_order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws)
def establish_colors_color_hue_order_incorrect_length(self): # Option 10. "color" and "hue_order" are specified, but "hue_order" is # the incorrect length from cupcake.smush.base import SmushPlotterBase # Reverse the index so hue_order is different from original order hue_order = self.data.index[::-1] hue_order = hue_order[:self.half] color_kws = self.color_kws.copy() color_kws['color'] = self.color color_kws['hue_order'] = hue_order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws)
def test__maybe_make_grouper_multiple_groupbys(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) half = int(self.nrow / 2.) groupby = pd.Series((['B'] * half) + (['A'] * half)) order = ['A', 'B'] test_grouper = p._maybe_make_grouper(groupby, order, str) true_grouper = pd.Series(pd.Categorical(groupby, categories=order, ordered=True), index=self.data.index) pdt.assert_series_equal(test_grouper, true_grouper)
def test_establish_symbols_text_series_not_str(self): from cupcake.smush.base import SmushPlotterBase half = int(self.nrow/2.) text = pd.Series(([1] * half) + ([2] * half)).map(str) symbol_kws = self.symbol_kws.copy() symbol_kws['text'] = text p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**symbol_kws) symbol = pd.Series(pd.Categorical(text, ordered=True, categories=['1', '2']), index=self.data.index) pdt.assert_series_equal(p.symbol, symbol) assert p.text
def establish_colors_palette_hue_order(self): # Option 6a. "palette" and "hue_order" are specified from cupcake.smush.base import SmushPlotterBase # Reverse the index order hue_order = self.data.index[::-1] color_kws = self.color_kws.copy() color_kws['palette'] = self.palette color_kws['hue_order'] = hue_order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == self.nrow assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def establish_colors_color_hue_order(self): # Option 10. "color" and "hue_order" are specified from cupcake.smush.base import SmushPlotterBase # Reverse the index so hue_order is different from original order hue_order = self.data.index[::-1] color_kws = self.color_kws.copy() color_kws['color'] = self.color color_kws['hue_order'] = hue_order p = SmushPlotterBase() p.establish_variables(self.data) p.establish_colors(**color_kws) assert p.n_colors == self.nrow assert len(p.high_dimensional_data.groupby(p.color)) == p.n_colors
def test_establish_symbols_text_true(self): from cupcake.smush.base import SmushPlotterBase symbol_kws = self.symbol_kws.copy() symbol_kws['text'] = True p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**symbol_kws) pdt.assert_series_equal( p.symbol, pd.Series(map(str, list(range(self.nrow))), index=self.data.index)) assert p.text
def test_establish_symbols_defaults(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**self.symbol_kws) pdt.assert_series_equal( p.symbol, pd.Series(['o'] * self.nrow, index=self.data.index)) pdt.assert_series_equal( p.linewidth, pd.Series([1] * self.nrow, index=self.data.index)) pdt.assert_series_equal( p.edgecolor, pd.Series(['k'] * self.nrow, index=self.data.index)) assert not p.text
def test_establish_symbols_text_series_not_str(self): from cupcake.smush.base import SmushPlotterBase half = int(self.nrow / 2.) text = pd.Series(([1] * half) + ([2] * half)).map(str) symbol_kws = self.symbol_kws.copy() symbol_kws['text'] = text p = SmushPlotterBase() p.establish_variables(self.data) p.establish_symbols(**symbol_kws) symbol = pd.Series(pd.Categorical(text, ordered=True, categories=['1', '2']), index=self.data.index) pdt.assert_series_equal(p.symbol, symbol) assert p.text
def test_establish_variables_too_many_axes(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() matrix = self.vector.reshape((1, self.nrow, self.ncol)) p.establish_variables(matrix)
def test_establish_variables_too_few_axes(self): from cupcake.smush.base import SmushPlotterBase p = SmushPlotterBase() matrix = self.vector.reshape(1, self.nrow * self.ncol) p.establish_variables(matrix)