Skip to content

Commit e7b4bfb

Browse files
authored
Merge pull request #125 from pymc-labs/isort
fix notebook formatting
2 parents c12d11a + 02c76f5 commit e7b4bfb

16 files changed

+1436
-1444
lines changed

.pre-commit-config.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ repos:
1010
exclude_types: [svg]
1111
- id: check-yaml
1212
- id: check-added-large-files
13-
- repo: https://github.com/asottile/seed-isort-config
14-
rev: v2.2.0
15-
hooks:
16-
- id: seed-isort-config
17-
- repo: https://github.com/pre-commit/mirrors-isort
18-
rev: v5.10.1
13+
- repo: https://github.com/pycqa/isort
14+
rev: 5.11.2
1915
hooks:
2016
- id: isort
2117
args: [--profile, black]
@@ -24,8 +20,16 @@ repos:
2420
rev: 22.10.0
2521
hooks:
2622
- id: black
27-
- id: black-jupyter
2823
- repo: https://github.com/pycqa/flake8
2924
rev: 3.9.2
3025
hooks:
3126
- id: flake8
27+
- repo: https://github.com/nbQA-dev/nbQA
28+
rev: 1.5.3
29+
hooks:
30+
- id: nbqa-black
31+
# additional_dependencies: [jupytext] # optional, only if you're using Jupytext
32+
- id: nbqa-pyupgrade
33+
args: ["--py37-plus"]
34+
- id: nbqa-isort
35+
args: ["--float-to-top"]

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ check_lint:
1313
flake8 .
1414
isort --check-only .
1515
black --diff --check --fast .
16+
nbqa black --check .
17+
nbqa isort --check-only .
1618

1719
test:
1820
pip install -r requirements-test.txt

docs/notebooks/ancova_pymc.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
"metadata": {},
3838
"outputs": [],
3939
"source": [
40-
"import causalpy as cp\n",
4140
"import matplotlib.pyplot as plt\n",
42-
"import seaborn as sns"
41+
"import seaborn as sns\n",
42+
"\n",
43+
"import causalpy as cp"
4344
]
4445
},
4546
{

docs/notebooks/did_pymc.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16+
"import arviz as az\n",
17+
"\n",
1618
"import causalpy as cp"
1719
]
1820
},
@@ -480,8 +482,6 @@
480482
}
481483
],
482484
"source": [
483-
"import arviz as az\n",
484-
"\n",
485485
"ax = az.plot_posterior(result.causal_impact, ref_val=0)\n",
486486
"ax.set(title=\"Posterior estimate of causal impact\");"
487487
]

docs/notebooks/did_pymc_banks.ipynb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"metadata": {},
2424
"outputs": [],
2525
"source": [
26+
"import arviz as az\n",
27+
"import pandas as pd\n",
28+
"\n",
2629
"import causalpy as cp"
2730
]
2831
},
@@ -255,8 +258,6 @@
255258
}
256259
],
257260
"source": [
258-
"import pandas as pd\n",
259-
"\n",
260261
"df.reset_index(level=0, inplace=True)\n",
261262
"df_long = pd.melt(\n",
262263
" df,\n",
@@ -630,8 +631,6 @@
630631
}
631632
],
632633
"source": [
633-
"import arviz as az\n",
634-
"\n",
635634
"ax = az.plot_posterior(result.causal_impact, ref_val=0)\n",
636635
"ax.set(title=\"Posterior estimate of causal impact\");"
637636
]

docs/notebooks/did_skl.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16+
"import xarray as xr\n",
17+
"from sklearn.linear_model import LinearRegression\n",
18+
"\n",
1619
"import causalpy as cp"
1720
]
1821
},
@@ -31,9 +34,6 @@
3134
"metadata": {},
3235
"outputs": [],
3336
"source": [
34-
"from sklearn.linear_model import LinearRegression\n",
35-
"\n",
36-
"\n",
3737
"result = cp.skl_experiments.DifferenceInDifferences(\n",
3838
" data,\n",
3939
" formula=\"y ~ 1 + group + t + treated:group\",\n",
@@ -80,7 +80,7 @@
8080
],
8181
"metadata": {
8282
"kernelspec": {
83-
"display_name": "Python 3.10.6 ('CausalPy')",
83+
"display_name": "CausalPy",
8484
"language": "python",
8585
"name": "python3"
8686
},
@@ -94,12 +94,12 @@
9494
"name": "python",
9595
"nbconvert_exporter": "python",
9696
"pygments_lexer": "ipython3",
97-
"version": "3.10.6"
97+
"version": "3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:38:29) [Clang 13.0.1 ]"
9898
},
9999
"orig_nbformat": 4,
100100
"vscode": {
101101
"interpreter": {
102-
"hash": "46d31859cc45aa26a1223a391e7cf3023d69984b498bed11e66c690302b7e251"
102+
"hash": "02f5385db19eab57520277c5168790c7855381ee953bdbb5c89c321e1f17586e"
103103
}
104104
}
105105
},

