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
Query
to 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
name
values are βfooβ:Filter("name", "is", "foo")
All
name
values 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
Result
object 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
Query
object, and passing the dataset to filter as the argument. Calling aQuery
with some data returns aResult
object with the filtered dataset.- Parameters:
filters (*) β One or more
Filter
objects.
- class bw2data.query.Result(result)[source]#
A container that wraps a filtered dataset. Returned by a calling a
Query
object. 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.