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

TypeError: unsupported operand type(s) for ^: 'float' and 'int #156

Closed
ccomb opened this issue Mar 1, 2023 · 1 comment
Closed

TypeError: unsupported operand type(s) for ^: 'float' and 'int #156

ccomb opened this issue Mar 1, 2023 · 1 comment

Comments

@ccomb
Copy link
Contributor

ccomb commented Mar 1, 2023

Trying to import AGB 3.1.1 from the SimaproCSV:

Traceback (most recent call last):
  File "/home/.../import_agb311.py", line 62, in <module>
    agb_importer = bw.SimaProCSVImporter(agb_csv_filepath, "agribalyse3.1")
  File "/home/.../brightway2-io/bw2io/importers/simapro_csv.py", line 45, in __init__
    self.data, self.global_parameters, self.metadata = SimaProCSVExtractor.extract(
  File "/home/.../brightway2-io/bw2io/extractors/simapro_csv.py", line 120, in extract
    ds, index = cls.read_data_set(
  File "/home/.../brightway2-io/bw2io/extractors/simapro_csv.py", line 514, in read_data_set
    cls.parse_input_line(data[index], category, pm)
  File "/home/.../brightway2-io/bw2io/extractors/simapro_csv.py", line 358, in parse_input_line
    is_formula = not isinstance(to_number(amount), Number)
  File "/home/.../brightway2-io/bw2io/extractors/simapro_csv.py", line 54, in to_number
    return float(eval(obj.replace(",", ".").strip()))
  File "<string>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'float' and 'int'

A debugging session leads to the problem: 10^6 cannot be evaluated by Python's eval:

> /home/dadafkas/prelab/ecobalyse/brightway/brightway2-io/bw2io/extractors/simapro_csv.py(59)to_number()->None
-> import pdb; pdb.set_trace()  # fmt: skip
(Pdb) float(eval(obj.replace(",", ".").strip()))
*** TypeError: unsupported operand type(s) for ^: 'float' and 'int'
(Pdb) obj.replace(",", ".")
'(38-15)*4185*30/0.9*10^-6'
ccomb added a commit to ccomb/brightway2-io that referenced this issue Mar 1, 2023
@ccomb
Copy link
Contributor Author

ccomb commented Mar 1, 2023

Looks like what I did is the job of normalize_simapro_formulae, but how can this strategy be applied during import?

@cmutel cmutel closed this as completed in cd41635 Mar 3, 2023
cmutel added a commit that referenced this issue Mar 3, 2023
Support '10^' as '10E' (fix #156)
ccomb added a commit to ccomb/brightway2-io that referenced this issue Mar 7, 2023
ccomb added a commit to ccomb/brightway2-io that referenced this issue Mar 10, 2023
ccomb added a commit to ccomb/brightway2-io that referenced this issue Mar 17, 2023
@ccomb ccomb mentioned this issue Mar 17, 2023
ccomb added a commit to ccomb/brightway2-io that referenced this issue Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant