saiunit.has_same_unit

Contents

saiunit.has_same_unit#

saiunit.has_same_unit(obj1, obj2)#

Check whether two objects have the same unit.

Compares the underlying units mathematically (dim, scale, base, factor) — alias spellings and display-name differences are ignored. For strict identity-level equality use Unit.__eq__ directly.

Parameters:
  • obj1 ({Quantity, Unit, array-like, number}) – The first value.

  • obj2 ({Quantity, Unit, array-like, number}) – The second value.

Returns:

sameTrue if obj1 and obj2 have the same unit.

Return type:

bool

See also

have_same_dim

Check whether two objects share the same dimension.

is_unit_equal_math

Same-math comparison for Unit objects directly.

Examples

>>> import saiunit as u
>>> u.has_same_unit(1.0 * u.mV, 2.0 * u.mV)
True
>>> u.has_same_unit(1.0 * u.mV, 2.0 * u.volt)
False
>>> u.has_same_unit(1.0, 2.0)
True