xarray_units.utils module#

exception UnitsConversionError[source]#

Bases: UnitsError

Units conversion is not successful.

exception UnitsError[source]#

Bases: Exception

Base exception for handling units.

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 be UnitBase.

  • 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: