Skip to content

Commit d289ea8

Browse files
committed
precommit autoformat docstrings
1 parent 3362395 commit d289ea8

7 files changed

+28
-25
lines changed

.pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ repos:
5858
- id: isort
5959
args: ["--profile", "black"]
6060

61+
# Format doctstrings
62+
- repo: https://github.com/DanielNoord/pydocstringformatter
63+
rev: "v0.7.3"
64+
hooks:
65+
- id: pydocstringformatter
66+
args: ["--style=numpydoc"]
67+
6168
# Black format Python and notebooks
6269
- repo: https://github.com/psf/black
6370
rev: 23.3.0

acro/acro.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def add_constant(data, prepend: bool = True, has_constant: str = "skip"):
774774
prepend : bool
775775
If true, the constant is in the first column. Else the constant is
776776
appended (last column).
777-
has_constant: str {'raise', 'add', 'skip'}
777+
has_constant : str {'raise', 'add', 'skip'}
778778
Behavior if data already has a constant. The default will return
779779
data without adding another constant. If 'raise', will raise an
780780
error if any column has a constant value. Using 'add' will add a

notebooks/test-nursery.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
ACRO Tests
3-
Copyright : Maha Albashir, Richard Preen, Jim Smith 2023
3+
Copyright : Maha Albashir, Richard Preen, Jim Smith 2023.
44
"""
55

66
# import libraries

stata/acro_stata_parser.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ def find_brace_contents(word: str, raw: str) -> (bool, str):
7070

7171

7272
def parse_table_details(varlist: list, varnames: list, options: str) -> dict:
73-
"""function to parse stata-13 style table calls
73+
"""Function to parse stata-13 style table calls
7474
Note this is not for latest version of stata, syntax here:
7575
https://www.stata.com/manuals13/rtable.pdf
76-
>> table rowvar [colvar [supercolvar] [if] [in] [weight] [, options]
76+
>> table rowvar [colvar [supercolvar] [if] [in] [weight] [, options].
7777
"""
7878
details = {"errmsg": ""}
7979
details["rowvars"] = [varlist.pop(0)]

test/stata.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python
2-
"""
3-
ACRO Stata Tests.
4-
"""
2+
"""ACRO Stata Tests."""
53

64
# ACRO Tests
75

test/test_initial.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def test_rename_output(data, acro):
296296

297297

298298
def test_add_comments(data, acro):
299-
"""Adding comments to output test"""
299+
"""Adding comments to output test."""
300300
_ = acro.crosstab(data.year, data.grant_type)
301301
results: Record = acro.finalise()
302302
output_0 = results.get_index(0)
@@ -313,7 +313,7 @@ def test_add_comments(data, acro):
313313

314314

315315
def test_custom_output(acro):
316-
"""Adding an unsupported output to the results dictionary test"""
316+
"""Adding an unsupported output to the results dictionary test."""
317317
save_path = "RES_PYTEST"
318318
filename = "notebooks/XandY.jfif"
319319
file_path = os.path.normpath(filename)

test/test_stata_interface.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def dummy_acrohandler(
3939
data, command, varlist, exclusion, exp, weights, options
4040
): # pylint:disable=too-many-arguments
4141
"""
42-
provides an alternative interface that mimics the code in acro.ado
43-
Most notably the presence of a global variable called stata_acro
42+
Provides an alternative interface that mimics the code in acro.ado
43+
Most notably the presence of a global variable called stata_acro.
4444
"""
4545
# global stata_acro
4646
acro_outstr = parse_and_run(
@@ -55,7 +55,7 @@ def test_find_brace_contents():
5555
"""Tests helper function
5656
that extracts contents 'A B C'
5757
of something specified via X(A B C)
58-
on the stata command line
58+
on the stata command line.
5959
"""
6060
options = "by(grant_type) contents(mean sd inc_activity) suppress nototals"
6161
res, substr = find_brace_contents("by", options)
@@ -70,7 +70,7 @@ def test_find_brace_contents():
7070

7171

7272
def test_apply_stata_ifstmt(data):
73-
"""tests that if statements work for selection"""
73+
"""Tests that if statements work for selection."""
7474
ifstring = "year!=2013"
7575
all_list = list(data["year"].unique())
7676
smaller = apply_stata_ifstmt(ifstring, data)
@@ -83,7 +83,7 @@ def test_apply_stata_ifstmt(data):
8383

8484

8585
def test_apply_stata_expstmt(data):
86-
"""tests that in statements work for row selection"""
86+
"""Tests that in statements work for row selection."""
8787
length = data.shape[0]
8888
# use of f/F and l/L for first and last with specified row range
8989
exp = "f/5"
@@ -122,7 +122,7 @@ def test_stata_acro_init() -> str:
122122
Tests creation of an acro object at the start of a session
123123
For stata this gets held in a variable stata_acro
124124
Which is initialsied to the string "empty" in the acro.ado file
125-
Then should be pointed at a new acro instance
125+
Then should be pointed at a new acro instance.
126126
"""
127127
assert isinstance(stata_acro, str)
128128
ret = dummy_acrohandler(
@@ -135,7 +135,7 @@ def test_stata_acro_init() -> str:
135135

136136

137137
def test_stata_print_outputs(data):
138-
"""checks print_outputs gets called"""
138+
"""Checks print_outputs gets called."""
139139
ret = dummy_acrohandler(
140140
data,
141141
command="print_outputs",
@@ -151,10 +151,10 @@ def test_stata_print_outputs(data):
151151
# ----main SDC functionality
152152
def test_simple_table(data) -> str:
153153
"""
154-
checks that the simple table command works as expected
154+
Checks that the simple table command works as expected
155155
Does via reference to direct call to pd.crosstab()
156156
To make sure table specification is parsed correctly
157-
acro SDC analysis is tested elsewhere
157+
acro SDC analysis is tested elsewhere.
158158
"""
159159
correct = pd.crosstab(
160160
index=data["survivor"], columns=data["grant_type"]
@@ -176,7 +176,7 @@ def test_simple_table(data) -> str:
176176
def test_parse_table_details(data):
177177
"""
178178
Series of checks that the varlist and options are parsed correctly
179-
by the helper function
179+
by the helper function.
180180
"""
181181

182182
varlist = ["survivor", "grant_type", "year"]
@@ -201,7 +201,7 @@ def test_parse_table_details(data):
201201

202202

203203
def test_stata_probit(data):
204-
"""checks probit gets called correctly"""
204+
"""Checks probit gets called correctly."""
205205
ret = dummy_acrohandler(
206206
data,
207207
command="probit",
@@ -222,7 +222,7 @@ def test_stata_probit(data):
222222

223223

224224
def test_stata_linregress(data):
225-
"""checks linear regression called correctly"""
225+
"""Checks linear regression called correctly."""
226226
ret = dummy_acrohandler(
227227
data,
228228
command="regress",
@@ -243,9 +243,7 @@ def test_stata_linregress(data):
243243

244244

245245
def test_unsupported_formatting_options(data):
246-
"""
247-
checks that user gets warning if they try to format table
248-
"""
246+
"""Checks that user gets warning if they try to format table."""
249247
format_string = "acro does not currently support table formatting commands."
250248
correct = pd.crosstab(
251249
index=data["survivor"], columns=data["grant_type"]
@@ -279,7 +277,7 @@ def test_unsupported_formatting_options(data):
279277

280278

281279
def test_stata_finalise():
282-
"""checks finalise gets called correctly"""
280+
"""Checks finalise gets called correctly."""
283281
ret = dummy_acrohandler(
284282
data,
285283
command="finalise",

0 commit comments

Comments
 (0)