bw2data.backends.utils#

Functions#

check_exchange(exc)

Check exchange data validity when processing

convert_backend(database_name, backend)

Convert a Database to another backend.

dict_as_activitydataset(→ dict)

dict_as_exchangedataset(→ dict)

get_csv_data_dict(ds)

get_obj_as_dict(→ dict)

Loads an object's data from the database as a dictionary.

replace_cfs(old_key, new_key)

Replace old_key with new_key in characterization factors.

retupleize_geo_strings(value)

Transform data from SQLite representation to Python objects.

Module Contents#

bw2data.backends.utils.check_exchange(exc)[source]#

Check exchange data validity when processing

bw2data.backends.utils.convert_backend(database_name, backend)[source]#

Convert a Database to another backend.

bw2data currently supports the default and json backends.

Parameters:
  • database_name (*) – Name of database.

  • backend (*) – Type of database. backend should be recoginized by DatabaseChooser.

Returns False if the old and new backend are the same. Otherwise returns an instance of the new Database object.

bw2data.backends.utils.dict_as_activitydataset(ds: Any, add_snowflake_id: bool = False) dict[source]#
bw2data.backends.utils.dict_as_exchangedataset(ds: Any) dict[source]#
bw2data.backends.utils.get_csv_data_dict(ds)[source]#
bw2data.backends.utils.get_obj_as_dict(cls: bw2data.signals.SignaledDataset, obj_id: int | None) dict[source]#

Loads an object’s data from the database as a dictionary.

The format used is that of the serialization of revisions (see also the dict_as_* functions above); in particular, an empty dictionary is returned if the ID is None (but not if the object does not exist).

bw2data.backends.utils.replace_cfs(old_key, new_key)[source]#

Replace old_key with new_key in characterization factors.

Returns list of modified methods.

bw2data.backends.utils.retupleize_geo_strings(value)[source]#

Transform data from SQLite representation to Python objects.

We are using a SQLite3 cursor, which means that the Peewee data conversion code is not called. So ('foo', 'bar') is stored as a string, not a tuple. This code tries to do this conversion correctly.

TODO: Adapt what Peewee does in this case?