Skip to content

Upstream Style.copy constructor regression breaks _Openpyxl2Writer #9747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
neirbowj opened this issue Mar 29, 2015 · 1 comment
Closed

Upstream Style.copy constructor regression breaks _Openpyxl2Writer #9747

neirbowj opened this issue Mar 29, 2015 · 1 comment
Labels
Compat pandas objects compatability with Numpy or Python functions IO Excel read_excel, to_excel
Milestone

Comments

@neirbowj
Copy link
Contributor

Starting with openpyxl 2.2.0, various tests in pandas.io.tests.test_excel fail with tracebacks similar to this one.

======================================================================
ERROR: test_basics_with_nan (pandas.io.tests.test_excel.Openpyxl2Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pandas/io/tests/test_excel.py", line 1229, in wrapped
    orig_method(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pandas/io/tests/test_excel.py", line 641, in test_basics_with_nan
    self.frame.to_excel(path, 'test1')
  File "/usr/local/lib/python2.7/site-packages/pandas/core/frame.py", line 1267, in to_excel
    startrow=startrow, startcol=startcol)
  File "/usr/local/lib/python2.7/site-packages/pandas/io/excel.py", line 778, in write_cells
    xcell.style = xcell.style.copy(**style_kwargs)
  File "/usr/local/lib/python2.7/site-packages/openpyxl/styles/styleable.py", line 107, in style
    protection=self.protection
  File "/usr/local/lib/python2.7/site-packages/openpyxl/styles/__init__.py", line 42, in __init__
    self._font = font
  File "/usr/local/lib/python2.7/site-packages/openpyxl/descriptors/base.py", line 35, in __set__
    raise TypeError('expected ' + str(self.expected_type))
TypeError: expected <class 'openpyxl.styles.fonts.Font'>

pandas.io.excel._Openpyxl2Writer.write_cells uses openpyxl.styles.Style.copy to merge newly specified style data with style data on existing cells. Sadly, the obvious workaround—iterate over the fields of the Style object and use them to build an updated Style object—won't work either without additional coddling, because the fields don't reliably return the native object that the Style constructor demands.

>>> from openpyxl.styles import Style
>>> s0 = Style()
>>> s1 = Style(fill=s0.fill)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/obrienjw/venv/py27-openpyxl220/lib/python2.7/site-packages/openpyxl-2.2.0-py2.7.egg/openpyxl/styles/__init__.py", line 43, in __init__
    self._fill = fill
  File "/Users/obrienjw/venv/py27-openpyxl220/lib/python2.7/site-packages/openpyxl-2.2.0-py2.7.egg/openpyxl/descriptors/base.py", line 35, in __set__
    raise TypeError('expected ' + str(self.expected_type))
TypeError: expected <class 'openpyxl.styles.fills.Fill'>

(See upstream issue: 444 copy() method on Style object raises TypeError)

@jreback
Copy link
Contributor

jreback commented Sep 11, 2015

replaced by #10125

@jreback jreback closed this as completed Sep 11, 2015
@jreback jreback added IO Excel read_excel, to_excel Compat pandas objects compatability with Numpy or Python functions labels Sep 11, 2015
@jreback jreback added this to the 0.17.0 milestone Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

2 participants