brightway-lca / brightway2-data

Tools for the management of inventory databases and impact assessment methods. Part of the Brightway LCA framework.
https://docs.brightway.dev/
BSD 3-Clause "New" or "Revised" License
8 stars 21 forks source link

Validation of ia method data fails #79

Closed pbaustert closed 3 years ago

pbaustert commented 3 years ago

Hi,

I am experiencing errors when trying to validate new method data as shown here:

https://github.com/pbaustert/bw2_reg_cfs/blob/main/notebooks/regionalisation_demo.ipynb

yielding the following error message:

MultipleInvalid: expected a list @ data[0]

I believe that this is related to the following lines:

https://github.com/brightway-lca/brightway2-data/blob/8d2e519f840ded0a700bb0d17df32e9182bb5577/bw2data/validate.py#L51-L52

Replacing lists with tuples solves the issue for me locally:

ia_validator = Schema([Any(
    (valid_tuple, maybe_uncertainty),         # site-generic
    (valid_tuple, maybe_uncertainty, object)  # regionalized
)])
pbaustert commented 3 years ago

The issue results from the load() method, which returns a list of tuples instead of a list of lists. That's why you can not validate data of an existing method:

To illustrate: the following example fails for me:

method_data = Method(('CML 2001 (obsolete)', 'acidification potential', 'generic')).load()
my_method = Method(('my method', 'a method', 'oh what a method'))
my_method.validate(method_data)

However, I don't see an easy to fix this. Closing the issue for now.