Skip to content

ExcelWriter fails with columns with int32 dtype #3122

Closed
@lbeltrame

Description

@lbeltrame

Test case

In [21]: df = pandas.DataFrame({"foo": [1,2,3]})

In [22]: df["foo"] = df["foo"].astype("int32")

In [23]: df.to_excel("foo.xls")
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-23-a8d956752923> in <module>()
----> 1 df.to_excel("foo.xls")

/usr/lib64/python2.7/site-packages/pandas-0.11.0.dev_4e0465d-py2.7-linux-x86_64.egg/pandas/core/frame.pyc in to_excel(self, excel_writer, sheet_name, na_rep, float_format, cols, header, index, index_label, startrow, startcol)
   1406         formatted_cells = formatter.get_formatted_cells()
   1407         excel_writer.write_cells(formatted_cells, sheet_name,
-> 1408                                  startrow=startrow, startcol=startcol)
   1409         if need_save:
   1410             excel_writer.save()

/usr/lib64/python2.7/site-packages/pandas-0.11.0.dev_4e0465d-py2.7-linux-x86_64.egg/pandas/io/parsers.pyc in write_cells(self, cells, sheet_name, startrow, startcol)
   2194             self._writecells_xlsx(cells, sheet_name, startrow, startcol)
   2195         else:
-> 2196             self._writecells_xls(cells, sheet_name, startrow, startcol)
   2197
   2198     def _writecells_xlsx(self, cells, sheet_name, startrow, startcol):

/usr/lib64/python2.7/site-packages/pandas-0.11.0.dev_4e0465d-py2.7-linux-x86_64.egg/pandas/io/parsers.pyc in _writecells_xls(self, cells, sheet_name, startrow, startcol)
   2270                 wks.write(startrow + cell.row,
   2271                           startcol + cell.col,
-> 2272                           val, style)

/usr/lib/python2.7/site-packages/xlwt/Worksheet.pyc in write(self, r, c, label, style)
   1030
   1031     def write(self, r, c, label="", style=Style.default_style):
-> 1032         self.row(r).write(c, label, style)
   1033
   1034     def write_rich_text(self, r, c, rich_text_list, style=Style.default_style):

/usr/lib/python2.7/site-packages/xlwt/Row.pyc in write(self, col, label, style)
    257             self.__rich_text_helper(col, label, style, style_index)
    258         else:
--> 259             raise Exception("Unexpected data type %r" % type(label))
    260
    261     def set_cell_rich_text(self, col, rich_text_list, style=Style.default_style):

Exception: Unexpected data type <type 'numpy.int32'>

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIO DataIO issues that don't fit into a more specific labelIO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions