Skip to content

Commit

Permalink
DEPR: deprecated nonkeyword arguments in to_excel (#54703)
Browse files Browse the repository at this point in the history
* deprecated nonkeyword arguments

* moved test

* fixed tests
  • Loading branch information
rsm-23 authored Aug 23, 2023
1 parent 43a3f0e commit 867cae3
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 81 deletions.
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

0 comments on commit 867cae3

Please sign in to comment.