docs/notebooks/its_covid.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16-
"import causalpy as cp\n",
16+
"import arviz as az\n",
1717
"import pandas as pd\n",
18-
"import arviz as az"
18+
"\n",
19+
"import causalpy as cp"
1920
]
2021
},
2122
{

docs/notebooks/rd_pymc_drinking.ipynb

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616
"outputs": [],
1717
"source": [
1818
"# for use when developing the code\n",
19+
"import arviz as az\n",
20+
"import matplotlib.pyplot as plt\n",
21+
"\n",
22+
"import causalpy as cp\n",
23+
"\n",
1924
"%load_ext autoreload\n",
2025
"%autoreload 2\n",
2126
"# %config InlineBackend.figure_format = 'svg'"
2227
]
2328
},
24-
{
25-
"cell_type": "code",
26-
"execution_count": 2,
27-
"metadata": {},
28-
"outputs": [],
29-
"source": [
30-
"import causalpy as cp"
31-
]
32-
},
3329
{
3430
"cell_type": "markdown",
3531
"metadata": {},
@@ -448,10 +444,6 @@
448444
}
449445
],
450446
"source": [
451-
"import matplotlib.pyplot as plt\n",
452-
"import arviz as az\n",
453-
"\n",
454-
"\n",
455447
"fig, ax = plt.subplots(1, 2, figsize=(10, 3))\n",
456448
"\n",
457449
"az.plot_forest(result.prediction_model.idata.posterior, var_names=\"beta\", ax=ax[0])\n",
@@ -1135,8 +1127,6 @@
11351127
}
11361128
],
11371129
"source": [
1138-
"import matplotlib.pyplot as plt\n",
1139-
"\n",
11401130
"fig, ax = plt.subplots(1, 2, figsize=(10, 3))\n",
11411131
"\n",
11421132
"az.plot_forest(result3.prediction_model.idata.posterior, var_names=\"beta\", ax=ax[0])\n",

docs/notebooks/rd_skl.ipynb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
16+
"from sklearn.gaussian_process import GaussianProcessRegressor\n",
17+
"from sklearn.gaussian_process.kernels import ExpSineSquared, WhiteKernel\n",
18+
"from sklearn.linear_model import LinearRegression\n",
19+
"\n",
1620
"import causalpy as cp"
1721
]
1822
},
@@ -121,8 +125,6 @@
121125
"metadata": {},
122126
"outputs": [],
123127
"source": [
124-
"from sklearn.linear_model import LinearRegression\n",
125-
"\n",
126128
"result = cp.skl_experiments.RegressionDiscontinuity(\n",
127129
" data,\n",
128130
" formula=\"y ~ 1 + x + treated\",\n",
@@ -205,9 +207,6 @@
205207
"metadata": {},
206208
"outputs": [],
207209
"source": [
208-
"from sklearn.gaussian_process import GaussianProcessRegressor\n",
209-
"from sklearn.gaussian_process.kernels import WhiteKernel, ExpSineSquared\n",
210-
"\n",
211210
"kernel = 1.0 * ExpSineSquared(1.0, 5.0) + WhiteKernel(1e-1)\n",
212211
"result = cp.skl_experiments.RegressionDiscontinuity(\n",
213212
" data,\n",
@@ -250,8 +249,6 @@
250249
"metadata": {},
251250
"outputs": [],
252251
"source": [
253-
"from sklearn.linear_model import LinearRegression\n",
254-
"\n",
255252
"# use basis splines\n",
256253
"result = cp.skl_experiments.RegressionDiscontinuity(\n",
257254
" data,\n",

docs/notebooks/rd_skl_drinking.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
20+
"from sklearn.linear_model import LinearRegression\n",
21+
"\n",
2022
"import causalpy as cp"
2123
]
2224
},
@@ -40,8 +42,6 @@
4042
"metadata": {},
4143
"outputs": [],
4244
"source": [
43-
"from sklearn.linear_model import LinearRegression\n",
44-
"\n",
4545
"result = cp.skl_experiments.RegressionDiscontinuity(\n",
4646
" df,\n",
4747
" formula=\"all ~ 1 + age + treated\",\n",

0 commit comments

Comments
 (0)