bw2data.query#
Attributes#
Classes#
Pretends to be a single dictionary when applying a |
|
A filter on a dataset. |
|
A container for a set of filters applied to a dataset. |
|
A container that wraps a filtered dataset. Returned by a calling a |
Functions#
Module Contents#
- class bw2data.query.Dictionaries(*args)[source]#
Pretends to be a single dictionary when applying a
Queryto multiple databases.- Usage:
first_database = Database(…).load() second_database = Database(…).load() my_joined_dataset = Dictionaries(first_database, second_database) search_results = Query(filter_1, filter_2)(my_joined_dataset)
- class bw2data.query.Filter(key, function, value)[source]#
A filter on a dataset.
The following functions are supported:
“<”, “<=”, “==”, “>”, “>=”: Mathematical relations
“is”, “not”: Identity relations. Work on any Python object.
“in”, “notin”: List or string relations.
“iin”, “iis”, “inot”: Case-insensitive string relations.
“len”: Length relation.
In addition, any function which defines a relationship between an input and an output can also be used.
Examples
All
namevalues are “foo”:Filter("name", "is", "foo")All
namevalues include the string “foo”:Filter("name", "has", "foo")Category (a list of categories and subcategories) includes “foo”:
Filter("category", "has", "foo")
- Parameters:
key (*) – The field to filter on.
function (*) – One of the pre-defined filters, or a callable object.
value (*) – The value to test against.
- Returns:
A
Resultobject which wraps a new data dictionary.
- class bw2data.query.Query(*filters)[source]#
A container for a set of filters applied to a dataset.
Filters are applied by calling the
Queryobject, and passing the dataset to filter as the argument. Calling aQuerywith some data returns aResultobject with the filtered dataset.- Parameters:
filters (*) – One or more
Filterobjects.
- class bw2data.query.Result(result)[source]#
A container that wraps a filtered dataset. Returned by a calling a
Queryobject. A result object functions like a read-only dictionary; you can callResult[some_key], orsome_key in Result, orlen(Result).The dataset can also be sorted, using
sort(field); the underlying data is then acollections.OrderedDict.- Parameters:
result (*) – The filtered dataset.