Functions#

unitstools.create_conversion(type1: Type[_T1], type2: Type[_T2], rate: Union[int, float]) Callable[[_T1], _T2]#

Creates a conversion function for the given types.

Parameters
  • type1 (Type[_T1]) – Given class inherited from Unit or IUnit to convert from.

  • type2 (Type[_T2]) – Given class inherited from Unit or IUnit to convert to.

  • rate (int | float) – Multiplier factor for the conversion, i.e. type1 = 60*type2

Returns

Function converting one unit to another.

Return type

Callable[[_T1], _T2]

unitstools.strip_unit(x: IntUnit) int#
unitstools.strip_unit(x: Unit) Union[int, float]

Strips the unit of the given Unit or IntUnit.

Parameters

x (Specified value.) – Unit | IntUnit

Returns

Float or int representing the value.

Return type

int | float

unitstools.embed_unit(x: int, unit: Type[_IU]) _IU#
unitstools.embed_unit(x: float, unit: Type[_U]) _U

Sets the given value to a specified unit.

Parameters
  • x (int | float) – Specified value.

  • unit (Type[Unit] | Type[IntUnit]) – Given class inherited from Unit or IntUnit.

Returns

Unit-imbued value.

Return type

Unit | IntUnit

unitstools.sum_iter(values: Iterable[_T1]) _T1#

Calculates sum of unit values in an iterable.

Parameters

values (list) – Values which bear an unit.

Returns

Sum of the values.

Return type

Type[Unit] | Type[IntUnit]