Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ I/O
- Bug in :meth:`~DataFrame.read_feather` was raising an `ArrowIOError` when reading an s3 or http file path (:issue:`29055`)
- Bug in :meth:`read_parquet` was raising a ``FileNotFoundError`` when passed an s3 directory path. (:issue:`26388`)
- Bug in :meth:`~DataFrame.to_parquet` was throwing an ``AttributeError`` when writing a partitioned parquet file to s3 (:issue:`27596`)
- Bug in :meth:`~DataFrame.to_excel` could not handle the column name `render` and was raising an ``KeyError`` (:issue:`34331`)

Plotting
^^^^^^^^
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pandas.core.dtypes.common import is_float, is_scalar
from pandas.core.dtypes.generic import ABCIndex

from pandas import Index, MultiIndex, PeriodIndex
from pandas import DataFrame, Index, MultiIndex, PeriodIndex
import pandas.core.common as com

from pandas.io.common import stringify_path
Expand Down Expand Up @@ -385,7 +385,7 @@ def __init__(
):
self.rowcounter = 0
self.na_rep = na_rep
if hasattr(df, "render"):
if not isinstance(df, DataFrame):
self.styler = df
df = df.data
if style_converter is None:
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/io/excel/test_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ def test_to_excel_with_openpyxl_engine(ext, tmpdir):

assert filename.exists()
os.remove(filename)


def test_to_excel_with_column_render(ext, tmpdir):
# GH 34331
df = DataFrame({"render": [1], "testcolumn": [2]})

filename = tmpdir / "render.xlsx"
df.to_excel(filename, engine="openpyxl")

assert filename.exists()
os.remove(filename)
8 changes: 8 additions & 0 deletions pandas/tests/io/excel/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,14 @@ def test_write_lists_dict(self, path):

tm.assert_frame_equal(read, expected)

def test_render_as_column_name(self, path):
# see gh-34331
df = DataFrame({"render": [1, 2], "data": [3, 4]})
df.to_excel(path, "Sheet1")
read = pd.read_excel(path, "Sheet1", index_col=0)
expected = df
tm.assert_frame_equal(read, expected)

def test_true_and_false_value_options(self, path):
# see gh-13347
df = pd.DataFrame([["foo", "bar"]], columns=["col1", "col2"])
Expand Down