Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Oct 16, 2024
2 parents 1a5405e + d572142 commit bac32fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion premise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"clear_inventory_cache",
"get_regions_definition",
)
__version__ = (2, 1, 4)
__version__ = (2, 1, 5)


from premise.new_database import NewDatabase
Expand Down
30 changes: 20 additions & 10 deletions premise/external_data_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,17 @@ def find_candidates_by_key(data, key):
return [
item
for item in data
if item["name"] == key[0] and item["reference product"] == key[1]
if item["name"].lower() == key[0].lower()
and item["reference product"].lower() == key[1].lower()
]

def filter_candidates_by_mask(candidates, mask):
"""Exclude candidates containing the mask in their name."""
return [candidate for candidate in candidates if mask not in candidate["name"]]
return [
candidate
for candidate in candidates
if mask.lower() not in candidate["name"].lower()
]

def identify_potential_candidates(database, inventory_data, key, mask):
"""Identify and return potential candidates based on key and mask."""
Expand Down Expand Up @@ -550,14 +555,19 @@ def adjust_candidates_or_raise_error(
potential_candidates = identify_potential_candidates(
database, inventory_data, key, mask
)
candidates = adjust_candidates_or_raise_error(
potential_candidates,
scenario_data,
key,
year,
val,
inventory_data,
)

try:
candidates = adjust_candidates_or_raise_error(
potential_candidates,
scenario_data,
key,
year,
val,
inventory_data,
)
except ValueError as e:
print(key, val, potential_candidates)
print()

if duplicate_name:
for candidate in candidates:
Expand Down

0 comments on commit bac32fc

Please sign in to comment.