brightway-lca / brightway2-calc

The calculation engine for the Brightway2 life cycle assessment framework.
BSD 3-Clause "New" or "Revised" License
12 stars 15 forks source link

redo_lci and redi_lcia fail if not supplied a demand argument #26

Closed aleksandra-kim closed 4 years ago

aleksandra-kim commented 4 years ago

Original report by Pascal Lesage (Bitbucket: MPa, ).


Despite apparently accepting demand=None, LCA.redo_lci() and LCA.redo_lcia() will fail if no demand argument is provided.

>>> import brightway2 as bw
>>> lca = bw.LCA({('some', 'act'):1})
>>> lca.lci()
>>> lca.redo_lci()

Traceback (most recent call last):
  File "C:\mypy\anaconda\envs\bw2020\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-25-82c6d21a2d04>", line 1, in <module>
    lca.redo_lci()
  File "C:\mypy\anaconda\envs\bw2020\lib\site-packages\bw2calc\lca.py", line 516, in redo_lci
    self.logger.info("Redoing LCI", extra={'demand': wrap_functional_unit(demand or self.demand)})
  File "C:\mypy\anaconda\envs\bw2020\lib\site-packages\bw2calc\utils.py", line 219, in wrap_functional_unit
    for key, amount in dct.items():
AttributeError: 'NoneType' object has no attribute 'items'

The problem is here (): and here. The line self.demand = demand should be in the if block.

I will provide a PR if there is no objection.

aleksandra-kim commented 4 years ago

Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).


Fixed in 64cfb0d.