Skip to content

Commit

Permalink
Support '10^' as '10E' (fix #156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccomb committed Mar 1, 2023
1 parent b247347 commit e2a55aa
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 @@ -57,7 +57,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("10^", "10E").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 @@ -17,6 +17,7 @@
get_biosphere_2_3_name_migration_data,
get_default_units_migration_data,
)
from bw2io.extractors.simapro_csv import to_number

SP_FIXTURES_DIR = os.path.join(os.path.dirname(__file__), "fixtures", "simapro")

Expand Down Expand Up @@ -122,6 +123,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 e2a55aa

Please sign in to comment.