Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom regex functionality to split_simapro_name_geo() #264

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions bw2io/strategies/simapro.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

# Pattern for SimaPro munging of ecoinvent names
detoxify_pattern = "^(?P<name>.+?)/(?P<geo>[A-Za-z]{2,10})(/I)? [SU]$"
detoxify_re = re.compile(detoxify_pattern)


def functional(exc: dict) -> bool:
Expand Down Expand Up @@ -350,7 +349,7 @@ def link_technosphere_based_on_name_unit_location(db, external_db_name=None):
)


def split_simapro_name_geo(db):
def split_simapro_name_geo(db, regex_string=detoxify_pattern):
"""
Split a name like 'foo/CH U' into name and geo components in a dataset.

Expand All @@ -363,6 +362,9 @@ def split_simapro_name_geo(db):
db : list
A list of dictionaries representing datasets with names to be split.

regex_string : str
A regex pattern to split names. Defaults to a routine to split ecoinvent names.

Returns
-------
db : list
Expand Down Expand Up @@ -390,6 +392,7 @@ def split_simapro_name_geo(db):
},
]
"""
detoxify_re = re.compile(regex_string)
for ds in db:
match = detoxify_re.match(ds["name"])
if match:
Expand Down