Skip to content

Commit 0345df0

Browse files
committed
deprecate non-keyword args for clip
1 parent b2a36bd commit 0345df0

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

doc/source/whatsnew/v1.3.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ Deprecations
647647
- Deprecated setting :attr:`Categorical._codes`, create a new :class:`Categorical` with the desired codes instead (:issue:`40606`)
648648
- Deprecated behavior of :meth:`DatetimeIndex.union` with mixed timezones; in a future version both will be cast to UTC instead of object dtype (:issue:`39328`)
649649
- Deprecated using ``usecols`` with out of bounds indices for ``read_csv`` with ``engine="c"`` (:issue:`25623`)
650+
- Deprecated passing arguments as positional in :meth:`DataFrame.clip` and :meth:`Series.clip` (:issue:`41485`)
650651

651652
.. ---------------------------------------------------------------------------
652653

pandas/core/generic.py

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
InvalidIndexError,
6262
)
6363
from pandas.util._decorators import (
64+
deprecate_nonkeyword_arguments,
6465
doc,
6566
rewrite_axis_style_signature,
6667
)
@@ -7469,6 +7470,9 @@ def clip(
74697470
) -> FrameOrSeries | None:
74707471
...
74717472

7473+
@deprecate_nonkeyword_arguments(
7474+
version="2.0", allowed_args=["self", "lower", "upper"]
7475+
)
74727476
@final
74737477
def clip(
74747478
self: FrameOrSeries,

pandas/tests/frame/methods/test_clip.py

+10
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,13 @@ def test_clip_with_na_args(self, float_frame):
166166
result = df.clip(lower=t, axis=0)
167167
expected = DataFrame({"col_0": [9, -3, 0, 6, 5], "col_1": [2, -4, 6, 8, 3]})
168168
tm.assert_frame_equal(result, expected)
169+
170+
def test_clip_pos_args_deprecation(self):
171+
# https://github.com/pandas-dev/pandas/issues/41485
172+
df = DataFrame({"a": [1, 2, 3]})
173+
msg = (
174+
r"Starting with Pandas version 2\.0 all arguments of clip except "
175+
r"for the arguments 'self', 'lower' and 'upper' will be keyword-only"
176+
)
177+
with tm.assert_produces_warning(FutureWarning, match=msg):
178+
df.clip(0, 1, 0)

pandas/tests/series/methods/test_clip.py

+10
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,13 @@ def test_clip_with_datetimes(self):
127127
]
128128
)
129129
tm.assert_series_equal(result, expected)
130+
131+
def test_clip_pos_args_deprecation(self):
132+
# https://github.com/pandas-dev/pandas/issues/41485
133+
ser = Series([1, 2, 3])
134+
msg = (
135+
r"Starting with Pandas version 2\.0 all arguments of clip except "
136+
r"for the arguments 'self', 'lower' and 'upper' will be keyword-only"
137+
)
138+
with tm.assert_produces_warning(FutureWarning, match=msg):
139+
ser.clip(0, 1, 0)

0 commit comments

Comments
 (0)