Exemplo n.º 1
0
    def test_precision(self):
        with pd.option_context('display.precision', 10):
            s = Styler(self.df)
        self.assertEqual(s.precision, 10)
        s = Styler(self.df, precision=2)
        self.assertEqual(s.precision, 2)

        s2 = s.set_precision(4)
        self.assertTrue(s is s2)
        self.assertEqual(s.precision, 4)
Exemplo n.º 2
0
    def test_nonunique_raises(self):
        df = pd.DataFrame([[1, 2]], columns=['A', 'A'])
        with tm.assertRaises(ValueError):
            df.style

        with tm.assertRaises(ValueError):
            Styler(df)
Exemplo n.º 3
0
 def test_render_double(self):
     df = pd.DataFrame({"A": [0, 1]})
     style = lambda x: pd.Series(
         ["color: red; border: 1px", "color: blue; border: 2px"],
         name=x.name)
     s = Styler(df, uuid='AB').apply(style)
     s.render()
Exemplo n.º 4
0
    def test_table_attributes(self):
        attributes = 'class="foo" data-bar'
        styler = Styler(self.df, table_attributes=attributes)
        result = styler.render()
        self.assertTrue('class="foo" data-bar' in result)

        result = self.df.style.set_table_attributes(attributes).render()
        self.assertTrue('class="foo" data-bar' in result)
Exemplo n.º 5
0
    def test_uuid(self):
        styler = Styler(self.df, uuid='abc123')
        result = styler.render()
        self.assertTrue('abc123' in result)

        styler = self.df.style
        result = styler.set_uuid('aaa')
        self.assertTrue(result is styler)
        self.assertEqual(result.uuid, 'aaa')
Exemplo n.º 6
0
    def test_caption(self):
        styler = Styler(self.df, caption='foo')
        result = styler.render()
        self.assertTrue(all(['caption' in result, 'foo' in result]))

        styler = self.df.style
        result = styler.set_caption('baz')
        self.assertTrue(styler is result)
        self.assertEqual(styler.caption, 'baz')
Exemplo n.º 7
0
    def test_table_styles(self):
        style = [{'selector': 'th', 'props': [('foo', 'bar')]}]
        styler = Styler(self.df, table_styles=style)
        result = ' '.join(styler.render().split())
        self.assertTrue('th { foo: bar; }' in result)

        styler = self.df.style
        result = styler.set_table_styles(style)
        self.assertTrue(styler is result)
        self.assertEqual(styler.table_styles, style)
Exemplo n.º 8
0
    def setUp(self):
        np.random.seed(24)
        self.s = DataFrame({'A': np.random.permutation(range(6))})
        self.df = DataFrame({'A': [0, 1], 'B': np.random.randn(2)})
        self.f = lambda x: x
        self.g = lambda x: x

        def h(x, foo='bar'):
            return pd.Series(['color: %s' % foo], index=x.index, name=x.name)

        self.h = h
        self.styler = Styler(self.df)
        self.attrs = pd.DataFrame({'A': ['color: red', 'color: blue']})
        self.dataframes = [
            self.df,
            pd.DataFrame({'f': [1., 2.], 'o': ['a', 'b'],
                          'c': pd.Categorical(['a', 'b'])})
        ]
Exemplo n.º 9
0
 def test_init_series(self):
     result = Styler(pd.Series([1, 2]))
     self.assertEqual(result.data.ndim, 2)
Exemplo n.º 10
0
 def test_init_non_pandas(self):
     with tm.assertRaises(TypeError):
         Styler([1, 2, 3])
 def apply_styling(self, df):
     styler = Styler(df)
     styler = styler.apply(highlight_rsquare, subset=["r_squared"])
     return styler
Exemplo n.º 12
0
 def apply_styling(self, df):
     styler = Styler(df)
     styler = styler.apply(self.rsquareHighlighterService.highlight_rsquare,
                           subset=["r_squared"])
     return styler
Exemplo n.º 13
0
 def test_render(self):
     df = pd.DataFrame({"A": [0, 1]})
     style = lambda x: pd.Series(["color: red", "color: blue"], name=x.name)
     s = Styler(df, uuid='AB').apply(style).apply(style, axis=1)
     s.render()