Skip to content

Commit 70e9ecb

Browse files
use context managers in notebooks
1 parent ce9d5b1 commit 70e9ecb

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

docs/examples/notebooks/ImpactPlot.ipynb

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,11 @@
7676
"outputs": [],
7777
"source": [
7878
"def make_model(channel_list):\n",
79-
" spec = json.load(\n",
80-
" open(\"1Lbb-probability-models/RegionA/BkgOnly.json\", encoding=\"utf-8\")\n",
81-
" )\n",
82-
" patchset = pyhf.PatchSet(\n",
83-
" json.load(\n",
84-
" open(\"1Lbb-probability-models/RegionA/patchset.json\", encoding=\"utf-8\")\n",
85-
" )\n",
86-
" )\n",
79+
" with open(\"1Lbb-probability-models/RegionA/BkgOnly.json\", encoding=\"utf-8\") as spec_file:\n",
80+
" spec = json.load(spec_file)\n",
81+
" with open(\"1Lbb-probability-models/RegionA/patchset.json\", encoding=\"utf-8\") as patchset_file:\n",
82+
" patchset = pyhf.PatchSet(json.load(patchset_file))\n",
83+
"\n",
8784
" patch = patchset[\"sbottom_750_745_60\"]\n",
8885
" spec = jsonpatch.apply_patch(spec, patch)\n",
8986
" spec[\"channels\"] = [c for c in spec[\"channels\"] if c[\"name\"] in channel_list]\n",

docs/examples/notebooks/multiBinPois.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
}
8686
],
8787
"source": [
88-
"source = json.load(open(validation_datadir + \"/1bin_example1.json\", encoding=\"utf-8\"))\n",
88+
"with open(validation_datadir + \"/1bin_example1.json\", encoding=\"utf-8\") as source_file:\n",
89+
" source = json.load(source_file)\n",
8990
"model = uncorrelated_background(\n",
9091
" source['bindata']['sig'], source['bindata']['bkg'], source['bindata']['bkgerr']\n",
9192
")\n",

docs/examples/notebooks/multichannel-coupled-histo.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,8 @@
165165
}
166166
],
167167
"source": [
168-
"with open(\n",
169-
" validation_datadir + \"/2bin_2channel_coupledhisto.json\", encoding=\"utf-8\"\n",
170-
") as spec:\n",
171-
" source = json.load(spec)\n",
168+
"with open(validation_datadir + \"/2bin_2channel_coupledhisto.json\", encoding=\"utf-8\") as source_file:\n",
169+
" source = json.load(source_file)\n",
172170
"\n",
173171
"data, pdf = prep_data(source[\"channels\"])\n",
174172
"\n",

docs/examples/notebooks/pullplot.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
" \"1Lbb-probability-models/RegionA/BkgOnly.json\", encoding=\"utf-8\"\n",
7777
" ) as spec_file:\n",
7878
" spec = json.load(spec_file)\n",
79+
"\n",
7980
" spec[\"channels\"] = [c for c in spec[\"channels\"] if c[\"name\"] in channel_list]\n",
8081
" spec[\"measurements\"][0][\"config\"][\"poi\"] = \"lumi\"\n",
8182
"\n",

0 commit comments

Comments
 (0)