Skip to content

Commit 9890325

Browse files
authored
Merge pull request #34 from alliander-opensource/fix-vuln
Fix vulnerabilities.
2 parents e6c7f39 + 779832d commit 9890325

9 files changed

Lines changed: 957 additions & 806 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: continuous-integration-checks
22

33
on:
4-
push:
5-
branches:
6-
- '*'
74
pull_request:
85
branches:
96
- main
@@ -12,25 +9,25 @@ on:
129

1310
jobs:
1411
python-checks:
15-
runs-on: ubuntu-latest
12+
runs-on:
13+
group: managed
1614
strategy:
1715
fail-fast: false
1816
matrix:
1917
python-version: ["3.12"]
2018

2119
steps:
22-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2321

24-
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version: ${{ matrix.python-version }}
22+
# uv installs via its standalone script (not a GitHub Action, so exempt
23+
# from the enterprise SHA-pinning policy) and provisions Python itself,
24+
# avoiding an extra pinned action such as actions/setup-python.
25+
- name: Install uv
26+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
2827

2928
- name: Install Dependencies
3029
run: |
31-
python -m pip install --upgrade pip build wheel setuptools
32-
python -m pip install uv
33-
uv venv
30+
uv python install ${{ matrix.python-version }}
3431
uv sync
3532
3633
- name: Check

notebooks/01_train_model.ipynb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,22 @@
215215
"outputs": [],
216216
"source": [
217217
"from torch.utils.data import DataLoader\n",
218+
"\n",
218219
"from s4casting.data.utils import collate_single_interval\n",
219220
"\n",
220221
"N = len(batcher.train)\n",
221222
"print(f\"The training dataset has {N} samples\")\n",
222223
"first, _ = next(\n",
223224
" iter(\n",
224-
" DataLoader(batcher.train, batch_size=1, num_workers=0, shuffle=True, pin_memory=False, persistent_workers=False, collate_fn=collate_single_interval)\n",
225+
" DataLoader(\n",
226+
" batcher.train,\n",
227+
" batch_size=1,\n",
228+
" num_workers=0,\n",
229+
" shuffle=True,\n",
230+
" pin_memory=False,\n",
231+
" persistent_workers=False,\n",
232+
" collate_fn=collate_single_interval,\n",
233+
" )\n",
225234
" )\n",
226235
")\n",
227236
"X, Xm, Y, Ym = (t for t in first)\n",
@@ -284,7 +293,9 @@
284293
"import numpy as np\n",
285294
"\n",
286295
"predict_width_samples = (config.model.predict_width * 24 * 60) // config.model.base_sample_interval_minutes\n",
287-
"input_width_samples = ((config.model.context_window[0] * 24 * 60) // config.model.base_sample_interval_minutes) - predict_width_samples\n",
296+
"input_width_samples = (\n",
297+
" (config.model.context_window[0] * 24 * 60) // config.model.base_sample_interval_minutes\n",
298+
") - predict_width_samples\n",
288299
"days_per_sample = config.model.context_window[0]\n",
289300
"samples_per_day = 96 # 24 hours x 4 samples/hour\n",
290301
"\n",
@@ -369,13 +380,11 @@
369380
" Xm = Xm.to(context.machine.torch_device).float()\n",
370381
" Ym = Ym.to(context.machine.torch_device).float()\n",
371382
"\n",
372-
" input_interval = batch_cfg.sample_interval_minutes.to(context.machine.torch_device)\n",
383+
" input_interval = batch_cfg.sample_interval_minutes.to(context.machine.torch_device)\n",
373384
" output_interval = select_rate(input_interval, config.model.output_sample_intervals_minutes)\n",
374385
"\n",
375386
" # input data to model\n",
376-
" _, loss = context.model_container.model(\n",
377-
" X, Xm, input_interval, output_interval, Y, Ym\n",
378-
" )\n",
387+
" _, loss = context.model_container.model(X, Xm, input_interval, output_interval, Y, Ym)\n",
379388
" loss.backward()\n",
380389
" total_loss += loss.item()\n",
381390
"\n",

notebooks/04_train_with_weather_time_location.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
"# Extract locations from Croissant measurements (data/LianderPower/measurements.parquet)\n",
357357
"# Snap lat/lon to a GRID (0.25°) and build `sampled_coordinates` used for sampling weather points\n",
358358
"from pathlib import Path\n",
359+
"\n",
359360
"import numpy as np\n",
360361
"import pandas as pd\n",
361362
"\n",
@@ -365,6 +366,7 @@
365366
"\n",
366367
"# Load measurements using the Croissant adapter; this returns a NumpyData with a `locations` dict\n",
367368
"from s4casting.data.dataset.croissant_adapter import load_measurements_from_croissant\n",
369+
"\n",
368370
"ndata = load_measurements_from_croissant(release_dir, to_memory=False)\n",
369371
"locs = ndata.locations\n",
370372
"\n",
@@ -391,10 +393,11 @@
391393
"# merged original ids, optional human-readable names, mean coordinate, and count.\n",
392394
"df = pd.DataFrame(rows)\n",
393395
"sampled_coordinates = (\n",
394-
" df.groupby([\"snapped_lat\", \"snapped_lon\"]) \n",
396+
" df\n",
397+
" .groupby([\"snapped_lat\", \"snapped_lon\"])\n",
395398
" .agg(\n",
396-
" merged_ids=(\"id\", lambda x: list(x)),\n",
397-
" names=(\"name\", lambda x: [n for n in dict.fromkeys([n for n in x if n])]),\n",
399+
" merged_ids=(\"id\", list),\n",
400+
" names=(\"name\", lambda x: list(dict.fromkeys([n for n in x if n]))),\n",
398401
" lat_mean=(\"lat\", \"mean\"),\n",
399402
" lon_mean=(\"lon\", \"mean\"),\n",
400403
" count=(\"id\", \"size\"),\n",
@@ -416,10 +419,7 @@
416419
"# Create interactive map showing sampled coordinates (snapped grid) and measurement points\n",
417420
"# This cell expects `sampled_coordinates` to exist in the notebook (produced above).\n",
418421
"from pathlib import Path\n",
419-
"import base64\n",
420-
"from IPython.display import HTML\n",
421-
"import folium\n",
422-
"from folium.plugins import FastMarkerCluster\n",
422+
"\n",
423423
"import pandas as pd\n",
424424
"\n",
425425
"from s4casting.data.dataset.croissant_adapter import load_measurements_from_croissant\n",
@@ -468,7 +468,7 @@
468468
" height=\"600\"\n",
469469
" style=\"border: none;\"\n",
470470
"></iframe>\n",
471-
"\"\"\")\n"
471+
"\"\"\")"
472472
]
473473
},
474474
{

0 commit comments

Comments
 (0)