SpecialUnitRegistry
¶
SpecialUnitRegistry(*args: tuple[Any, ...], **kwargs: dict[str, Any])
Bases: UnitRegistry
A special pint.UnitRegistry subclass that includes methods for handling currency units and conversion using pydeflate.
This constructor creates a new SpecialUnitRegistry object,
inheriting all default behaviors from pint.UnitRegistry.
It also defines a reference currency unit (USD_2020) for
handling currency conversions and related operations.
Parameters:
-
*args(tuple, default:()) –Positional arguments passed to the base
pint.UnitRegistryconstructor. -
**kwargs(dict, default:{}) –Keyword arguments passed to the base
pint.UnitRegistryconstructor.
Methods:
-
ensure_currency_is_unit–Ensure that all currency units in the given string are valid units in the registry.
-
get_reference_currency–Get the reference currency from the unit registry.
ensure_currency_is_unit
¶
ensure_currency_is_unit(units: str) -> None
Ensure that all currency units in the given string are valid units in the registry.
Extracts all currency-like strings from the input and checks if they are defined in the unit registry. If they are not defined, they are added as valid units relative to the reference currency but without a conversion factor.
Parameters:
-
units(str) –The units string to check for currency units.
Examples:
>>> ureg.ensure_currency_is_unit("USD_2020/kW")
>>> ureg.ensure_currency_is_unit("EUR_2015/USD_2020")
get_reference_currency
¶
get_reference_currency() -> str
Get the reference currency from the unit registry.