Skip to content

Commit c8284ef

Browse files
committed
Update warnings messages.
The positional arguments are now said to become unavailable since version 1.4. Also str.format() method called properly and updated numerous docstrings.
1 parent 6fa0e84 commit c8284ef

File tree

6 files changed

+45
-27
lines changed

6 files changed

+45
-27
lines changed

pandas/io/html.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs):
921921
return ret
922922

923923

924-
@deprecate_nonkeyword_arguments(version="1.1")
924+
@deprecate_nonkeyword_arguments(version="1.4")
925925
def read_html(
926926
io,
927927
match=".+",

pandas/io/json/_json.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def _write(
332332
return serialized
333333

334334

335-
@deprecate_nonkeyword_arguments(version="1.1", allowed_args=['path_or_buf'])
335+
@deprecate_nonkeyword_arguments(version="1.4", allowed_args=["path_or_buf"])
336336
def read_json(
337337
path_or_buf=None,
338338
orient=None,

pandas/tests/io/json/test_deprecated_kwargs.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ def test_deprecated_kwargs():
1515
argument passed as positional.
1616
"""
1717
df = pd.DataFrame({"A": [2, 4, 6], "B": [3, 6, 9]}, index=[0, 1, 2])
18+
buf = df.to_json(orient="split")
1819
with tm.assert_produces_warning(FutureWarning):
19-
assert_frame_equal(df, read_json(df.to_json(orient="split"), "split"))
20+
assert_frame_equal(df, read_json(buf, "split"))
21+
buf = df.to_json(orient="columns")
2022
with tm.assert_produces_warning(FutureWarning):
21-
assert_frame_equal(df, read_json(df.to_json(orient="columns"), "columns"))
23+
assert_frame_equal(df, read_json(buf, "columns"))
24+
buf = df.to_json(orient="index")
2225
with tm.assert_produces_warning(FutureWarning):
23-
assert_frame_equal(df, read_json(df.to_json(orient="index"), "index"))
26+
assert_frame_equal(df, read_json(buf, "index"))
2427

2528

2629
def test_good_kwargs():
@@ -29,6 +32,9 @@ def test_good_kwargs():
2932
argument passed as keyword.
3033
"""
3134
df = pd.DataFrame({"A": [2, 4, 6], "B": [3, 6, 9]}, index=[0, 1, 2])
32-
assert_frame_equal(df, read_json(df.to_json(orient="split"), orient="split"))
33-
assert_frame_equal(df, read_json(df.to_json(orient="columns"), orient="columns"))
34-
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/io/test_html.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ def test_to_html_compat(self):
125125
def test_banklist_url(self):
126126
url = "http://www.fdic.gov/bank/individual/failed/banklist.html"
127127
df1 = self.read_html(
128-
url, "First Federal Bank of Florida", attrs={"id": "table"}
128+
url, match="First Federal Bank of Florida", attrs={"id": "table"}
129129
)
130-
df2 = self.read_html(url, "Metcalf Bank", attrs={"id": "table"})
130+
df2 = self.read_html(url, match="Metcalf Bank", attrs={"id": "table"})
131131

132132
assert_framelist_equal(df1, df2)
133133

@@ -1004,7 +1004,7 @@ def test_wikipedia_states_table(self, datapath):
10041004
data = datapath("io", "data", "wikipedia_states.html")
10051005
assert os.path.isfile(data), "{data!r} is not a file".format(data=data)
10061006
assert os.path.getsize(data), "{data!r} is an empty file".format(data=data)
1007-
result = self.read_html(data, "Arizona", header=1)[0]
1007+
result = self.read_html(data, match="Arizona", header=1)[0]
10081008
assert result["sq mi"].dtype == np.dtype("float64")
10091009

10101010
def test_parser_error_on_empty_header_row(self):

pandas/tests/util/test_deprecate_nonkeyword_arguments.py

+15-9
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():
@@ -71,10 +75,11 @@ def test_four_arguments():
7175
@deprecate_nonkeyword_arguments(version="1.1")
7276
def g(a, b=0, c=0, d=0):
7377
"""
74-
Sum of one to four numbers, the two last arguments
75-
should be given as keyword arguments only
78+
Sum of one to four numbers, but three of them have default
79+
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)