Skip to content

DEPR: deprecated nonkeyword arguments in to_excel #54703

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 4 commits into from
Aug 23, 2023
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Deprecations
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_clipboard`. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_csv` except ``path_or_buf``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_dict`. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_excel` except ``excel_writer``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_gbq` except ``destination_table``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_html` except ``buf``. (:issue:`54229`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,9 @@ def _repr_data_resource_(self):
# I/O Methods

@final
@deprecate_nonkeyword_arguments(
version="3.0", allowed_args=["self", "excel_writer"], name="to_excel"
)
@doc(
klass="object",
storage_options=_shared_docs["storage_options"],
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/excel/test_openpyxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def test_if_sheet_exists_raises(ext, if_sheet_exists, msg):
df = DataFrame({"fruit": ["pear"]})
with tm.ensure_clean(ext) as f:
with pytest.raises(ValueError, match=re.escape(msg)):
df.to_excel(f, "foo", engine="openpyxl")
df.to_excel(f, sheet_name="foo", engine="openpyxl")
with ExcelWriter(
f, engine="openpyxl", mode="a", if_sheet_exists=if_sheet_exists
) as writer:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def test_dtype_backend(self, read_ext, dtype_backend):
}
)
with tm.ensure_clean(read_ext) as file_path:
df.to_excel(file_path, "test", index=False)
df.to_excel(file_path, sheet_name="test", index=False)
result = pd.read_excel(
file_path, sheet_name="test", dtype_backend=dtype_backend
)
Expand Down Expand Up @@ -623,7 +623,7 @@ def test_dtype_backend_and_dtype(self, read_ext):

df = DataFrame({"a": [np.nan, 1.0], "b": [2.5, np.nan]})
with tm.ensure_clean(read_ext) as file_path:
df.to_excel(file_path, "test", index=False)
df.to_excel(file_path, sheet_name="test", index=False)
result = pd.read_excel(
file_path,
sheet_name="test",
Expand All @@ -647,7 +647,7 @@ def test_dtype_backend_string(self, read_ext, string_storage):
}
)
with tm.ensure_clean(read_ext) as file_path:
df.to_excel(file_path, "test", index=False)
df.to_excel(file_path, sheet_name="test", index=False)
result = pd.read_excel(
file_path, sheet_name="test", dtype_backend="numpy_nullable"
)
Expand Down
Loading