xarray_units.utils module#
- exception UnitsConversionError[source]#
Bases:
UnitsErrorUnits conversion is not successful.
- exception UnitsExistError[source]#
Bases:
UnitsErrorUnits already exist in a DataArray.
- exception UnitsNotFoundError[source]#
Bases:
UnitsErrorUnits do not exist in a DataArray.
- exception UnitsNotValidError[source]#
Bases:
UnitsErrorUnits are not valid for a DataArray.
- unitsof(obj: Any, /, *, format: None = None, strict: Literal[False] = False, **kwargs: Any) UnitBase | None[source]#
- unitsof(obj: Any, /, *, format: str, strict: Literal[False] = False, **kwargs: Any) str | None
- unitsof(obj: Any, /, *, format: None = None, strict: Literal[True] = True, **kwargs: Any) UnitBase
- unitsof(obj: Any, /, *, format: str, strict: Literal[True] = True, **kwargs: Any) str
Return units of an object if they exist and are valid.
- Parameters:
obj – Any object from which units are extracted.
format – Format of units. If given, the return value will be
string. Otherwise, it will beUnitBase.strict – Whether to allow
Noneas the return value when units do not exist in the object.**kwargs – Keyword arguments of the formatting.
- Returns:
Extracted units from the object.
- Raises:
UnitsConversionError – Raised if
formatis given but units cannot be formatted to it.UnitsNotFoundError – Raised if
strictisTruebut units do not exist in the object.UnitsNotValidError – Raised if units exist in the object but they cannot be converted to
UnitBase.