Skip to content

Bug46381 - Add storage_option parameter to to_excel method in Styler #46491

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

Merged
merged 33 commits into from
Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fd45ab2
Fixing documentation format in read_csv
eshirvana Feb 7, 2022
098c170
Merge branch 'pandas-dev:main' into main
eshirvana Feb 7, 2022
f2caa9e
Merge branch 'pandas-dev:main' into main
eshirvana Feb 10, 2022
a116612
Merge branch 'pandas-dev:main' into main
eshirvana Feb 11, 2022
b14b82a
Merge branch 'pandas-dev:main' into main
eshirvana Feb 17, 2022
0127564
Merge branch 'pandas-dev:main' into main
eshirvana Feb 20, 2022
9b538db
Merge branch 'pandas-dev:main' into main
eshirvana Feb 22, 2022
ab49b97
Merge branch 'pandas-dev:main' into main
eshirvana Feb 27, 2022
adcc8fe
Merge branch 'pandas-dev:main' into main
eshirvana Feb 27, 2022
92a375e
Merge branch 'pandas-dev:main' into main
eshirvana Feb 27, 2022
13ab03b
Merge branch 'pandas-dev:main' into main
eshirvana Mar 1, 2022
4e805da
Merge branch 'pandas-dev:main' into main
eshirvana Mar 10, 2022
7db3a1d
Merge branch 'pandas-dev:main' into main
eshirvana Mar 15, 2022
8d74df2
Merge branch 'pandas-dev:main' into main
eshirvana Mar 17, 2022
c9118e8
Merge branch 'pandas-dev:main' into main
eshirvana Mar 23, 2022
346eb6a
remove store_option from docstring
eshirvana Mar 24, 2022
f97b904
remove unused refrenced module
eshirvana Mar 24, 2022
eb2000f
add storage_option to the parameters of to_excel
eshirvana Mar 24, 2022
481ed71
Merge branch 'main' into bug4638144642
eshirvana Mar 27, 2022
08237ad
add versionadded 1.5.0 blac hook
eshirvana Mar 29, 2022
c66d3d4
Merge branch 'pandas-dev:main' into bug4638144642
eshirvana Apr 17, 2022
1c2a4e6
add test unit test_styler_to_s3
eshirvana Apr 17, 2022
1397e91
Merge branch 'main' into bug4638144642
eshirvana Apr 18, 2022
27ff3ac
move import;add bug # to the testa
eshirvana Apr 19, 2022
1e66dd5
Merge branch 'pandas-dev:main' into bug4638144642
eshirvana May 25, 2022
bf9446d
add reading excel from s3 to test the whole process
eshirvana May 25, 2022
6e9a212
parameterize the storage options versionadded description in documents
eshirvana Jun 13, 2022
73cb37d
remove self in test test_styler_to_s3
eshirvana Jun 17, 2022
66e0d95
add necessary decorators for the test unit
eshirvana Jun 19, 2022
5888713
fix the import module in test file
eshirvana Jun 19, 2022
18325aa
Merge branch 'main' into bug4638144642
eshirvana Jul 6, 2022
23dd3f3
Merge branch 'pandas-dev:main' into bug4638144642
eshirvana Jul 8, 2022
0768668
Merge branch 'main' into bug4638144642
jreback Jul 8, 2022
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
8 changes: 6 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,11 @@ def _repr_data_resource_(self):
# I/O Methods

@final
@doc(klass="object", storage_options=_shared_docs["storage_options"])
@doc(
klass="object",
storage_options=_shared_docs["storage_options"],
storage_options_versionadded="1.2.0",
)
def to_excel(
self,
excel_writer,
Expand Down Expand Up @@ -2218,7 +2222,7 @@ def to_excel(
is to be frozen.
{storage_options}

.. versionadded:: 1.2.0
.. versionadded:: {storage_options_versionadded}

See Also
--------
Expand Down
4 changes: 4 additions & 0 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Level,
QuantileInterpolation,
Scalar,
StorageOptions,
WriteBuffer,
)
from pandas.compat._optional import import_optional_dependency
Expand Down Expand Up @@ -549,6 +550,7 @@ def set_tooltips(
NDFrame.to_excel,
klass="Styler",
storage_options=_shared_docs["storage_options"],
storage_options_versionadded="1.5.0",
)
def to_excel(
self,
Expand All @@ -568,6 +570,7 @@ def to_excel(
inf_rep: str = "inf",
verbose: bool = True,
freeze_panes: tuple[int, int] | None = None,
storage_options: StorageOptions = None,
) -> None:

from pandas.io.formats.excel import ExcelFormatter
Expand All @@ -590,6 +593,7 @@ def to_excel(
startcol=startcol,
freeze_panes=freeze_panes,
engine=engine,
storage_options=storage_options,
)

@overload
Expand Down
32 changes: 31 additions & 1 deletion pandas/tests/io/excel/test_style.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import contextlib
import time

import numpy as np
import pytest

from pandas import DataFrame
import pandas.util._test_decorators as td

from pandas import (
DataFrame,
read_excel,
)
import pandas._testing as tm

from pandas.io.excel import ExcelWriter
Expand Down Expand Up @@ -206,3 +212,27 @@ def custom_converter(css):

with contextlib.closing(openpyxl.load_workbook(path)) as wb:
assert wb["custom"].cell(2, 2).font.color.value == "00111222"


@pytest.mark.single_cpu
@td.skip_if_not_us_locale
def test_styler_to_s3(s3_resource, s3so):
# GH#46381

mock_bucket_name, target_file = "pandas-test", "test.xlsx"
df = DataFrame({"x": [1, 2, 3], "y": [2, 4, 6]})
styler = df.style.set_sticky(axis="index")
styler.to_excel(f"s3://{mock_bucket_name}/{target_file}", storage_options=s3so)
timeout = 5
while True:
if target_file in (
obj.key for obj in s3_resource.Bucket("pandas-test").objects.all()
):
break
time.sleep(0.1)
timeout -= 0.1
assert timeout > 0, "Timed out waiting for file to appear on moto"
result = read_excel(
f"s3://{mock_bucket_name}/{target_file}", index_col=0, storage_options=s3so
)
tm.assert_frame_equal(result, df)