Skip to content

Commit bbe6539

Browse files
committed
ENH: Raise error on trying to write excel file with a MultiIndexed DataFrame. closes #9794
1 parent b3dfc32 commit bbe6539

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

doc/source/whatsnew/v0.16.1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Enhancements
5252

5353
- Allow timedelta string conversion when leading zero is missing from time definition, ie `0:00:00` vs `00:00:00`. (:issue:`9570`)
5454

55+
- Trying to write an excel file now raises error if the DataFrame has a MultiIndex instead of writing a broken Excel file. (:issue:`9794`)
56+
5557
.. _whatsnew_0161.api:
5658

5759
API changes
@@ -132,3 +134,4 @@ Bug Fixes
132134
- Bug in unequal comparisons between a ``Series`` of dtype `"category"` and a scalar (e.g. ``Series(Categorical(list("abc"), categories=list("cba"), ordered=True)) > "b"``, which wouldn't use the order of the categories but use the lexicographical order. (:issue:`9848`)
133135

134136
- Bug in unequal comparisons between categorical data and a scalar, which was not in the categories (e.g. ``Series(Categorical(list("abc"), ordered=True)) > "d"``. This returned ``False`` for all elements, but now raises a ``TypeError``. Equality comparisons also now return ``False`` for ``==`` and ``True`` for ``!=``. (:issue:`9848`)
137+

pandas/core/frame.py

+4
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,10 @@ def to_excel(self, excel_writer, sheet_name='Sheet1', na_rep='',
12441244
>>> writer.save()
12451245
"""
12461246
from pandas.io.excel import ExcelWriter
1247+
print self.index.nlevels
1248+
if self.index.nlevels > 1 or self.columns.nlevels > 1:
1249+
raise NotImplementedError("Writing as Excel with a MultiIndex is "
1250+
"not yet implemented.")
12471251

12481252
need_save = False
12491253
if encoding == None:

0 commit comments

Comments
 (0)