Skip to content

Bug: exporting data frames to excel using xlsxwriter with option cons… #22502

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
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ Missing
- Bug in :func:`DataFrame.fillna` where a ``ValueError`` would raise when one column contained a ``datetime64[ns, tz]`` dtype (:issue:`15522`)
- Bug in :func:`Series.hasnans` that could be incorrectly cached and return incorrect answers if null elements are introduced after an initial call (:issue:`19700`)
- :func:`Series.isin` now treats all nans as equal also for `np.object`-dtype. This behavior is consistent with the behavior for float64 (:issue:`22119`)
- Bug in: class:`ExcelWriter` where exporting `DataFrames` to Excel using ``xlsxwriter`` with option `constant_memory` set to True, most of the cells are empty. Now raises ``NotImlementedError``. (:issue:`15392`)

MultiIndex
^^^^^^^^^^
Expand Down
8 changes: 8 additions & 0 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,14 @@ def save(self):
def __init__(self, path, engine=None,
date_format=None, datetime_format=None, mode='w',
**engine_kwargs):

# check for contant_memory option
options = engine_kwargs.get('options', {})
constant_memory = options.get('constant_memory', None)
if constant_memory:
raise NotImplementedError('The option constant_memory=True is '
'not supported.')

# validate that this engine can handle the extension
if isinstance(path, string_types):
ext = os.path.splitext(path)[-1]
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/io/test_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,16 @@ def test_comment_used(self, merge_cells, engine, ext):
result = read_excel(self.path, 'test_c', comment='#')
tm.assert_frame_equal(result, expected)

def test_constant_memory_option_raises_NotImplementedError(self, engine):
# Re issue # 15392
# Test ExcelWriter with constant_memory=True raises NotImplementedError
df = DataFrame({'a': ['1', '2'], 'b': ['2', '3']})
msg = 'The option constant_memory=True is not supported.'
with tm.assert_raises_regex(NotImplementedError, msg):
xlw = pd.ExcelWriter(self.path, engine=engine,
options=dict(constant_memory=True))
df.to_excel(xlw)

def test_comment_emptyline(self, merge_cells, engine, ext):
# Re issue #18735
# Test that read_excel ignores commented lines at the end of file
Expand Down