bw2data.query
#
Module Contents#
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#
|
Shortcut for a name filter |
|
Shortcut for a reference product filter |
|
Attributes#
- 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")
- Args:
key (str): The field to filter on.
function (str or object): One of the pre-defined filters, or a callable object.
value (object): 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.- Args:
filters (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
.- Args:
result (dict): The filtered dataset.