Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nbQA for notebook and docs linting #361

Merged
merged 9 commits into from Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -25,3 +25,14 @@ repos:
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.5.0
basnijholt marked this conversation as resolved.
Show resolved Hide resolved
hooks:
- id: nbqa-black
additional_dependencies: [jupytext, black]
basnijholt marked this conversation as resolved.
Show resolved Hide resolved
- id: nbqa-pyupgrade
args: ["--py37-plus"]
additional_dependencies: [jupytext, pyupgrade]
- id: nbqa-isort
args: ["--profile=black"]
additional_dependencies: [jupytext, isort]
26 changes: 14 additions & 12 deletions example-notebook.ipynb
Expand Up @@ -27,11 +27,12 @@
"\n",
"adaptive.notebook_extension()\n",
"\n",
"import random\n",
"from functools import partial\n",
"\n",
"# Import modules that are used in multiple cells\n",
"import holoviews as hv\n",
"import numpy as np\n",
"from functools import partial\n",
"import random"
"import numpy as np"
]
},
{
Expand Down Expand Up @@ -60,15 +61,15 @@
"\n",
"\n",
"def peak(x, offset=offset, wait=True):\n",
" from time import sleep\n",
" from random import random\n",
" from time import sleep\n",
"\n",
" a = 0.01\n",
" if wait:\n",
" # we pretend that this is a slow function\n",
" sleep(random())\n",
"\n",
" return x + a**2 / (a**2 + (x - offset)**2)"
" return x + a**2 / (a**2 + (x - offset) ** 2)"
]
},
{
Expand Down Expand Up @@ -173,16 +174,17 @@
"outputs": [],
"source": [
"def ring(xy, wait=True):\n",
" import numpy as np\n",
" from time import sleep\n",
" from random import random\n",
" from time import sleep\n",
"\n",
" import numpy as np\n",
"\n",
" if wait:\n",
" # we pretend that this is a slow function\n",
" sleep(random() / 10)\n",
" x, y = xy\n",
" a = 0.2\n",
" return x + np.exp(-((x**2 + y**2 - 0.75**2)**2) / a**4)\n",
" return x + np.exp(-((x**2 + y**2 - 0.75**2) ** 2) / a**4)\n",
"\n",
"\n",
"learner = adaptive.Learner2D(ring, bounds=[(-1, 1), (-1, 1)])"
Expand Down Expand Up @@ -223,7 +225,7 @@
"# Create a learner and add data on homogeneous grid, so that we can plot it\n",
"learner2 = adaptive.Learner2D(ring, bounds=learner.bounds)\n",
"n = int(learner.npoints**0.5)\n",
"xs, ys = [np.linspace(*bounds, n) for bounds in learner.bounds]\n",
"xs, ys = (np.linspace(*bounds, n) for bounds in learner.bounds)\n",
"xys = list(itertools.product(xs, ys))\n",
"zs = [ring(xy, wait=False) for xy in xys]\n",
"learner2.tell_many(xys, zs)\n",
Expand Down Expand Up @@ -316,7 +318,7 @@
"source": [
"def noisy_peak(seed_x, sigma=0, peak_width=0.05, offset=-0.5):\n",
" seed, x = seed_x\n",
" y = x**3 - x + 3 * peak_width**2 / (peak_width**2 + (x - offset)**2)\n",
" y = x**3 - x + 3 * peak_width**2 / (peak_width**2 + (x - offset) ** 2)\n",
" rng = np.random.RandomState(int(seed))\n",
" noise = rng.normal(scale=sigma)\n",
" return y + noise"
Expand Down Expand Up @@ -568,7 +570,7 @@
"def sphere(xyz):\n",
" x, y, z = xyz\n",
" a = 0.4\n",
" return x + z**2 + np.exp(-((x**2 + y**2 + z**2 - 0.75**2)**2) / a**4)\n",
" return x + z**2 + np.exp(-((x**2 + y**2 + z**2 - 0.75**2) ** 2) / a**4)\n",
"\n",
"\n",
"learner = adaptive.LearnerND(sphere, bounds=[(-1, 1), (-1, 1), (-1, 1)])\n",
Expand Down Expand Up @@ -817,7 +819,7 @@
"source": [
"def h(x, offset=0):\n",
" a = 0.01\n",
" return x + a**2 / (a**2 + (x - offset)**2)\n",
" return x + a**2 / (a**2 + (x - offset) ** 2)\n",
"\n",
"\n",
"learners = [\n",
Expand Down