Raises an AssertionError if two objects are not equal. Given two objects (scalars, lists, tuples, dictionaries or numpy arrays), check that all elements of these objects are equal. An exception is raised at the first conflicting values. This function handles NaN comparisons as
(actual, desired, err_msg='', verbose=True, *, strict=False)
| 258 | |
| 259 | |
| 260 | def assert_equal(actual, desired, err_msg='', verbose=True, *, strict=False): |
| 261 | """ |
| 262 | Raises an AssertionError if two objects are not equal. |
| 263 | |
| 264 | Given two objects (scalars, lists, tuples, dictionaries or numpy arrays), |
| 265 | check that all elements of these objects are equal. An exception is raised |
| 266 | at the first conflicting values. |
| 267 | |
| 268 | This function handles NaN comparisons as if NaN was a "normal" number. |
| 269 | That is, AssertionError is not raised if both objects have NaNs in the same |
| 270 | positions. This is in contrast to the IEEE standard on NaNs, which says |
| 271 | that NaN compared to anything must return False. |
| 272 | |
| 273 | Parameters |
| 274 | ---------- |
| 275 | actual : array_like |
| 276 | The object to check. |
| 277 | desired : array_like |
| 278 | The expected object. |
| 279 | err_msg : str, optional |
| 280 | The error message to be printed in case of failure. |
| 281 | verbose : bool, optional |
| 282 | If True, the conflicting values are appended to the error message. |
| 283 | strict : bool, optional |
| 284 | If True and either of the `actual` and `desired` arguments is an array, |
| 285 | raise an ``AssertionError`` when either the shape or the data type of |
| 286 | the arguments does not match. If neither argument is an array, this |
| 287 | parameter has no effect. |
| 288 | |
| 289 | .. versionadded:: 2.0.0 |
| 290 | |
| 291 | Raises |
| 292 | ------ |
| 293 | AssertionError |
| 294 | If actual and desired are not equal. |
| 295 | |
| 296 | See Also |
| 297 | -------- |
| 298 | assert_allclose |
| 299 | assert_array_almost_equal_nulp, |
| 300 | assert_array_max_ulp, |
| 301 | |
| 302 | Notes |
| 303 | ----- |
| 304 | When one of `actual` and `desired` is a scalar and the other is array_like, the |
| 305 | function checks that each element of the array_like is equal to the scalar. |
| 306 | Note that empty arrays are therefore considered equal to scalars. |
| 307 | This behaviour can be disabled by setting ``strict==True``. |
| 308 | |
| 309 | Examples |
| 310 | -------- |
| 311 | >>> np.testing.assert_equal([4, 5], [4, 6]) |
| 312 | Traceback (most recent call last): |
| 313 | ... |
| 314 | AssertionError: |
| 315 | Items are not equal: |
| 316 | item=1 |
| 317 | ACTUAL: 5 |
searching dependent graphs…