Skip to content

Commit a0de606

Browse files
Fix some tests
1 parent 78cdfa9 commit a0de606

File tree

14 files changed

+40
-97
lines changed

14 files changed

+40
-97
lines changed

.github/workflows/any_changes.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ jobs:
2626

2727
- name: Test documentation builds
2828
run: make documentation
29-
env:
30-
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
3129

3230
- name: Check documentation build
3331
run: |

.github/workflows/code_changes.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,4 @@ jobs:
4343
run: uv pip install .[dev] --system
4444

4545
- name: Run tests
46-
run: make test
47-
env:
48-
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
46+
run: make test

.github/workflows/publish_documentation.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ jobs:
2929

3030
- name: Build documentation
3131
run: make documentation
32-
env:
33-
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
3432

3533
- name: Deploy documentation
3634
uses: JamesIves/github-pages-deploy-action@releases/v3

.github/workflows/publish_package.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ jobs:
3636

3737
- name: Test documentation builds
3838
run: make documentation
39-
env:
40-
HUGGING_FACE_TOKEN: ${{ secrets.HUGGING_FACE_TOKEN }}
4139

4240
- name: Deploy documentation
4341
uses: JamesIves/github-pages-deploy-action@releases/v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,5 @@ cython_debug/
162162
*.ipynb
163163

164164
!docs/**/*.ipynb
165+
166+
**/*.h5

policyengine/outputs/macro/comparison/calculate_economy_comparison.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,6 @@ def uk_constituency_breakdown(
711711
reform_hnet = reform.household_net_income
712712

713713
constituency_weights_path = download(
714-
huggingface_repo="policyengine-uk-data",
715714
gcs_bucket="policyengine-uk-data-private",
716715
filepath="parliamentary_constituency_weights.h5",
717716
)
@@ -721,7 +720,6 @@ def uk_constituency_breakdown(
721720
] # {2025: array(650, 100180) where cell i, j is the weight of household record i in constituency j}
722721

723722
constituency_names_path = download(
724-
huggingface_repo="policyengine-uk-data",
725723
gcs_bucket="policyengine-uk-data-private",
726724
filepath="constituencies_2024.csv",
727725
)

policyengine/simulation.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class SimulationOptions(BaseModel):
6767
None,
6868
description="The version of the country model used in the simulation. If not provided, the current package version will be used. If provided, this package will throw an error if the package version does not match. Use this as an extra safety check.",
6969
)
70+
data_version: str | None = Field(
71+
None,
72+
description="The version of the data used in the simulation. If not provided, the current data version will be used. If provided, this package will throw an error if the data version does not match. Use this as an extra safety check.",
73+
)
7074

7175

7276
class Simulation:
@@ -133,12 +137,7 @@ def _set_data(self):
133137
bucket, filename = self.options.data.split("://")[-1].split(
134138
"/"
135139
)
136-
137-
if "@" in filename:
138-
filename, version = filename.split("@")
139-
self.data_version = version
140-
else:
141-
version = None
140+
version = self.options.data_version
142141

143142
file_path = download(
144143
filepath=filename,
@@ -267,7 +266,6 @@ def _apply_region_to_simulation(
267266
elif "constituency/" in region:
268267
constituency = region.split("/")[1]
269268
constituency_names_file_path = download(
270-
huggingface_repo="policyengine-uk-data",
271269
gcs_bucket="policyengine-uk-data-private",
272270
filepath="constituencies_2024.csv",
273271
)
@@ -288,7 +286,6 @@ def _apply_region_to_simulation(
288286
f"Constituency {constituency} not found. See {constituency_names_file_path} for the list of available constituencies."
289287
)
290288
weights_file_path = download(
291-
huggingface_repo="policyengine-uk-data",
292289
gcs_bucket="policyengine-uk-data-private",
293290
filepath="parliamentary_constituency_weights.h5",
294291
)
@@ -304,7 +301,6 @@ def _apply_region_to_simulation(
304301
elif "local_authority/" in region:
305302
la = region.split("/")[1]
306303
la_names_file_path = download(
307-
huggingface_repo="policyengine-uk-data",
308304
gcs_bucket="policyengine-uk-data-private",
309305
filepath="local_authorities_2021.csv",
310306
)
@@ -319,7 +315,6 @@ def _apply_region_to_simulation(
319315
f"Local authority {la} not found. See {la_names_file_path} for the list of available local authorities."
320316
)
321317
weights_file_path = download(
322-
huggingface_repo="policyengine-uk-data",
323318
gcs_bucket="policyengine-uk-data-private",
324319
filepath="local_authority_weights.h5",
325320
)

policyengine/utils/data/caching_google_storage_client.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ def __init__(self):
2121
def _data_key(self, bucket: str, key: str, version: str | None) -> str:
2222
return f"{bucket}.{key}.{version}.data"
2323

24-
def _get_latest_version(self, bucket: str, key: str) -> str | None:
25-
"""
26-
Get the latest version of a blob in the specified bucket and key.
27-
If no version is specified, return None.
28-
"""
29-
blob = self.client.client.get_bucket(bucket).get_blob(key)
30-
if blob.metadata is None:
31-
logging.warning(
32-
"No metadata found for blob, so it has no version attached."
33-
)
34-
return None
35-
else:
36-
return blob.metadata.get("version")
37-
3824
# To absolutely 100% avoid any possible issue with file corruption or thread contention
3925
# always replace the current target file with whatever we have cached as an atomic write.
4026
def download(
@@ -45,7 +31,7 @@ def download(
4531
"""
4632
if version is None:
4733
# If no version is specified, get the latest version from the cache
48-
version = self._get_latest_version(bucket, key)
34+
version = self.client._get_latest_version(bucket, key)
4935
logging.warning(
5036
f"No version specified for {bucket}, {key}. Using latest version: {version}"
5137
)

policyengine/utils/data/simplified_google_storage_client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@ def download(
6767
# downloading the content. As a result this should now be the crc of the downloaded
6868
# content (i.e. there is not a race condition where it's getting the CRC from the cloud)
6969
return (result, blob.crc32c)
70+
71+
def _get_latest_version(self, bucket: str, key: str) -> str | None:
72+
"""
73+
Get the latest version of a blob in the specified bucket and key.
74+
If no version is specified, return None.
75+
"""
76+
blob = self.client.get_bucket(bucket).get_blob(key)
77+
if blob.metadata is None:
78+
logging.warning(
79+
"No metadata found for blob, so it has no version attached."
80+
)
81+
return None
82+
else:
83+
return blob.metadata.get("version")

policyengine/utils/data_download.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pathlib import Path
22
import logging
33
import os
4-
from policyengine.utils.huggingface import download_from_hf
54
from policyengine.utils.google_cloud_bucket import download_file_from_gcs
65
from pydantic import BaseModel
76
import json

0 commit comments

Comments
 (0)