Generic equality function that raises an ``AssertionError`` if the objects are not equal. Notes ----- Works with pandas.DataFrame, pandas.Series, numpy.ndarray, str, int, float, bool, None, or a dictionary or list of such items, with arbitrary nesting of dictionaries and lists.
(
actual,
expected,
ignore_list_order=False,
rel=1e-5,
dict_path="",
ignore_keys=None,
**kwargs)
| 207 | |
| 208 | |
| 209 | def assert_equal( |
| 210 | actual, |
| 211 | expected, |
| 212 | ignore_list_order=False, |
| 213 | rel=1e-5, |
| 214 | dict_path="", |
| 215 | ignore_keys=None, |
| 216 | **kwargs): |
| 217 | """Generic equality function that raises an ``AssertionError`` if the objects are not equal. |
| 218 | |
| 219 | Notes |
| 220 | ----- |
| 221 | Works with pandas.DataFrame, pandas.Series, numpy.ndarray, str, int, float, |
| 222 | bool, None, or a dictionary or list of such items, with arbitrary nesting |
| 223 | of dictionaries and lists. |
| 224 | |
| 225 | Does not check equivalence of functions, or work with nested numpy arrays. |
| 226 | |
| 227 | Parameters |
| 228 | ---------- |
| 229 | actual : `pandas.DataFrame`, `pandas.Series`, `numpy.array`, `str`, `int`, |
| 230 | `float`, `bool`, `None`, or a dictionary or list of such items |
| 231 | Actual value. |
| 232 | expected : `pandas.DataFrame`, `pandas.Series`, `numpy.array`, `str`, `int`, |
| 233 | `float`, `bool`, `None`, or a dictionary or list of such items |
| 234 | Expected value to compare against. |
| 235 | ignore_list_order : `bool`, optional, default False |
| 236 | If True, lists are considered equal if they contain the same elements. This option is valid |
| 237 | only if the list can be sorted (all elements can be compared to each other). |
| 238 | If False, lists are considered equal if they contain the same elements in the same order. |
| 239 | rel : `float`, optional, default 1e-5 |
| 240 | To check int and float, passed to ``rel`` argument of `pytest.approx`. |
| 241 | To check numpy arrays, passed to ``rtol`` argument of |
| 242 | `numpy.testing.assert_allclose`. |
| 243 | To check pandas dataframe, series, and index, passed to ``rtol`` argument of |
| 244 | `pandas.testing.assert_frame_equal`, `pandas.testing.assert_series_equal`, |
| 245 | `pandas.testing.assert_index_equal`. |
| 246 | dict_path : `str`, optional, default "" |
| 247 | Location within nested dictionary of the original call to this function. |
| 248 | User should not set this parameter. |
| 249 | ignore_keys : `dict`, optional, default None |
| 250 | Keys to ignore in equality comparison. This only applies if |
| 251 | `expected` is a dictionary. |
| 252 | Does not compare the values of these keys. However, |
| 253 | still returns false if the key is not present. |
| 254 | |
| 255 | Can be a nested dictionary. Terminal keys are those whose values should |
| 256 | not be compared. |
| 257 | |
| 258 | |
| 259 | If the expected value is an nested dictionary, this dictionary can |
| 260 | also be nested, with the same structure. |
| 261 | For example, if expected: |
| 262 | expected = { |
| 263 | "k1": { |
| 264 | "k1": 1, |
| 265 | "k2": [1, 2, 3], |
| 266 | } |
no outgoing calls