Skip to content

Commit

Permalink
lint notebooks (isort, pyupgrade) (pymc-devs#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli authored Nov 7, 2020
1 parent 5f95ecb commit 8aa52a4
Show file tree
Hide file tree
Showing 55 changed files with 343 additions and 179 deletions.
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
- id: check-toml
- id: check-yaml
- repo: https://github.com/nbQA-dev/nbQA
rev: 0.4.0
hooks:
- id: nbqa-isort
additional_dependencies: [isort==5.6.4]
- id: nbqa-pyupgrade
additional_dependencies: [pyupgrade==2.7.3]
2 changes: 1 addition & 1 deletion BCM/CaseStudies/ExtrasensoryPerception.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"import scipy as sp\n",
"\n",
"from matplotlib import gridspec\n",
"from theano import tensor as tt\n",
"from scipy import stats\n",
"from theano import tensor as tt\n",
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"warnings.simplefilter(action='ignore', category=(FutureWarning, UserWarning))\n",
Expand Down
2 changes: 1 addition & 1 deletion BCM/CaseStudies/HeuristicDecisionMaking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"import pymc3 as pm\n",
"import scipy.io as sio\n",
"\n",
"from theano import tensor as tt\n",
"from scipy import stats\n",
"from theano import tensor as tt\n",
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"RANDOM_SEED = 8927\n",
Expand Down
2 changes: 1 addition & 1 deletion BCM/CaseStudies/MemoryRetention.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"import seaborn as sns\n",
"import theano\n",
"\n",
"from theano import tensor as tt\n",
"from scipy import stats\n",
"from theano import tensor as tt\n",
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"warnings.simplefilter(action='ignore', category=(FutureWarning, UserWarning))\n",
Expand Down
2 changes: 1 addition & 1 deletion BCM/CaseStudies/MultinomialProcessingTrees.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"import scipy.special as sp\n",
"import theano\n",
"\n",
"from theano import tensor as tt\n",
"from scipy import stats\n",
"from theano import tensor as tt\n",
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"warnings.simplefilter(action='ignore', category=(FutureWarning, UserWarning))\n",
Expand Down
2 changes: 1 addition & 1 deletion BCM/CaseStudies/NumberConceptDevelopment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"import scipy.io as sio\n",
"import theano\n",
"\n",
"from theano import tensor as tt\n",
"from scipy import stats\n",
"from theano import tensor as tt\n",
"\n",
"%config InlineBackend.figure_format = 'retina'\n",
"warnings.simplefilter(action='ignore', category=(FutureWarning, UserWarning))\n",
Expand Down
10 changes: 6 additions & 4 deletions BDA3/chap_02.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import arviz as az\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc3 as pm\n",
"import arviz as az\n",
"\n",
"from scipy.special import expit"
]
},
Expand Down Expand Up @@ -627,7 +628,7 @@
"lldd = expit(df2.loc['trans','hpd_3%'])\n",
"llii = expit(df2.loc['trans','hpd_97%'])\n",
"\n",
"print('The interval is [{:.3f}, {:.3f}]'.format(lldd, llii))"
"print(f'The interval is [{lldd:.3f}, {llii:.3f}]')"
]
},
{
Expand All @@ -647,6 +648,7 @@
"source": [
"import theano.tensor as tt\n",
"\n",
"\n",
"def triangular(central_num, width):\n",
" \n",
" left_num = central_num - width\n",
Expand Down Expand Up @@ -1446,7 +1448,7 @@
],
"source": [
"val = np.mean(trace_poisson_2['theta'] >= 1)\n",
"print('The posterior probability that theta exceeds 1.0 is {:.2f}.'.format(val))"
"print(f'The posterior probability that theta exceeds 1.0 is {val:.2f}.')"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions BDA3/chap_03.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc3 as pm\n",
"import seaborn as sns\n",
"\n",
Expand Down Expand Up @@ -106,7 +106,7 @@
],
"source": [
"mean_t = np.mean(nums)\n",
"print('The mean of the 66 measurements is {:.1f}'.format(mean_t))"
"print(f'The mean of the 66 measurements is {mean_t:.1f}')"
]
},
{
Expand All @@ -124,7 +124,7 @@
],
"source": [
"std_t = np.std(nums, ddof=1)\n",
"print('The standard deviation of the 66 measurements is {:.1f}'.format(std_t))"
"print(f'The standard deviation of the 66 measurements is {std_t:.1f}')"
]
},
{
Expand Down Expand Up @@ -419,7 +419,7 @@
],
"source": [
"delta_bin = bins1[1] - bins1[0]\n",
"print('This is delta x: {}'.format(delta_bin))"
"print(f'This is delta x: {delta_bin}')"
]
},
{
Expand Down Expand Up @@ -484,7 +484,7 @@
"l_i = bins1[idx - int(idx_sol)]\n",
"l_d = bins1[idx + int(idx_sol)]\n",
"\n",
"print('The central posterior interval is [{:.2f}, {:.2f}]'.format(l_i, l_d))"
"print(f'The central posterior interval is [{l_i:.2f}, {l_d:.2f}]')"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions BDA3/chap_05.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import arviz as az\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc3 as pm\n",
"import theano.tensor as tt\n",
"import arviz as az"
"import theano.tensor as tt"
]
},
{
Expand Down Expand Up @@ -90,7 +90,7 @@
}
],
"source": [
"print('The shape of rat_tumor is {}'.format(rat_tumor.shape))"
"print(f'The shape of rat_tumor is {rat_tumor.shape}')"
]
},
{
Expand Down Expand Up @@ -810,7 +810,7 @@
"ax.grid()\n",
"ax.set_ylim(1.7, 3.75)\n",
"ax.set_xlabel('log(α / β)')\n",
"_ = ax.set_ylabel('log(α + β)')\n"
"_ = ax.set_ylabel('log(α + β)')"
]
},
{
Expand Down Expand Up @@ -1587,7 +1587,7 @@
" a3 = np.percentile(post_obs['obs'][:, i], 50)\n",
" a4 = np.percentile(post_obs['obs'][:, i], 75)\n",
" a5 = np.percentile(post_obs['obs'][:, i], 97.5)\n",
" print('{:^7} {:^10.0f} {:^10.0f} {:^10.0f} {:^10.0f} {:^10.0f}'.format(z, a1, a2, a3, a4, a5))"
" print(f'{z:^7} {a1:^10.0f} {a2:^10.0f} {a3:^10.0f} {a4:^10.0f} {a5:^10.0f}')"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions BDA3/chap_06.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
"outputs": [],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import itertools\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc3 as pm\n",
"import seaborn as sns\n",
"import theano.tensor as tt\n",
"import itertools\n",
"\n",
"plt.style.use('seaborn-darkgrid')\n",
"plt.rc('font', size=12)\n",
Expand Down
27 changes: 15 additions & 12 deletions BDA3/chap_07.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import random\n",
"import statistics as stat\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc3 as pm\n",
"import theano.tensor as tt\n",
"\n",
"import statistics as stat\n",
"from scipy import stats\n",
"import random\n",
"\n",
"plt.style.use('seaborn-darkgrid')\n",
"plt.rc('font', size=12)\n",
Expand Down Expand Up @@ -387,7 +388,7 @@
"y_total = n * np.mean(ppc_1['y_bar'], axis=1) + (N - n) * y_miss_1\n",
"perc_25 = int(np.percentile(y_total, 2.5))\n",
"perc_975 = int(np.percentile(y_total, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -416,7 +417,7 @@
"y_to = n * np.mean(ppc_1['y_bar'], axis=1) + (N - n) * np.mean(ppc_1['y_bar'], axis=1) \n",
"perc_25 = int(np.percentile(y_to, 2.5))\n",
"perc_975 = int(np.percentile(y_to, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -635,7 +636,7 @@
"y_total_2 = n * np.mean(ppc_1_log['y_bar'], axis=1) + (N - n) * y_miss_2\n",
"perc_25 = int(np.percentile(y_total_2, 2.5))\n",
"perc_975 = int(np.percentile(y_total_2, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -732,6 +733,7 @@
],
"source": [
"from scipy import stats\n",
"\n",
"stats.boxcox(sample1)"
]
},
Expand Down Expand Up @@ -961,7 +963,7 @@
"y_total_3 = n * np.mean(invbox_cox(ppc_trans['y_phi'], phi), axis=1) + (N - n) * invbox_cox(y_miss_3, phi)\n",
"perc_25 = int(np.percentile(y_total_3, 2.5))\n",
"perc_975 = int(np.percentile(y_total_3, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -1226,7 +1228,7 @@
"y_total_4 = n * np.mean(ppc_2['y_bar'], axis=1) + (N - n) * y_miss_4\n",
"perc_25 = int(np.percentile(y_total_4, 2.5))\n",
"perc_975 = int(np.percentile(y_total_4, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -1445,7 +1447,7 @@
"y_total_5 = n * np.mean(ppc_2_log['y_bar'], axis=1) + (N - n) * y_miss_5\n",
"perc_25 = int(np.percentile(y_total_5, 2.5))\n",
"perc_975 = int(np.percentile(y_total_5, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -1542,6 +1544,7 @@
],
"source": [
"from scipy import stats\n",
"\n",
"stats.boxcox(sample2)"
]
},
Expand Down Expand Up @@ -1776,7 +1779,7 @@
"y_total_6 = n * np.mean(invbox_cox(ppc_trans_2['y_phi'], phi2), axis=1) + (N - n) * invbox_cox(y_miss_6, phi2)\n",
"perc_25 = int(np.percentile(y_total_6, 2.5))\n",
"perc_975 = int(np.percentile(y_total_6, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -1848,7 +1851,7 @@
"y_total_6 = y_total_6[~np.isnan(y_total_6)]\n",
"perc_25 = int(np.percentile(y_total_6, 2.5))\n",
"perc_975 = int(np.percentile(y_total_6, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down Expand Up @@ -1888,7 +1891,7 @@
"y_total_6 = n * np.mean(invbox_cox_mod(ppc_trans_2['y_phi'], phi2), axis=1) + (N - n) * invbox_cox_mod(y_miss_6, phi2)\n",
"perc_25 = int(np.percentile(y_total_6, 2.5))\n",
"perc_975 = int(np.percentile(y_total_6, 97.5))\n",
"print('The 95% interval is [{:.2e}, {:.2e}]'.format(perc_25, perc_975))"
"print(f'The 95% interval is [{perc_25:.2e}, {perc_975:.2e}]')"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions BSM/Chapter_03_00_Bayesian_CLT.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from scipy import stats\n",
"import matplotlib.pyplot as plt"
"\n",
"from scipy import stats"
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions BSM/Chapter_03_01_Gibbs_sampling_one_sample_t-test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from scipy import stats\n",
"import matplotlib.pyplot as plt"
"\n",
"from scipy import stats"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions BSM/Chapter_03_02_Gibbs_sampling_two_sample_t-test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy import stats\n",
"import arviz as az\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import arviz as az"
"from scipy import stats"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy import stats\n",
"import arviz as az\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import statsmodels.formula.api as smf\n",
"\n",
"import arviz as az"
"from scipy import stats"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions BSM/Chapter_03_04_Gibbs_sampling_for_concussions_data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from scipy import stats\n",
"import arviz as az\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import arviz as az"
"from scipy import stats"
]
},
{
Expand Down
Loading

0 comments on commit 8aa52a4

Please sign in to comment.