brightway-lca / brightway2-io

Importing and exporting for the Brightway LCA framework
BSD 3-Clause "New" or "Revised" License
26 stars 40 forks source link

TypeError: unhashable type: 'list' on an lcia strategy #212

Closed ccomb closed 9 months ago

ccomb commented 11 months ago

While doing ef.apply_strategies() on a custom simapro exported EF 3.1, with normalize_biosphere=False :

### Importing Environmental Footprint 3.1 (adapted) patch wtu.CSV...
Extracted 27 methods in 1.52 seconds
27 methods
281724 cfs
281724 unlinked cfs
Applying strategy: normalize_units
Applying strategy: set_biosphere_type
Applying strategy: drop_unspecified_subcategories
Applying strategy: normalize_biosphere_categories
Applying strategy: normalize_biosphere_names
Applying strategy: link_iterable_by_fields
Applying strategy: match_subcategories
Traceback (most recent call last):
  File "/home/jovyan/ecobalyse/data/import_method.py", line 62, in <module>
    main()
  File "/home/jovyan/ecobalyse/data/import_method.py", line 56, in main
    import_method()
  File "/home/jovyan/ecobalyse/data/import_method.py", line 40, in import_method
    ef.apply_strategies()
  File "/opt/conda/lib/python3.11/site-packages/bw2io/importers/base.py", line 126, in apply_strategies
    self.apply_strategy(func, verbose)
  File "/opt/conda/lib/python3.11/site-packages/bw2io/importers/base.py", line 92, in apply_strategy
    self.data = strategy(self.data)
                ^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/bw2io/strategies/lcia.py", line 306, in match_subcategories
    already_have = {(obj["name"], obj["categories"]) for obj in method["exchanges"]}
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/bw2io/strategies/lcia.py", line 306, in <setcomp>
    already_have = {(obj["name"], obj["categories"]) for obj in method["exchanges"]}
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unhashable type: 'list'
ccomb commented 11 months ago
(Pdb) [(obj["name"], obj["categories"]) for obj in method["exchanges"] if type(obj["categories"]) is list]
[('Fungicides, unspecified', ['water', 'surface water']), ('Tin (IV) oxide', ['water', 'surface water'])]

I seems the water categories are lists instead of tuples. So I guess there might be some strategy that forgot to keep the categories as tuples. Or maybe the ensure_categories_are_tuple strategy should be run at some point.