Skip to content

Commit 62c0fb8

Browse files
authored
DEPR: enforce non-positional, keyword deprecations (#49507)
1 parent cd38fa3 commit 62c0fb8

File tree

8 files changed

+12
-74
lines changed

8 files changed

+12
-74
lines changed

doc/source/whatsnew/v2.0.0.rst

+4
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ Removal of prior version deprecations/changes
295295
- Removed ``keep_tz`` argument in :meth:`DatetimeIndex.to_series` (:issue:`29731`)
296296
- Remove arguments ``names`` and ``dtype`` from :meth:`Index.copy` and ``levels`` and ``codes`` from :meth:`MultiIndex.copy` (:issue:`35853`, :issue:`36685`)
297297
- Remove argument ``inplace`` from :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`35626`)
298+
- Removed arguments ``verbose`` and ``encoding`` from :meth:`DataFrame.to_excel` and :meth:`Series.to_excel` (:issue:`47912`)
299+
- Removed argument ``line_terminator`` from :meth:`DataFrame.to_csv` and :meth:`Series.to_csv`, use ``lineterminator`` instead (:issue:`45302`)
298300
- Removed argument ``inplace`` from :meth:`DataFrame.set_axis` and :meth:`Series.set_axis`, use ``obj = obj.set_axis(..., copy=False)`` instead (:issue:`48130`)
299301
- Disallow passing positional arguments to :meth:`MultiIndex.set_levels` and :meth:`MultiIndex.set_codes` (:issue:`41485`)
300302
- Removed :meth:`MultiIndex.is_lexsorted` and :meth:`MultiIndex.lexsort_depth` (:issue:`38701`)
@@ -312,6 +314,8 @@ Removal of prior version deprecations/changes
312314
- Remove keywords ``convert_float`` and ``mangle_dupe_cols`` from :func:`read_excel` (:issue:`41176`)
313315
- Removed ``errors`` keyword from :meth:`DataFrame.where`, :meth:`Series.where`, :meth:`DataFrame.mask` and :meth:`Series.mask` (:issue:`47728`)
314316
- Disallow passing non-keyword arguments to :func:`read_excel` except ``io`` and ``sheet_name`` (:issue:`34418`)
317+
- Disallow passing non-keyword arguments to :meth:`DataFrame.drop` and :meth:`Series.drop` except ``labels`` (:issue:`41486`)
318+
- Disallow passing non-keyword arguments to :meth:`DataFrame.fillna` and :meth:`Series.fillna` except ``value`` (:issue:`41485`)
315319
- Disallow passing non-keyword arguments to :meth:`StringMethods.split` and :meth:`StringMethods.rsplit` except for ``pat`` (:issue:`47448`)
316320
- Disallow passing non-keyword arguments to :meth:`DataFrame.set_index` except ``keys`` (:issue:`41495`)
317321
- Disallow passing non-keyword arguments to :meth:`Resampler.interpolate` except ``method`` (:issue:`41699`)

pandas/core/frame.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -5156,12 +5156,10 @@ def drop(
51565156
) -> DataFrame | None:
51575157
...
51585158

