Skip to content

Commit f9187fa

Browse files
romainsacchiromainsacchi
authored andcommitted
Merge remote-tracking branch 'origin/main'
2 parents 09a7535 + 6c87165 commit f9187fa

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

pathways/pathways.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ def _load_array(filepath):
8181
elif Path(filepath[0]).suffix == ".json":
8282
with open(filepath[0], encoding="utf-8") as f:
8383
payload = json.load(f)
84-
return {
85-
tuple(item["activity"]): int(item["index"])
86-
for item in payload
87-
}
84+
return {tuple(item["activity"]): int(item["index"]) for item in payload}
8885
elif Path(filepath[0]).suffix == ".pkl":
8986
if not ALLOW_UNSAFE_PICKLE:
9087
raise ValueError(

pathways/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ def load_units_conversion() -> dict:
239239
with open(UNITS_CONVERSION, "r") as f:
240240
data = yaml.safe_load(f)
241241
if not isinstance(data, dict):
242-
raise ValueError("Invalid units conversion mapping: expected a YAML dictionary.")
242+
raise ValueError(
243+
"Invalid units conversion mapping: expected a YAML dictionary."
244+
)
243245

244246
return data
245247

@@ -508,7 +510,9 @@ def clean_cache_directory():
508510
f"Expected: {allowed_dir}. Set PATHWAYS_ALLOW_UNSAFE_CACHE_DELETE=1 to override."
509511
)
510512
if not cache_dir.exists() or not cache_dir.is_dir():
511-
raise ValueError(f"Cache directory does not exist or is not a directory: {cache_dir}")
513+
raise ValueError(
514+
f"Cache directory does not exist or is not a directory: {cache_dir}"
515+
)
512516

513517
allowed_suffixes = {".npy", ".npz", ".json", ".pkl"}
514518
removed = 0
@@ -793,7 +797,9 @@ def csv_to_dict(filename: str) -> dict[int, tuple[str, ...]]:
793797
output_dict[int(value)] = key
794798
except ValueError:
795799
logging.warning(
796-
"Row %s has a non-integer index value '%s'; skipping.", row, value
800+
"Row %s has a non-integer index value '%s'; skipping.",
801+
row,
802+
value,
797803
)
798804
else:
799805
logging.warning(f"Row {row} has less than 5 items.")

tests/test_utilities.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ def test_clean_cache_directory(tmp_path, monkeypatch):
188188

189189
clean_cache_directory()
190190

191-
assert not (cache_dir / "temp_cache_file.npy").exists(), "Cache file was not deleted"
191+
assert not (
192+
cache_dir / "temp_cache_file.npy"
193+
).exists(), "Cache file was not deleted"
192194
assert (
193195
non_cache_dir / "temp_non_cache_file"
194196
).exists(), "Non-cache file was incorrectly deleted"
@@ -207,7 +209,12 @@ def test_clean_cache_directory_rejects_unsafe_path(tmp_path, monkeypatch):
207209
def test_apply_filters_path_matching_is_not_character_based():
208210
technosphere = {("alpha plant", "prod", "EU", "kg"): 1}
209211
filters = {"name_fltr": [], "name_mask": [], "product_fltr": [], "product_mask": []}
210-
exceptions = {"name_fltr": [], "name_mask": [], "product_fltr": [], "product_mask": []}
212+
exceptions = {
213+
"name_fltr": [],
214+
"name_mask": [],
215+
"product_fltr": [],
216+
"product_mask": [],
217+
}
211218
paths = [["ab"]]
212219

213220
_, _, filtered_names, _ = apply_filters(technosphere, filters, exceptions, paths)

0 commit comments

Comments
 (0)