diff --git a/pandas/formats/format.py b/pandas/formats/format.py index 34e59b2977319..c16f1ce4f49ac 100644 --- a/pandas/formats/format.py +++ b/pandas/formats/format.py @@ -1826,7 +1826,7 @@ def __call__(self, declarations_str, inherited=None): if val is None: # we do not define a complete initial stylesheet - del props[val] + del props[prop] else: props[prop] = val @@ -1984,7 +1984,8 @@ class CSSToExcelConverter(object): def __init__(self, inherited=None): if inherited is not None: - inherited = self.compute_css(inherited, sefl.INITIAL_STYLE) + inherited = self.compute_css(inherited, + self.compute_css.INITIAL_STYLE) self.inherited = inherited diff --git a/pandas/tests/formats/test_to_excel.py b/pandas/tests/formats/test_to_excel.py index de24e62f2d2a1..99a4ed6259ddd 100644 --- a/pandas/tests/formats/test_to_excel.py +++ b/pandas/tests/formats/test_to_excel.py @@ -176,3 +176,21 @@ def test_css_font_size_invalid(): def test_css_to_excel(css, expected): convert = CSSToExcelConverter() assert expected == convert(css) + + +@pytest.mark.parametrize('css,inherited,expected', [ + ('font-weight: bold', '', + {'font': {'bold': True}}), + ('', 'font-weight: bold', + {'font': {'bold': True}}), + ('font-weight: bold', 'font-style: italic', + {'font': {'bold': True, 'italic': True}}), + ('font-style: normal', 'font-style: italic', + {'font': {'italic': False}}), + ('font-style: inherit', '', {}), + ('font-style: normal; font-style: inherit', 'font-style: italic', + {'font': {'italic': True}}), +]) +def test_css_to_excel_inherited(css, inherited, expected): + convert = CSSToExcelConverter(inherited) + assert expected == convert(css)