bw_simapro_csv.utils
Attributes
Functions
|
Add amount or formula depending on value form |
|
Transform data in alternating key/value/blank rows to tuples with (key, value). |
|
Convert SimaPro strings to actual booleans |
|
Parse a string to a datetime.date |
|
Take a number stored as a string and convert to a float. |
|
Pull off the first non-empty line, then optional empty lines, and then each data line until |
|
|
|
Computes line length, not accounting for trailing empty elements |
|
|
|
Skip empty rows at beginning of list |
|
Remove braces from header section elements |
|
Remove string start/end characters and colons |
|
|
|
Do manual evaluation to catch math errors and give individual context. |
|
Return iterable of nonempty lines |
Module Contents
- bw_simapro_csv.utils.add_amount_or_formula(data: dict, value: str, decimal_separator: str, amount_key: str = 'amount', formula_key: str = 'formula') dict[source]
Add amount or formula depending on value form
- bw_simapro_csv.utils.alternating_key_value(data: List[list]) List[tuple][source]
Transform data in alternating key/value/blank rows to tuples with (key, value).
For example, turn:
Foo bar; baz
Into:
`python [("Foo", ["bar", "baz"])] `
- bw_simapro_csv.utils.asboolean(s: str, allow_nonboolean: bool = False) bool[source]
Convert SimaPro strings to actual booleans
- bw_simapro_csv.utils.asdate(value: str, dayfirst: bool = True) datetime.date[source]
Parse a string to a datetime.date
- bw_simapro_csv.utils.asnumber(value: str | numbers.Number, decimal_separator: str = '.', allow_nonnumber: bool = False) numbers.Number | str[source]
Take a number stored as a string and convert to a float.
Tries hard to handle different formats.
- bw_simapro_csv.utils.get_key_multiline_values(block: list[tuple], stop_terms: Iterable) tuple[str, list][source]
Pull off the first non-empty line, then optional empty lines, and then each data line until an empty line
- bw_simapro_csv.utils.get_true_length(line: list) int[source]
Computes line length, not accounting for trailing empty elements
- bw_simapro_csv.utils.jump_to_nonempty(data: list) list[source]
Skip empty rows at beginning of list
- bw_simapro_csv.utils.normalize_number_in_formula(formula: str, decimal_separator: str = '.') str[source]
- bw_simapro_csv.utils.parameter_set_evaluate_each_formula(ps: bw2parameters.ParameterSet) dict[str, float][source]
Do manual evaluation to catch math errors and give individual context.
Copied from https://github.com/brightway-lca/brightway2-parameters/blob/main/bw2parameters/parameter_set.py.