Skip to content

Commit 867cae3

Browse files
authored
DEPR: deprecated nonkeyword arguments in to_excel (#54703)
* deprecated nonkeyword arguments * moved test * fixed tests
1 parent 43a3f0e commit 867cae3

File tree

5 files changed

+103
-81
lines changed

5 files changed

+103
-81
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Deprecations
134134
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_clipboard`. (:issue:`54229`)
135135
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_csv` except ``path_or_buf``. (:issue:`54229`)
136136
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_dict`. (:issue:`54229`)
137+
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_excel` except ``excel_writer``. (:issue:`54229`)
137138
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_gbq` except ``destination_table``. (:issue:`54229`)
138139
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_hdf` except ``path_or_buf``. (:issue:`54229`)
139140
- Deprecated allowing non-keyword arguments in :meth:`DataFrame.to_html` except ``buf``. (:issue:`54229`)

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,9 @@ def _repr_data_resource_(self):
21872187
# I/O Methods
21882188

21892189
@final
2190+
@deprecate_nonkeyword_arguments(
2191+
version="3.0", allowed_args=["self", "excel_writer"], name="to_excel"
2192+
)
21902193
@doc(
21912194
klass="object",
21922195
storage_options=_shared_docs["storage_options"],

pandas/tests/io/excel/test_openpyxl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def test_if_sheet_exists_raises(ext, if_sheet_exists, msg):
241241
df = DataFrame({"fruit": ["pear"]})
242242
with tm.ensure_clean(ext) as f:
243243
with pytest.raises(ValueError, match=re.escape(msg)):
244-
df.to_excel(f, "foo", engine="openpyxl")
244+
df.to_excel(f, sheet_name="foo", engine="openpyxl")
245245
with ExcelWriter(
246246
f, engine="openpyxl", mode="a", if_sheet_exists=if_sheet_exists
247247
) as writer:

pandas/tests/io/excel/test_readers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def test_dtype_backend(self, read_ext, dtype_backend):
591591
}
592592
)
593593
with tm.ensure_clean(read_ext) as file_path:
594-
df.to_excel(file_path, "test", index=False)
594+
df.to_excel(file_path, sheet_name="test", index=False)
595595
result = pd.read_excel(
596596
file_path, sheet_name="test", dtype_backend=dtype_backend
597597
)
@@ -623,7 +623,7 @@ def test_dtype_backend_and_dtype(self, read_ext):
623623

624624
df = DataFrame({"a": [np.nan, 1.0], "b": [2.5, np.nan]})
625625
with tm.ensure_clean(read_ext) as file_path:
626-
df.to_excel(file_path, "test", index=False)
626+
df.to_excel(file_path, sheet_name="test", index=False)
627627
result = pd.read_excel(
628628
file_path,
629629
sheet_name="test",
@@ -647,7 +647,7 @@ def test_dtype_backend_string(self, read_ext, string_storage):
647647
}
648648
)
649649
with tm.ensure_clean(read_ext) as file_path:
650-
df.to_excel(file_path, "test", index=False)
650+
df.to_excel(file_path, sheet_name="test", index=False)
651651
result = pd.read_excel(
652652
file_path, sheet_name="test", dtype_backend="numpy_nullable"
653653
)

0 commit comments

Comments
 (0)