piel.units.string#

Functions#

prefix2int(→ int)

Converts a string with a number and optional suffix into an integer.

match_unit_abbreviation(→ piel.types.units.Unit)

Matches a unit string to a predefined Unit instance.

Module Contents#

prefix2int(s: str) int[source]#

Converts a string with a number and optional suffix into an integer.

Supported suffixes:

‘k’ or ‘K’ - Thousand ‘m’ or ‘M’ - Million ‘b’ or ‘B’ - Billion ‘t’ or ‘T’ - Trillion

Examples

‘17.03k’ -> 17030 ‘17K’ -> 17000 ‘2.5M’ -> 2500000 ‘500’ -> 500 ‘-3.2B’ -> -3200000000

Parameters:

s (str) – The string to convert.

Returns:

The integer representation of the input string.

Return type:

int

Raises:

ValueError – If the string format is invalid or contains unsupported suffixes.

match_unit_abbreviation(unit_str: str) piel.types.units.Unit[source]#

Matches a unit string to a predefined Unit instance.

Parameters:

unit_str (str) – The unit abbreviation extracted from a column name (e.g., “s”, “v”, “dB”).

Returns:

The corresponding Unit instance.

Return type:

Unit

Raises:

ValueError – If the unit string does not match any predefined units.