snaptol.compare.compare_intelligent

snaptol.compare.compare_intelligent#

snaptol.compare.compare_intelligent(actual, expected, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#

Intelligently compare two values of any type for equality. Returns True if the values are considered equal, and False otherwise.

This function handles various Python data types and performs appropriate comparisons:

  • Floats: Uses numpy’s isclose with relative and absolute tolerances

  • Integers: Exact equality

  • Complex: Exact equality

  • Strings: Exact equality

  • Booleans: Exact equality

  • Bytes/Bytearray/Memoryview: Byte-wise equality

  • None: Identity comparison

  • NumPy arrays: Uses numpy’s allclose

  • Mapping (dict-like): Deep comparison of keys and values

  • Iterable: Order-sensitive element-wise comparison

  • Collection: Length and element-wise comparison

  • Set: Order-insensitive comparison of string representations

  • Other types: Standard equality comparison

Parameters:
  • actual (Any) – The value to compare

  • expected (Any) – The expected value to compare against

  • rtol (optional) – Relative tolerance for floating point comparisons, by default 1e-05

  • atol (optional) – Absolute tolerance for floating point comparisons, by default 1e-08

  • equal_nan (optional) – Whether to consider NaN values equal to each other, by default False

Return type:

bool