bw_processing.indexing
Functions
|
Utility function to get CSV data from datapackage. |
|
Use the metadata to set the integer indices in |
|
Reset the numerical indices in |
Module Contents
- bw_processing.indexing._get_csv_data(datapackage: bw_processing.datapackage.Datapackage | fsspec.AbstractFileSystem, metadata_name: str)[source]
Utility function to get CSV data from datapackage.
- Parameters:
datapackage (*) – datapackage or Filesystem. Input to load_datapackage function.
metadata_name (*) – Name identifying a CSV metadata resource in
datapackage
- Raises:
* KeyError –
metadata_nameis not indatapackage* ValueError –
metadata_nameis not CSV metadata.* KeyError – Resource referenced by CSV
valid_fornot indatapackage
- Returns:
datapackage object
pandas DataFrame with CSV data
metadata (dict) stored with dataframe
list of indices arrays reference by CSV data
indices of arrays
- bw_processing.indexing.reindex(datapackage: bw_processing.datapackage.Datapackage | fsspec.AbstractFileSystem, metadata_name: str, data_iterable: collections.abc.Iterable, fields: List[str] = None, id_field_datapackage: str = 'id', id_field_destination: str = 'id') None[source]
Use the metadata to set the integer indices in
datapackageto those used indata_iterable.Used in data exchange. Often, the integer ids provided in the data package are arbitrary, and need to be mapped to the values present in your database.
Updates the datapackage in place.
- Parameters:
datapackage (*) – datapackage of Filesystem. Input to load_datapackage function.
metadata_name (*) – Name identifying a CSV metadata resource in
datapackagedata_iterable (*) – Iterable which returns objects that support
.get().fields (*) – Optional list of fields to use while matching
id_field_datapackage (*) – String identifying the column providing an integer id in the datapackage
id_field_destination (*) – String identifying the column providing an integer id in
data_iterable
- Raises:
* KeyError –
data_iterableis missingid_field_destinationfield* KeyError –
metadata_nameis missingid_field_datapackagefield* NonUnique – Multiple objects found in
data_iterablewhich matches fields indatapackage* KeyError –
metadata_nameis not indatapackage* KeyError – No object found in
data_iterablewhich matches fields indatapackage* ValueError –
metadata_nameis not CSV metadata.* ValueError – The resources given for
metadata_nameare not present in thisdatapackage* AttributeError –
data_iterabledoesn’t support field retrieval using.get().
- Returns:
Datapackage instance with modified data
- bw_processing.indexing.reset_index(datapackage: bw_processing.datapackage.Datapackage | fsspec.AbstractFileSystem, metadata_name: str) bw_processing.datapackage.Datapackage[source]
Reset the numerical indices in
datapackageto sequential integers starting from zero.Updates the datapackage in place.
- Parameters:
datapackage (*) – datapackage or Filesystem. Input to load_datapackage function.
metadata_name (*) – Name identifying a CSV metadata resource in
datapackage
- Returns:
Datapackage instance with modified data