Skip to content

Commit 796cb26

Browse files
committed
ruff formatting of docstrings
1 parent e61bfd0 commit 796cb26

8 files changed

+47
-41
lines changed

causalpy/data/simulate_data.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def generate_synthetic_control_data(
7171
Example
7272
--------
7373
>>> from causalpy.data.simulate_data import generate_synthetic_control_data
74-
>>> df, weightings_true = generate_synthetic_control_data(
75-
... treatment_time=70
76-
... )
74+
>>> df, weightings_true = generate_synthetic_control_data(treatment_time=70)
7775
"""
7876

7977
# 1. Generate non-treated variables
@@ -267,8 +265,9 @@ def generate_regression_discontinuity_data(
267265
>>> import pathlib
268266
>>> from causalpy.data.simulate_data import generate_regression_discontinuity_data
269267
>>> df = generate_regression_discontinuity_data(true_treatment_threshold=0.5)
270-
>>> df.to_csv(pathlib.Path.cwd() / 'regression_discontinuity.csv',
271-
... index=False) # doctest: +SKIP
268+
>>> df.to_csv(
269+
... pathlib.Path.cwd() / "regression_discontinuity.csv", index=False
270+
... ) # doctest: +SKIP
272271
"""
273272

274273
def is_treated(x):
@@ -298,13 +297,9 @@ def generate_ancova_data(
298297
>>> import pathlib
299298
>>> from causalpy.data.simulate_data import generate_ancova_data
300299
>>> df = generate_ancova_data(
301-
... N=200,
302-
... pre_treatment_means=np.array([10, 12]),
303-
... treatment_effect=2,
304-
... sigma=1
300+
... N=200, pre_treatment_means=np.array([10, 12]), treatment_effect=2, sigma=1
305301
... )
306-
>>> df.to_csv(pathlib.Path.cwd() / 'ancova_data.csv',
307-
... index=False) # doctest: +SKIP
302+
>>> df.to_csv(pathlib.Path.cwd() / "ancova_data.csv", index=False) # doctest: +SKIP
308303
"""
309304
group = np.random.choice(2, size=N)
310305
pre = np.random.normal(loc=pre_treatment_means[group])

causalpy/experiments/diff_in_diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class DifferenceInDifferences(BaseExperiment):
7070
... "random_seed": seed,
7171
... "progressbar": False,
7272
... }
73-
... )
74-
... )
73+
... ),
74+
... )
7575
"""
7676

7777
supports_ols = True

causalpy/experiments/instrumental_variable.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ class InstrumentalVariable(BaseExperiment):
7474
... "cores": 4,
7575
... "target_accept": 0.95,
7676
... "progressbar": False,
77-
... }
77+
... }
7878
>>> instruments_formula = "X ~ 1 + Z"
7979
>>> formula = "y ~ 1 + X"
8080
>>> instruments_data = test_data[["X", "Z"]]
8181
>>> data = test_data[["y", "X"]]
8282
>>> iv = cp.InstrumentalVariable(
83-
... instruments_data=instruments_data,
84-
... data=data,
85-
... instruments_formula=instruments_formula,
86-
... formula=formula,
87-
... model=InstrumentalVariableRegression(sample_kwargs=sample_kwargs),
83+
... instruments_data=instruments_data,
84+
... data=data,
85+
... instruments_formula=instruments_formula,
86+
... formula=formula,
87+
... model=InstrumentalVariableRegression(sample_kwargs=sample_kwargs),
8888
... )
8989
"""
9090

causalpy/experiments/inverse_propensity_weighting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class InversePropensityWeighting(BaseExperiment):
5656
>>> result = cp.InversePropensityWeighting(
5757
... df,
5858
... formula="trt ~ 1 + age + race",
59-
... outcome_variable ="outcome",
59+
... outcome_variable="outcome",
6060
... weighting_scheme="robust",
6161
... model=cp.pymc_models.PropensityScore(
6262
... sample_kwargs={

causalpy/experiments/prepostfit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class InterruptedTimeSeries(PrePostFit):
337337
... "random_seed": seed,
338338
... "progressbar": False,
339339
... }
340-
... )
340+
... ),
341341
... )
342342
"""
343343

