Skip to content

Updated Dataframe.to_excel and Dataframe.to_latex #179

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 2 commits into from
Aug 4, 2022
Merged
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
70 changes: 0 additions & 70 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1986,25 +1986,6 @@ class DataFrame(NDFrame, OpsMixin):
errors: _str = ...,
storage_options: dict[_str, Any] | None = ...,
) -> _str: ...
def to_excel(
self,
excel_writer,
sheet_name: _str = ...,
na_rep: _str = ...,
float_format: _str | None = ...,
columns: _str | Sequence[_str] | None = ...,
header: _bool = ...,
index: _bool = ...,
index_label: _str | Sequence[_str] | None = ...,
startrow: int = ...,
startcol: int = ...,
engine: _str | None = ...,
merge_cells: _bool = ...,
encoding: _str | None = ...,
inf_rep: _str = ...,
verbose: _bool = ...,
freeze_panes: tuple[int, int] | None = ...,
) -> None: ...
def to_hdf(
self,
path_or_buf: FilePathOrBuffer,
Expand Down Expand Up @@ -2057,57 +2038,6 @@ class DataFrame(NDFrame, OpsMixin):
index: _bool = ...,
indent: int | None = ...,
) -> _str: ...
@overload
def to_latex(
self,
buf: FilePathOrBuffer | None,
columns: list[_str] | None = ...,
col_space: int | None = ...,
header: _bool = ...,
index: _bool = ...,
na_rep: _str = ...,
formatters=...,
float_format=...,
sparsify: _bool | None = ...,
index_names: _bool = ...,
bold_rows: _bool = ...,
column_format: _str | None = ...,
longtable: _bool | None = ...,
escape: _bool | None = ...,
encoding: _str | None = ...,
decimal: _str = ...,
multicolumn: _bool | None = ...,
multicolumn_format: _str | None = ...,
multirow: _bool | None = ...,
caption: _str | tuple[_str, _str] | None = ...,
label: _str | None = ...,
position: _str | None = ...,
) -> None: ...
@overload
def to_latex(
self,
columns: list[_str] | None = ...,
col_space: int | None = ...,
header: _bool = ...,
index: _bool = ...,
na_rep: _str = ...,
formatters=...,
float_format=...,
sparsify: _bool | None = ...,
index_names: _bool = ...,
bold_rows: _bool = ...,
column_format: _str | None = ...,
longtable: _bool | None = ...,
escape: _bool | None = ...,
encoding: _str | None = ...,
decimal: _str = ...,
multicolumn: _bool | None = ...,
multicolumn_format: _str | None = ...,
multirow: _bool | None = ...,
caption: _str | tuple[_str, _str] | None = ...,
label: _str | None = ...,
position: _str | None = ...,
) -> _str: ...
def to_pickle(
self,
path: _str,
Expand Down
6 changes: 3 additions & 3 deletions pandas-stubs/core/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
na_rep: _str = ...,
float_format: _str | None = ...,
columns: _str | Sequence[_str] | None = ...,
header: _bool = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
index_label: _str | Sequence[_str] | None = ...,
startrow: int = ...,
Expand Down Expand Up @@ -175,7 +175,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
buf: FilePathOrBuffer | None,
columns: list[_str] | None = ...,
col_space: int | None = ...,
header: _bool = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
na_rep: _str = ...,
formatters=...,
Expand All @@ -200,7 +200,7 @@ class NDFrame(PandasObject, indexing.IndexingMixin):
self,
columns: list[_str] | None = ...,
col_space: int | None = ...,
header: _bool = ...,
header: _bool | list[_str] = ...,
index: _bool = ...,
na_rep: _str = ...,
formatters=...,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ matplotlib = ">=3.3.2"
pre-commit = ">=2.19.0"
black = ">=22.6.0"
isort = ">=5.10.1"
openpyxl = ">=3.0.10"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
29 changes: 29 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,35 @@ def test_frame_getitem_isin() -> None:
check(assert_type(df[df.index.isin([1, 3, 5])], pd.DataFrame), pd.DataFrame)


def test_to_excel() -> None:
df = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]})

with tempfile.NamedTemporaryFile(delete=False) as file:
df.to_excel(file.name, engine="openpyxl")
file.close()
df2: pd.DataFrame = pd.read_excel(file.name)
with tempfile.NamedTemporaryFile(delete=False) as file:
df.to_excel(Path(file.name), engine="openpyxl")
file.close()
df3: pd.DataFrame = pd.read_excel(file.name)
with tempfile.NamedTemporaryFile(delete=False) as file:
df.to_excel(file.name, engine="openpyxl", startrow=1, startcol=1, header=False)
file.close()
df4: pd.DataFrame = pd.read_excel(file.name)
with tempfile.NamedTemporaryFile(delete=False) as file:
df.to_excel(file.name, engine="openpyxl", sheet_name="sheet", index=False)
file.close()
df5: pd.DataFrame = pd.read_excel(file.name)
with tempfile.NamedTemporaryFile(delete=False) as file:
df.to_excel(file.name, engine="openpyxl", header=["x", "y"])
file.close()
df6: pd.DataFrame = pd.read_excel(file.name)
with tempfile.NamedTemporaryFile(delete=False) as file:
df.to_excel(file.name, engine="openpyxl", columns=["col1"])
file.close()
df7: pd.DataFrame = pd.read_excel(file.name)


def test_read_excel() -> None:
if TYPE_CHECKING: # skip pytest

Expand Down