From 836f39ef9a59373864023a11352882505699cfe1 Mon Sep 17 00:00:00 2001 From: Joel Nothman <joel.nothman@gmail.com> Date: Thu, 20 Apr 2017 08:49:33 +1000 Subject: [PATCH] Revert changes to xlwt --- pandas/io/excel.py | 38 ++--------------------------------- pandas/tests/io/test_excel.py | 9 ++++----- 2 files changed, 6 insertions(+), 41 deletions(-) diff --git a/pandas/io/excel.py b/pandas/io/excel.py index 5129c4db171ae..fbb10ebdfc56d 100644 --- a/pandas/io/excel.py +++ b/pandas/io/excel.py @@ -1468,37 +1468,6 @@ def write_cells(self, cells, sheet_name=None, startrow=0, startcol=0, startcol + cell.col, val, style) - @classmethod - def _tweak_style(cls, item): - item = item.copy() - for k in ['top', 'right', 'bottom', 'left']: - if k not in item: - continue - side = item[k] - if not hasattr(side, 'items'): - continue - color = side.get('color') or side.get('colour') - if color is not None: - item[k + '_color'] = color - if side.get('style'): - item[k] = side['style'] - if 'fill' in item and 'pattern' not in item: - fill = item.pop('fill') - item['pattern'] = {} - for k in ['patternType', 'patterntype', 'fill_type']: - if k in fill: - item['pattern']['pattern'] = fill[k] - break - for k in ['fgColor', 'fgcolor', 'start_color']: - if k in fill: - item['pattern']['fore_color'] = fill[k] - break - for k in ['bgColor', 'bgcolor', 'end_color']: - if k in fill: - item['pattern']['back_color'] = fill[k] - break - return item - @classmethod def _style_to_xlwt(cls, item, firstlevel=True, field_sep=',', line_sep=';'): @@ -1507,19 +1476,16 @@ def _style_to_xlwt(cls, item, firstlevel=True, field_sep=',', hstyle = {"font": {"bold": True}, "border": {"top": "thin", - "right": {"style": "thin", "color": "red"}, + "right": "thin", "bottom": "thin", "left": "thin"}, "align": {"horiz": "center"}} will be converted to font: bold on; \ - border: top thin, right thin, right_color red, \ - bottom thin, left thin; \ + border: top thin, right thin, bottom thin, left thin; \ align: horiz center; """ if hasattr(item, 'items'): - item = cls._tweak_style(item) - if firstlevel: it = ["%s: %s" % (key, cls._style_to_xlwt(value, False)) for key, value in item.items()] diff --git a/pandas/tests/io/test_excel.py b/pandas/tests/io/test_excel.py index 579eba26b0d9c..2e4c6c0618582 100644 --- a/pandas/tests/io/test_excel.py +++ b/pandas/tests/io/test_excel.py @@ -2355,7 +2355,8 @@ def check_called(func): @pytest.mark.parametrize('engine', [ - 'xlwt', + pytest.mark.xfail('xlwt', reason='xlwt does not support ' + 'openpyxl-compatible style dicts'), 'xlsxwriter', 'openpyxl', ]) @@ -2363,14 +2364,12 @@ def test_styler_to_excel(engine): def style(df): # XXX: RGB colors not supported in xlwt return DataFrame([['font-weight: bold', '', ''], - (['', '', ''] if engine == 'xlwt' - else ['', 'color: blue', '']), + ['', 'color: blue', ''], ['', '', 'text-decoration: underline'], ['border-style: solid', '', ''], ['', 'font-style: italic', ''], ['', '', 'text-align: right'], - (['', '', ''] if engine == 'xlwt' - else ['background-color: red', '', '']), + ['background-color: red', '', ''], ['', '', ''], ['', '', ''], ['', '', '']],