brightway-lca / brightway2-io

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

Issue when importing CSV inventories #131

Closed romainsacchi closed 2 years ago

romainsacchi commented 2 years ago

The import of CSV inventory files using bw2io.CSVImporter() fails.

For example, using the CSV located at : https://raw.githubusercontent.com/brightway-lca/brightway2-io/master/bw2io/data/examples/example.csv

fp = "lci-example.csv"
i = bw2io.CSVImporter(fp)

throws the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [3], in <cell line: 2>()
      1 fp = "lci-example.csv"
----> 2 i = bw2io.CSVImporter(fp)

File ~/GitHub/brightway2-io/bw2io/importers/excel.py:109, in ExcelImporter.__init__(self, filepath)
    105 start = time()
    106 data = self.extractor.extract(filepath)
--> 109 data = [(x, y) for x, y in data if valid_first_cell(x, y)]
    110 print(
    111     "Extracted {} worksheets in {:.2f} seconds".format(
    112         len(data), time() - start
    113     )
    114 )
    115 if data and any(line for line in data):

File ~/GitHub/brightway2-io/bw2io/importers/excel.py:109, in <listcomp>(.0)
    105 start = time()
    106 data = self.extractor.extract(filepath)
--> 109 data = [(x, y) for x, y in data if valid_first_cell(x, y)]
    110 print(
    111     "Extracted {} worksheets in {:.2f} seconds".format(
    112         len(data), time() - start
    113     )
    114 )
    115 if data and any(line for line in data):

ValueError: too many values to unpack (expected 2)

It seems it is expecting to receive items of length of 2 when iterating over data, but items in data have a length superior to 2.

cmutel commented 2 years ago

Fixed in 62669e3bab04e18e75ad1e4764bb86fb0fc8e4a1