cfdm.mixin.Properties.equals

Properties.equals(other, rtol=None, atol=None, verbose=False, ignore_data_type=False, ignore_fill_value=False, ignore_properties=(), ignore_type=False)[source]

Whether two instances are the same.

Equality is strict by default. This means that:

  • the same descriptive properties must be present, with the same values and data types, and vector-valued properties must also have same the size and be element-wise equal (see the ignore_properties and ignore_data_type parameters).

Two real numbers x and y are considered equal if |x-y|<=atol+rtol|y|, where atol (the tolerance on absolute differences) and rtol (the tolerance on relative differences) are positive, typically very small numbers. See the atol and rtol parameters.

Any type of object may be tested but, in general, equality is only possible with another object of the same type, or a subclass of one. See the ignore_type parameter.

New in version 1.7.0.

Parameters:
other:

The object to compare for equality.

atol: float, optional

The tolerance on absolute differences between real numbers. The default value is set by the cfdm.ATOL function.

rtol: float, optional

The tolerance on relative differences between real numbers. The default value is set by the cfdm.RTOL function.

ignore_fill_value: bool, optional

If True then the “_FillValue” and “missing_value” properties are omitted from the comparison.

verbose: bool, optional

If True then print information about differences that lead to inequality.

ignore_properties: sequence of str, optional

The names of properties to omit from the comparison.

ignore_data_type: bool, optional

If True then ignore the data types in all numerical comparisons. By default different numerical data types imply inequality, regardless of whether the elements are within the tolerance for equality.

ignore_type: bool, optional

Any type of object may be tested but, in general, equality is only possible with another object of the same type, or a subclass of one. If ignore_type is True then equality is possible for any object with a compatible API.

Returns:
bool

Whether the two instances are equal.

Examples:

>>> p.equals(p)
True
>>> p.equals(p.copy())
True
>>> p.equals('not a colection of properties')
False
>>> q = p.copy()
>>> q.set_property('foo', 'bar')
>>> p.equals(q)
False
>>> p.equals(q, verbose=True)
Field: Non-common property name: foo
Field: Different properties
False