cfunits.Units.equals

Units.equals(other, rtol=None, atol=None, verbose=False)[source]

Tests if units are numerically convertible to equal value.

Returns True if and only if numeric values in one unit are convertible to numeric values in the other unit and their conversion is a scale factor of 1.

See also

equivalent

Parameters
other: Units

The other units.

Returns
bool

True if the units are equal, False otherwise.

Examples

>>> u = Units('km')
>>> v = Units('1000m')
>>> w = Units('100000m')
>>> u.equals(v)
True
>>> u.equals(w)
False
>>> u = Units('m s-1')
>>> m = Units('m')
>>> s = Units('s')
>>> u.equals(m)
False
>>> u.equals(m/s)
True
>>> (m/s).equals(u)
True

Undefined units are considered equal:

>>> u = Units()
>>> v = Units()
>>> u.equals(v)
True

Invalid units are not equal:

>>> Units('bad units').equals(Units('bad units'))
False