xarray_units.utils module#
- exception UnitsConversionError[source]#
Bases:
UnitsError
Units conversion is not successful.
- exception UnitsExistError[source]#
Bases:
UnitsError
Units already exist in a DataArray.
- exception UnitsNotFoundError[source]#
Bases:
UnitsError
Units do not exist in a DataArray.
- exception UnitsNotValidError[source]#
Bases:
UnitsError
Units 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
None
as 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
format
is given but units cannot be formatted to it.UnitsNotFoundError – Raised if
strict
isTrue
but units do not exist in the object.UnitsNotValidError – Raised if units exist in the object but they cannot be converted to
UnitBase
.