5159-
# error: Signature of "drop" incompatible with supertype "NDFrame"
5160-
# github.com/python/mypy/issues/12387
5161-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
5162-
def drop( # type: ignore[override]
5159+
def drop(
51635160
self,
51645161
labels: IndexLabel = None,
5162+
*,
51655163
axis: Axis = 0,
51665164
index: IndexLabel = None,
51675165
columns: IndexLabel = None,
@@ -5531,11 +5529,11 @@ def fillna(
55315529
...
55325530

55335531
# error: Signature of "fillna" incompatible with supertype "NDFrame"
5534-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"])
55355532
@doc(NDFrame.fillna, **_shared_doc_kwargs)
55365533
def fillna( # type: ignore[override]
55375534
self,
55385535
value: Hashable | Mapping | Series | DataFrame = None,
5536+
*,
55395537
method: FillnaOptions | None = None,
55405538
axis: Axis | None = None,
55415539
inplace: bool = False,

pandas/core/generic.py

+1-23
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@
8686
SettingWithCopyWarning,
8787
)
8888
from pandas.util._decorators import (
89-
deprecate_kwarg,
90-
deprecate_nonkeyword_arguments,
9189
doc,
9290
rewrite_axis_style_signature,
9391
)
@@ -2130,8 +2128,6 @@ def _repr_data_resource_(self):
21302128
# I/O Methods
21312129

21322130
@final
2133-
@deprecate_kwarg(old_arg_name="verbose", new_arg_name=None)
2134-
@deprecate_kwarg(old_arg_name="encoding", new_arg_name=None)
21352131
@doc(
21362132
klass="object",
21372133
storage_options=_shared_docs["storage_options"],
@@ -2151,9 +2147,7 @@ def to_excel(
21512147
startcol: int = 0,
21522148
engine: str | None = None,
21532149
merge_cells: bool_t = True,
2154-
encoding: lib.NoDefault = lib.no_default,
21552150
inf_rep: str = "inf",
2156-
verbose: lib.NoDefault = lib.no_default,
21572151
freeze_panes: tuple[int, int] | None = None,
21582152
storage_options: StorageOptions = None,
21592153
) -> None:
@@ -2203,24 +2197,9 @@ def to_excel(
22032197
22042198
merge_cells : bool, default True
22052199
Write MultiIndex and Hierarchical Rows as merged cells.
2206-
encoding : str, optional
2207-
Encoding of the resulting excel file. Only necessary for xlwt,
2208-
other writers support unicode natively.
2209-
2210-
.. deprecated:: 1.5.0
2211-
2212-
This keyword was not used.
2213-
22142200
inf_rep : str, default 'inf'
22152201
Representation for infinity (there is no native representation for
22162202
infinity in Excel).
2217-
verbose : bool, default True
2218-
Display more information in the error logs.
2219-
2220-
.. deprecated:: 1.5.0
2221-
2222-
This keyword was not used.
2223-
22242203
freeze_panes : tuple of int (length 2), optional
22252204
Specifies the one-based bottommost row and rightmost column that
22262205
is to be frozen.
@@ -3469,7 +3448,6 @@ def to_csv(
34693448
storage_options=_shared_docs["storage_options"],
34703449
compression_options=_shared_docs["compression_options"] % "path_or_buf",
34713450
)
3472-
@deprecate_kwarg(old_arg_name="line_terminator", new_arg_name="lineterminator")
34733451
def to_csv(
34743452
self,
34753453
path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str] | None = None,
@@ -4394,10 +4372,10 @@ def drop(
43944372
) -> NDFrameT | None:
43954373
...
43964374

4397-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
43984375
def drop(
43994376
self: NDFrameT,
44004377
labels: IndexLabel = None,
4378+
*,
44014379
axis: Axis = 0,
44024380
index: IndexLabel = None,
44034381
columns: IndexLabel = None,

pandas/core/series.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
from pandas.util._decorators import (
6868
Appender,
6969
Substitution,
70-
deprecate_nonkeyword_arguments,
7170
doc,
7271
)
7372
from pandas.util._exceptions import find_stack_level
@@ -5021,12 +5020,10 @@ def drop(
50215020
) -> Series | None:
50225021
...
50235022

5024-
# error: Signature of "drop" incompatible with supertype "NDFrame"
5025-
# github.com/python/mypy/issues/12387
5026-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
5027-
def drop( # type: ignore[override]
5023+
def drop(
50285024
self,
50295025
labels: IndexLabel = None,
5026+
*,
50305027
axis: Axis = 0,
50315028
index: IndexLabel = None,
50325029
columns: IndexLabel = None,
@@ -5170,11 +5167,11 @@ def fillna(
51705167
...
51715168

51725169
# error: Signature of "fillna" incompatible with supertype "NDFrame"
5173-
@deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "value"])
51745170
@doc(NDFrame.fillna, **_shared_doc_kwargs)
51755171
def fillna( # type: ignore[override]
51765172
self,
51775173
value: Hashable | Mapping | Series | DataFrame = None,
5174+
*,
51785175
method: FillnaOptions | None = None,
51795176
axis: Axis | None = None,
51805177
inplace: bool = False,

pandas/tests/frame/methods/test_fillna.py

-12
Original file line numberDiff line numberDiff line change
@@ -611,18 +611,6 @@ def test_fillna_downcast_dict(self):
611611
expected = DataFrame({"col1": [1, 2]})
612612
tm.assert_frame_equal(result, expected)
613613

614-
def test_fillna_pos_args_deprecation(self):
615-
# https://github.com/pandas-dev/pandas/issues/41485
616-
df = DataFrame({"a": [1, 2, 3, np.nan]}, dtype=float)
617-
msg = (
618-
r"In a future version of pandas all arguments of DataFrame.fillna "
619-
r"except for the argument 'value' will be keyword-only"
620-
)
621-
with tm.assert_produces_warning(FutureWarning, match=msg):
622-
result = df.fillna(0, None, None)
623-
expected = DataFrame({"a": [1, 2, 3, 0]}, dtype=float)
624-
tm.assert_frame_equal(result, expected)
625-
626614
def test_fillna_with_columns_and_limit(self):
627615
# GH40989
628616
df = DataFrame(

pandas/tests/io/formats/test_to_csv.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,7 @@ def test_to_csv_single_level_multi_index(self, ind, expected, frame_or_series):
388388
# see gh-19589
389389
obj = frame_or_series(pd.Series([1], ind, name="data"))
390390

391-
with tm.assert_produces_warning(FutureWarning, match="lineterminator"):
392-
# GH#9568 standardize on lineterminator matching stdlib
393-
result = obj.to_csv(line_terminator="\n", header=True)
391+
result = obj.to_csv(lineterminator="\n", header=True)
394392
assert result == expected
395393

396394
def test_to_csv_string_array_ascii(self):

pandas/tests/series/methods/test_drop.py

-13
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,6 @@ def test_drop_non_empty_list(data, index, drop_labels):
9090
ser.drop(drop_labels)
9191

9292

93-
def test_drop_pos_args_deprecation():
94-
# https://github.com/pandas-dev/pandas/issues/41485
95-
ser = Series([1, 2, 3])
96-
msg = (
97-
r"In a future version of pandas all arguments of Series\.drop "
98-
r"except for the argument 'labels' will be keyword-only"
99-
)
100-
with tm.assert_produces_warning(FutureWarning, match=msg):
101-
result = ser.drop(1, 0)
102-
expected = Series([1, 3], index=[0, 2])
103-
tm.assert_series_equal(result, expected)
104-
105-
10693
def test_drop_index_ea_dtype(any_numeric_ea_dtype):
10794
# GH#45860
10895
df = Series(100, index=Index([1, 2, 2], dtype=any_numeric_ea_dtype))

pandas/tests/series/methods/test_fillna.py

-12
Original file line numberDiff line numberDiff line change
@@ -828,18 +828,6 @@ def test_fillna_datetime64_with_timezone_tzinfo(self):
828828
)
829829
tm.assert_series_equal(result, expected)
830830

831-
def test_fillna_pos_args_deprecation(self):
832-
# https://github.com/pandas-dev/pandas/issues/41485
833-
srs = Series([1, 2, 3, np.nan], dtype=float)
834-
msg = (
835-
r"In a future version of pandas all arguments of Series.fillna "
836-
r"except for the argument 'value' will be keyword-only"
837-
)
838-
with tm.assert_produces_warning(FutureWarning, match=msg):
839-
result = srs.fillna(0, None, None)
840-
expected = Series([1, 2, 3, 0], dtype=float)
841-
tm.assert_series_equal(result, expected)
842-
843831
@pytest.mark.parametrize(
844832
"input, input_fillna, expected_data, expected_categories",
845833
[

0 commit comments

Comments
 (0)