Пример #1
0
    def _load_sheet(self, sheet):
        sheet_name = sheet['sheet_name']
        default_cell_style = sheet.get('default_styles', {}).get('cells')
        data = defaultdict(list)
        for col in sheet['columns']:
            col_name = col['col_name']
            col_width = col.get('width')
            if col_width:
                self.col_names_to_width[sheet_name][col_name] = col_width
            for cell in col['cells']:
                provided_style = cell.get('style') or col.get(
                    'style') or default_cell_style or {}
                unrecognized_styler_kwargs = set(
                    provided_style.keys()) - styler_kwargs
                if unrecognized_styler_kwargs:
                    raise TypeError(
                        'Styler dict {} contains unexpected argument: {}.\n'
                        'Expected arguments: {}'.format(
                            provided_style, unrecognized_styler_kwargs,
                            styler_kwargs))
                else:
                    data[col_name].append(
                        Container(cell['value'],
                                  Styler(**(provided_style)).create_style()))
        sf = StyleFrame(pd.DataFrame(data=data))

        self._apply_headers_style(sf, sheet)
        self._apply_cols_and_rows_dimensions(sf, sheet)
        sf.to_excel(excel_writer=self.excel_writer,
                    sheet_name=sheet_name,
                    **sheet.get('extra_features', {}))
        setattr(self, '{}_sf'.format(sheet_name), sf)
Пример #2
0
 def setUp(self):
     self.cont_0 = Container(0)
     self.cont_1 = Container(1)
     self.cont_2 = Container(2)
     self.cont_str = Container('a string')
     self.cont_empty_str = Container('')
     self.cont_false = Container(False)
     self.cont_true = Container(True)
Пример #3
0
    def _load_sheet(self, sheet):
        sheet_name = sheet['sheet_name']
        default_cell_style = sheet.get('default_styles', {}).get('cells')
        data = defaultdict(list)
        for col in sheet['columns']:
            col_name = col['col_name']
            col_width = col.get('width')
            if col_width:
                self.col_names_to_width[sheet_name][col_name] = col_width
            for cell in col['cells']:
                data[col_name].append(
                    Container(
                        cell['value'],
                        Styler(
                            **(cell.get('style') or col.get('style')
                               or default_cell_style or {})).create_style()))
        sf = StyleFrame(pd.DataFrame(data=data))

        self._apply_headers_style(sf, sheet)
        self._apply_cols_and_rows_dimensions(sf, sheet)
        sf.to_excel(excel_writer=self.excel_writer,
                    sheet_name=sheet_name,
                    **sheet.get('extra_features', {}))
        setattr(self, '{}_sf'.format(sheet_name), sf)
Пример #4
0
 def setUpClass(cls):
     cls.pandas_series = pd.Series((None, 1))
     cls.sf_series = Series((Container(None), Container(1)))
Пример #5
0
 def test__pow__(self):
     self.assertEqual(self.cont_2**2, Container(4))
Пример #6
0
 def test__mod__(self):
     self.assertEqual(self.cont_2 % self.cont_1, Container(0))
     self.assertEqual(self.cont_2 % 1, Container(0))
Пример #7
0
 def test__div__(self):
     self.assertEqual(self.cont_2 / self.cont_2, self.cont_1)
     self.assertEqual(self.cont_2 / self.cont_1, self.cont_2)
     self.assertEqual(self.cont_2 / 3, Container(2 / 3))
Пример #8
0
 def setUp(self):
     self.cont_1 = Container(1)
     self.cont_2 = Container(2)