Skip to content

Commit aca165c

Browse files
committed
Fix a flake8 warnings and reformat the code.
1 parent afc10ea commit aca165c

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

pandas/tests/io/json/test_deprecated_kwargs.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
Tests for the deprecated keyword arguments for `read_json`.
33
"""
44

5-
import pytest
6-
75
import pandas as pd
6+
7+
from pandas.io.json import read_json
8+
89
import pandas.util.testing as tm
910

1011
from pandas.util.testing import assert_frame_equal
@@ -15,31 +16,21 @@ def test_deprecated_kwargs():
1516
Check whether FutureWarning is produced if `orient`
1617
argument passed as positional.
1718
"""
18-
df = pd.DataFrame({'A': [2, 4, 6],
19-
'B': [3, 6, 9]},
20-
index=[0, 1, 2])
19+
df = pd.DataFrame({"A": [2, 4, 6], "B": [3, 6, 9]}, index=[0, 1, 2])
2120
with tm.assert_produces_warning(FutureWarning):
22-
assert_frame_equal(df,
23-
read_json(df.to_json(orient="split"), "split"))
21+
assert_frame_equal(df, read_json(df.to_json(orient="split"), "split"))
2422
with tm.assert_produces_warning(FutureWarning):
25-
assert_frame_equal(df,
26-
read_json(df.to_json(orient="columns"), "columns"))
23+
assert_frame_equal(df, read_json(df.to_json(orient="columns"), "columns"))
2724
with tm.assert_produces_warning(FutureWarning):
28-
assert_frame_equal(df,
29-
read_json(df.to_json(orient="index"), "index"))
25+
assert_frame_equal(df, read_json(df.to_json(orient="index"), "index"))
3026

3127

3228
def test_good_kwargs():
3329
"""
3430
Check whether FutureWarning is not produced if `orient`
3531
argument passed as keyword.
3632
"""
37-
df = pd.DataFrame({'A': [2, 4, 6],
38-
'B': [3, 6, 9]},
39-
index=[0, 1, 2])
40-
assert_frame_equal(df,
41-
read_json(df.to_json(orient="split"), "split"))
42-
assert_frame_equal(df,
43-
read_json(df.to_json(orient="columns"), "columns"))
44-
assert_frame_equal(df,
45-
read_json(df.to_json(orient="index"), "index"))
33+
df = pd.DataFrame({"A": [2, 4, 6], "B": [3, 6, 9]}, index=[0, 1, 2])
34+
assert_frame_equal(df, read_json(df.to_json(orient="split"), "split"))
35+
assert_frame_equal(df, read_json(df.to_json(orient="columns"), "columns"))
36+
assert_frame_equal(df, read_json(df.to_json(orient="index"), "index"))

pandas/tests/io/test_html.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,26 @@ def test_banklist(self):
164164
# This test gives match to read_html as a positional
165165
# argument that is now deprecated, so expect FutureWarning
166166
with tm.assert_produces_warning(FutureWarning):
167-
df1 = self.read_html(self.banklist_data, ".*Florida.*", attrs={"id": "table"})
167+
df1 = self.read_html(
168+
self.banklist_data, ".*Florida.*", attrs={"id": "table"}
169+
)
168170
with tm.assert_produces_warning(FutureWarning):
169-
df2 = self.read_html(self.banklist_data, "Metcalf Bank", attrs={"id": "table"})
171+
df2 = self.read_html(
172+
self.banklist_data, "Metcalf Bank", attrs={"id": "table"}
173+
)
170174

171175
assert_framelist_equal(df1, df2)
172176

173177
@pytest.mark.slow
174178
def test_banklist_match_kwarg(self):
175179
# Just like test_banklist, but passes match as a keyword argument,
176180
# so expect no FutureWarning.
177-
df1 = self.read_html(self.banklist_data, match=".*Florida.*", attrs={"id": "table"})
178-
df2 = self.read_html(self.banklist_data, match="Metcalf Bank", attrs={"id": "table"})
181+
df1 = self.read_html(
182+
self.banklist_data, match=".*Florida.*", attrs={"id": "table"}
183+
)
184+
df2 = self.read_html(
185+
self.banklist_data, match="Metcalf Bank", attrs={"id": "table"}
186+
)
179187

180188
assert_framelist_equal(df1, df2)
181189

@@ -228,6 +236,8 @@ def test_skiprows_int(self):
228236
with tm.assert_produces_warning(FutureWarning):
229237
df2 = self.read_html(self.spam_data, "Unit", skiprows=1)
230238

239+
assert_framelist_equal(df1, df2)
240+
231241
def test_skiprows_int_match_kwarg(self):
232242
df1 = self.read_html(self.spam_data, match=".*Water.*", skiprows=1)
233243
df2 = self.read_html(self.spam_data, match="Unit", skiprows=1)

pandas/util/_decorators.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def wrapper(*args, **kwargs):
213213

214214

215215
def deprecate_nonkeyword_arguments(
216-
version: str, allowed_args = None, *, stacklevel: int = 2
216+
version: str, allowed_args=None, stacklevel: int = 2
217217
) -> Callable:
218218
"""
219219
Decorator to deprecate a use of non-keyword arguments of a function.
@@ -237,24 +237,25 @@ def deprecate_nonkeyword_arguments(
237237
The stack level for warnings.warn
238238
"""
239239

240-
if allowed_args is None:
241-
spec = inspect.getfullargspec(func).args
242-
allowed_args = spec.args[:-len(spec.defaults)]
243240
def decorate(func):
241+
if allowed_args is None:
242+
spec = inspect.getfullargspec(func).args
243+
allow_args = spec.args[: -len(spec.defaults)]
244+
else:
245+
allow_args = allowed_args
246+
244247
@wraps(func)
245248
def wrapper(*args, **kwargs):
246-
if isinstance(allowed_args, int) and len(args) > allowed_args:
249+
if isinstance(allow_args, int) and len(args) > allow_args:
247250
msg = (
248251
"After version %s all arguments of %s "
249252
"except for the first %i will be keyword-only"
250-
) % (version, func.__name__, allowed_args)
251-
elif isinstance(allowed_args, (list, tuple)) and len(args) > len(
252-
allowed_args
253-
):
253+
) % (version, func.__name__, allow_args)
254+
elif isinstance(allow_args, (list, tuple)) and len(args) > len(allow_args):
254255
msg = (
255256
"After version %s all arguments of %s "
256257
"except for (%s) will be keyword-only"
257-
) % (version, func.__name__, ", ".join(allowed_args))
258+
) % (version, func.__name__, ", ".join(allow_args))
258259
else:
259260
msg = None
260261
if msg:

0 commit comments

Comments
 (0)