bw_simapro_csv.utils

Attributes

NO_STRINGS

RE_SPECIAL

YES_STRINGS

comma

period

Functions

add_amount_or_formula(→ dict)

Add amount or formula depending on value form

alternating_key_value(→ List[tuple])

Transform data in alternating key/value/blank rows to tuples with (key, value).

asboolean(→ bool)

Convert SimaPro strings to actual booleans

asdate(→ datetime.date)

Parse a string to a datetime.date

asnumber(→ Union[numbers.Number, str])

Take a number stored as a string and convert to a float.

get_key_multiline_values(→ tuple[str, list])

Pull off the first non-empty line, then optional empty lines, and then each data line until

get_numbers_re(→ Pattern)

get_true_length(→ int)

Computes line length, not accounting for trailing empty elements

json_serializer(obj)

jump_to_nonempty(→ list)

Skip empty rows at beginning of list

nobraces(→ str)

Remove braces from header section elements

noquotes(→ str)

Remove string start/end characters and colons

normalize_number_in_formula(→ str)

parameter_set_evaluate_each_formula(→ dict[str, float])

Do manual evaluation to catch math errors and give individual context.

skip_empty(→ Iterable)

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_numbers_re(separator: str) Pattern[source]
bw_simapro_csv.utils.get_true_length(line: list) int[source]

Computes line length, not accounting for trailing empty elements

bw_simapro_csv.utils.json_serializer(obj)[source]
bw_simapro_csv.utils.jump_to_nonempty(data: list) list[source]

Skip empty rows at beginning of list

bw_simapro_csv.utils.nobraces(s: str) str[source]

Remove braces from header section elements

bw_simapro_csv.utils.noquotes(s: str) str[source]

Remove string start/end characters and colons

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.

bw_simapro_csv.utils.skip_empty(data: list) Iterable[source]

Return iterable of nonempty lines

bw_simapro_csv.utils.NO_STRINGS[source]
bw_simapro_csv.utils.RE_SPECIAL = '.*^$+?[]\\|'[source]
bw_simapro_csv.utils.YES_STRINGS[source]
bw_simapro_csv.utils.comma[source]
bw_simapro_csv.utils.period[source]