Skip to content

Commit cd84833

Browse files
committed
Call str.format function in better way and update documentation string
1 parent 61e51eb commit cd84833

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

pandas/tests/io/json/test_deprecated_kwargs.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def test_good_kwargs():
3232
argument passed as keyword.
3333
"""
3434
df = pd.DataFrame({"A": [2, 4, 6], "B": [3, 6, 9]}, index=[0, 1, 2])
35-
assert_frame_equal(df, read_json(df.to_json(orient="split"), orient="split"))
36-
assert_frame_equal(df, read_json(df.to_json(orient="columns"), orient="columns"))
37-
assert_frame_equal(df, read_json(df.to_json(orient="index"), orient="index"))
35+
with tm.assert_produces_warning(None):
36+
assert_frame_equal(df, read_json(df.to_json(orient="split"), orient="split"))
37+
assert_frame_equal(
38+
df, read_json(df.to_json(orient="columns"), orient="columns")
39+
)
40+
assert_frame_equal(df, read_json(df.to_json(orient="index"), orient="index"))

pandas/tests/util/test_deprecate_nonkeyword_arguments.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ def f(a, b=0, c=0, d=0):
1616
return a + b + c + d
1717

1818

19-
def test_one_arguments():
19+
def test_one_argument():
2020
"""
2121
Check whether no future warning is produced if one
2222
positional argument given.
2323
"""
24-
assert f(19) == 19
24+
with tm.assert_produces_warning(None):
25+
assert f(19) == 19
2526

2627

2728
def test_one_and_one_arguments():
@@ -30,15 +31,17 @@ def test_one_and_one_arguments():
3031
positional argument and one keyword argument are
3132
given.
3233
"""
33-
assert f(19, d=6) == 25
34+
with tm.assert_produces_warning(None):
35+
assert f(19, d=6) == 25
3436

3537

3638
def test_two_arguments():
3739
"""
3840
Check whether no future warning is produced if two
3941
positional arguments given.
4042
"""
41-
assert f(1, 5) == 6
43+
with tm.assert_produces_warning(None):
44+
assert f(1, 5) == 6
4245

4346

4447
def test_two_and_two_arguments():
@@ -47,7 +50,8 @@ def test_two_and_two_arguments():
4750
positional arguments and two keyword arguments are
4851
given.
4952
"""
50-
assert f(1, 3, c=3, d=5) == 12
53+
with tm.assert_produces_warning(None):
54+
assert f(1, 3, c=3, d=5) == 12
5155

5256

5357
def test_three_arguments():
@@ -74,7 +78,8 @@ def g(a, b=0, c=0, d=0):
7478
Sum of one to four numbers, but three of them have default
7579
values, so may be given as keyword arguments only.
7680
"""
77-
return a + b + c + d
81+
with tm.assert_produces_warning(None):
82+
return a + b + c + d
7883

7984

8085
def test_one_and_three_arguments_default_allowed_args():
@@ -85,7 +90,8 @@ def test_one_and_three_arguments_default_allowed_args():
8590
option, meaning that all arguments with default value
8691
are keyword-only.
8792
"""
88-
assert g(1, b=3, c=3, d=5) == 12
93+
with tm.assert_produces_warning(None):
94+
assert g(1, b=3, c=3, d=5) == 12
8995

9096

9197
def test_three_arguments_default_allowed_args():

pandas/util/_decorators.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def deprecate_nonkeyword_arguments(
224224
The version in which positional arguments will become
225225
keyword-only.
226226
227-
allowed_args : list, int or None, default=None
227+
allowed_args : list or int, optional
228228
In case of list, it must be the list of names of some
229229
first arguments of the decorated functions that are
230230
OK to be given as positional arguments. In case of an
@@ -248,14 +248,20 @@ def decorate(func):
248248
def wrapper(*args, **kwargs):
249249
if isinstance(allow_args, int) and len(args) > allow_args:
250250
msg = (
251-
"After version %s all arguments of %s "
252-
"except for the first %i will be keyword-only"
253-
) % (version, func.__name__, allow_args)
251+
"After Pandas version {version} all arguments of {funcname} "
252+
"except for the first {num_args} will be keyword-only"
253+
).format(version=version, funcname=func.__name__, num_args=allow_args)
254254
elif isinstance(allow_args, (list, tuple)) and len(args) > len(allow_args):
255255
msg = (
256-
"After version %s all arguments of %s "
257-
"except for (%s) will be keyword-only"
258-
) % (version, func.__name__, ", ".join(allow_args))
256+
"After Pandas version {version} all arguments of {funcname} "
257+
"except for {first_args} will be keyword-only"
258+
).format(
259+
version=version,
260+
funcname=func.__name__,
261+
first_args="(" + ", ".join(allow_args) + ")"
262+
if len(allow_args) > 1
263+
else allow_args[0],
264+
)
259265
else:
260266
msg = None
261267
if msg:

0 commit comments

Comments
 (0)