Skip to content

Commit 54b1151

Browse files
ChiefMilesEdgeworthWillAyd
authored andcommittedOct 11, 2019
TST: Allow for multiple variables on the same line in docstring validation (#28811)
1 parent 0748c91 commit 54b1151

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed
 

‎pandas/core/series.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2076,12 +2076,12 @@ def idxmin(self, axis=0, skipna=True, *args, **kwargs):
20762076
20772077
Parameters
20782078
----------
2079-
skipna : bool, default True
2080-
Exclude NA/null values. If the entire Series is NA, the result
2081-
will be NA.
20822079
axis : int, default 0
20832080
For compatibility with DataFrame.idxmin. Redundant for application
20842081
on Series.
2082+
skipna : bool, default True
2083+
Exclude NA/null values. If the entire Series is NA, the result
2084+
will be NA.
20852085
*args, **kwargs
20862086
Additional keywords have no effect but might be accepted
20872087
for compatibility with NumPy.
@@ -2146,12 +2146,12 @@ def idxmax(self, axis=0, skipna=True, *args, **kwargs):
21462146
21472147
Parameters
21482148
----------
2149-
skipna : bool, default True
2150-
Exclude NA/null values. If the entire Series is NA, the result
2151-
will be NA.
21522149
axis : int, default 0
21532150
For compatibility with DataFrame.idxmax. Redundant for application
21542151
on Series.
2152+
skipna : bool, default True
2153+
Exclude NA/null values. If the entire Series is NA, the result
2154+
will be NA.
21552155
*args, **kwargs
21562156
Additional keywords have no effect but might be accepted
21572157
for compatibility with NumPy.

‎scripts/tests/test_validate_docstrings.py

+48
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ def plot(self, kind, color="blue", **kwargs):
3939
"""
4040
pass
4141

42+
def swap(self, arr, i, j, *args, **kwargs):
43+
"""
44+
Swap two indicies on an array.
45+
46+
Parameters
47+
----------
48+
arr : list
49+
The list having indexes swapped.
50+
i, j : int
51+
The indexes being swapped.
52+
*args, **kwargs
53+
Extraneous parameters are being permitted.
54+
"""
55+
pass
56+
4257
def sample(self):
4358
"""
4459
Generate and return a random number.
@@ -256,6 +271,21 @@ def say_hello():
256271
else:
257272
return None
258273

274+
def multiple_variables_on_one_line(self, matrix, a, b, i, j):
275+
"""
276+
Swap two values in a matrix.
277+
278+
Parameters
279+
----------
280+
matrix : list of list
281+
A double list that represents a matrix.
282+
a, b : int
283+
The indicies of the first value.
284+
i, j : int
285+
The indicies of the second value.
286+
"""
287+
pass
288+
259289

260290
class BadGenericDocStrings:
261291
"""Everything here has a bad docstring
@@ -634,6 +664,17 @@ def list_incorrect_parameter_type(self, kind):
634664
"""
635665
pass
636666

667+
def bad_parameter_spacing(self, a, b):
668+
"""
669+
The parameters on the same line have an extra space between them.
670+
671+
Parameters
672+
----------
673+
a, b : int
674+
Foo bar baz.
675+
"""
676+
pass
677+
637678

638679
class BadReturns:
639680
def return_not_documented(self):
@@ -827,6 +868,7 @@ def test_good_class(self, capsys):
827868
"func",
828869
[
829870
"plot",
871+
"swap",
830872
"sample",
831873
"random_letters",
832874
"sample_values",
@@ -837,6 +879,7 @@ def test_good_class(self, capsys):
837879
"good_imports",
838880
"no_returns",
839881
"empty_returns",
882+
"multiple_variables_on_one_line",
840883
],
841884
)
842885
def test_good_functions(self, capsys, func):
@@ -1002,6 +1045,11 @@ def test_bad_generic_functions(self, capsys, func):
10021045
"list_incorrect_parameter_type",
10031046
('Parameter "kind" type should use "str" instead of "string"',),
10041047
),
1048+
(
1049+
"BadParameters",
1050+
"bad_parameter_spacing",
1051+
("Parameters {b} not documented", "Unknown parameters { b}"),
1052+
),
10051053
pytest.param(
10061054
"BadParameters",
10071055
"blank_lines",

‎scripts/validate_docstrings.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,11 @@ def needs_summary(self):
422422

423423
@property
424424
def doc_parameters(self):
425-
return collections.OrderedDict(
426-
(name, (type_, "".join(desc)))
427-
for name, type_, desc in self.doc["Parameters"]
428-
)
425+
parameters = collections.OrderedDict()
426+
for names, type_, desc in self.doc["Parameters"]:
427+
for name in names.split(", "):
428+
parameters[name] = (type_, "".join(desc))
429+
return parameters
429430

430431
@property
431432
def signature_parameters(self):

0 commit comments

Comments
 (0)
Please sign in to comment.