示例#1
0
    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"
示例#2
0
    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"
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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
示例#7
0
    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
示例#8
0
    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)
示例#9
0
    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
示例#10
0
    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
示例#11
0
    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
示例#12
0
    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
示例#13
0
    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
示例#14
0
    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
示例#15
0
    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
示例#16
0
    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
示例#17
0
    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)
示例#18
0
    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)
示例#19
0
    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
示例#20
0
    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
示例#21
0
    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
示例#22
0
    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)
示例#23
0
    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
示例#24
0
    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
示例#25
0
    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
示例#26
0
    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
示例#27
0
    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
示例#28
0
    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
示例#29
0
    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)
示例#30
0
    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)
示例#31
0
    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)
示例#32
0
    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)
示例#33
0
    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)
示例#34
0
    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
示例#35
0
    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
示例#36
0
    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
示例#37
0
    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
示例#38
0
    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
示例#39
0
    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
示例#40
0
    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
示例#41
0
    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)
示例#42
0
    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)