Search code examples
brightway

'location' filter on database.search filtering everything


I have imported the ecoinvent database as ei

The search function works quite well:

In[0]   eidb.search("glass", 
                     filter = {'name':'green', 
                               'product':'packaging'
                              }
                     )
Excluding 296 filtered results

Out[0]:
['packaging glass production, green' (kilogram, RER w/o CH+DE, None),
 'packaging glass production, green' (kilogram, DE, None),
 'packaging glass production, green' (kilogram, RoW, None),
 'packaging glass production, green' (kilogram, CH, None),
 'packaging glass production, green, without cullet' (kilogram, GLO, None),
 'market for packaging glass, green' (kilogram, GLO, None)]

This is exactly as one would hope.

However, filtering on 'location' does not work so well:

In[1]   eidb.search("glass", 
                     filter = {'location':'DE', 
                              }
                     )
Excluding 304 filtered results

Out[1]: []

According to the above result, I should have at least two results. 'location' is definitely an accepted filter, and DE is definitely one of the locations (e.g. eidb.get('d2db85e14baf9e47bdbb824797420f08').get('location') returns DE).

I observe this anytime location is used as filter, e.g. eidb.search('*', filter = {'location':'CA-QC'}) returns an empty list.

Why?


Solution

  • I have no idea why this is occurring, but you can get the behaviour you are looking for by putting the location code in lowercase:

    In [1]: db.search("glass", filter={"location": "de"})
    Excluding 103 filtered results
    Out[1]:
    ['glass tube plant' (unit, DE, ['glass', 'construction']),
     'glass tube, borosilicate, at plant' (kilogram, DE, ['glass', 'construction']),
     'packaging glass, white, at plant' (kilogram, DE, ['glass', 'packaging']),
     'packaging glass, brown, at plant' (kilogram, DE, ['glass', 'packaging']),
     'packaging glass, green, at plant' (kilogram, DE, ['glass', 'packaging']),
     'solar collector glass tube, with silver mirror, at plant' (kilogram, DE, ['glass', 'construction']),
     'photovoltaic laminate, CdTe, at plant' (square meter, DE, ['photovoltaic', 'production of components'])]
    

    Please file this as a bug for bw2data.