causalpy/experiments/prepostnegd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ class PrePostNEGD(BaseExperiment):
6969
... "random_seed": seed,
7070
... "progressbar": False,
7171
... }
72-
... )
72+
... ),
7373
... )
74-
>>> result.summary(round_to=1) # doctest: +NUMBER
74+
>>> result.summary(round_to=1) # doctest: +NUMBER
7575
==================Pretest/posttest Nonequivalent Group Design===================
7676
Formula: post ~ 1 + C(group) + pre
7777
<BLANKLINE>

causalpy/pymc_models.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ class PyMCModel(pm.Model):
5050
>>> X = rng.normal(loc=0, scale=1, size=(20, 2))
5151
>>> y = rng.normal(loc=0, scale=1, size=(20,))
5252
>>> model = MyToyModel(
53-
... sample_kwargs={
54-
... "chains": 2,
55-
... "draws": 2000,
56-
... "progressbar": False,
57-
... "random_seed": 42,
58-
... }
53+
... sample_kwargs={
54+
... "chains": 2,
55+
... "draws": 2000,
56+
... "progressbar": False,
57+
... "random_seed": 42,
58+
... }
5959
... )
6060
>>> model.fit(X, y)
6161
Inference data...
6262
>>> model.score(X, y) # doctest: +ELLIPSIS
6363
r2 ...
6464
r2_std ...
6565
dtype: float64
66-
>>> X_new = rng.normal(loc=0, scale=1, size=(20,2))
66+
>>> X_new = rng.normal(loc=0, scale=1, size=(20, 2))
6767
>>> model.predict(X_new)
6868
Inference data...
6969
"""
@@ -286,11 +286,11 @@ class InstrumentalVariableRegression(PyMCModel):
286286
>>> ## Ensure the endogeneity of the the treatment variable
287287
>>> X = -1 + 4 * Z + e2 + 2 * e1
288288
>>> y = 2 + 3 * X + 3 * e1
289-
>>> t = X.reshape(10,1)
290-
>>> y = y.reshape(10,1)
291-
>>> Z = np.asarray([[1, Z[i]] for i in range(0,10)])
292-
>>> X = np.asarray([[1, X[i]] for i in range(0,10)])
293-
>>> COORDS = {'instruments': ['Intercept', 'Z'], 'covariates': ['Intercept', 'X']}
289+
>>> t = X.reshape(10, 1)
290+
>>> y = y.reshape(10, 1)
291+
>>> Z = np.asarray([[1, Z[i]] for i in range(0, 10)])
292+
>>> X = np.asarray([[1, X[i]] for i in range(0, 10)])
293+
>>> COORDS = {"instruments": ["Intercept", "Z"], "covariates": ["Intercept", "X"]}
294294
>>> sample_kwargs = {
295295
... "tune": 5,
296296
... "draws": 10,
@@ -300,12 +300,20 @@ class InstrumentalVariableRegression(PyMCModel):
300300
... "progressbar": False,
301301
... }
302302
>>> iv_reg = InstrumentalVariableRegression(sample_kwargs=sample_kwargs)
303-
>>> iv_reg.fit(X, Z,y, t, COORDS, {
304-
... "mus": [[-2,4], [0.5, 3]],
305-
... "sigmas": [1, 1],
306-
... "eta": 2,
307-
... "lkj_sd": 1,
308-
... }, None)
303+
>>> iv_reg.fit(
304+
... X,
305+
... Z,
306+
... y,
307+
... t,
308+
... COORDS,
309+
... {
310+
... "mus": [[-2, 4], [0.5, 3]],
311+
... "sigmas": [1, 1],
312+
... "eta": 2,
313+
... "lkj_sd": 1,
314+
... },
315+
... None,
316+
... )
309317
Inference data...
310318
"""
311319

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ omit-covered-files = false
118118
generate-badge = "docs/source/_static/"
119119
badge-format = "svg"
120120

121+
[tool.ruff.format]
122+
docstring-code-format = true
123+
121124
[tool.ruff.lint]
122125
extend-select = [
123126
"I", # isort

0 commit comments

Comments
 (0)