Skip to content

Commit

Permalink
Convert exponent (fix brightway-lca#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomb committed Mar 7, 2023
1 parent f5c9d28 commit c2ab8aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bw2io/extractors/simapro_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def to_number(obj):
return float(obj.replace("%", "").strip()) / 100.0
try:
# Eval for simple expressions like "1/2"
return float(eval(obj.replace(",", ".").strip()))
return float(eval(obj.replace(",", ".").replace("^", "**").strip()))
except NameError:
# Formula with a variable which isn't in scope - raises NameError
return obj
Expand Down
6 changes: 6 additions & 0 deletions tests/simapro.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get_biosphere_2_3_category_migration_data,
get_biosphere_2_3_name_migration_data,
)
from bw2io.extractors.simapro_csv import to_number

# from bw2data.utils import recursive_str_to_unicode as _
# from stats_arrays import UndefinedUncertainty, NoUncertainty
Expand Down Expand Up @@ -114,6 +115,11 @@ def test_set_lognormal_loc_value_on_import():
assert np.abs(loc - np.log(amount)) < 1e-10


@bw2test
def test_to_number():
assert to_number("(38-15)*4185*30/0.9*10^-6") == 32.085


class SimaProCSVImporterTest(BW2DataTest):
# def extra_setup(self):
# # SimaPro importer always wants biosphere database
Expand Down

0 comments on commit c2ab8aa

Please sign in to comment.