MCPcopy Create free account
hub / github.com/numpy/numpy / assert_equal

Function assert_equal

numpy/testing/_private/utils.py:212–369  ·  view source on GitHub ↗

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. When one of `actual` and `desired` is a

(actual, desired, err_msg='', verbose=True)

Source from the content-addressed store, hash-verified

210
211
212def assert_equal(actual, desired, err_msg='', verbose=True):
213 """
214 Raises an AssertionError if two objects are not equal.
215
216 Given two objects (scalars, lists, tuples, dictionaries or numpy arrays),
217 check that all elements of these objects are equal. An exception is raised
218 at the first conflicting values.
219
220 When one of `actual` and `desired` is a scalar and the other is array_like,
221 the function checks that each element of the array_like object is equal to
222 the scalar.
223
224 This function handles NaN comparisons as if NaN was a "normal" number.
225 That is, AssertionError is not raised if both objects have NaNs in the same
226 positions. This is in contrast to the IEEE standard on NaNs, which says
227 that NaN compared to anything must return False.
228
229 Parameters
230 ----------
231 actual : array_like
232 The object to check.
233 desired : array_like
234 The expected object.
235 err_msg : str, optional
236 The error message to be printed in case of failure.
237 verbose : bool, optional
238 If True, the conflicting values are appended to the error message.
239
240 Raises
241 ------
242 AssertionError
243 If actual and desired are not equal.
244
245 Examples
246 --------
247 >>> np.testing.assert_equal([4,5], [4,6])
248 Traceback (most recent call last):
249 ...
250 AssertionError:
251 Items are not equal:
252 item=1
253 ACTUAL: 5
254 DESIRED: 6
255
256 The following comparison does not raise an exception. There are NaNs
257 in the inputs, but they are in the same positions.
258
259 >>> np.testing.assert_equal(np.array([1.0, 2.0, np.nan]), [1, 2, np.nan])
260
261 """
262 __tracebackhide__ = True # Hide traceback for py.test
263 if isinstance(desired, dict):
264 if not isinstance(actual, dict):
265 raise AssertionError(repr(type(actual)))
266 assert_equal(len(actual), len(desired), err_msg, verbose)
267 for k, i in desired.items():
268 if k not in actual:
269 raise AssertionError(repr(k))

Callers 15

test_seedsequenceFunction · 0.90
test_rawMethod · 0.90
test_uniform_doubleMethod · 0.90
test_uniform_floatMethod · 0.90
test_pickleMethod · 0.90
test_state_tupleMethod · 0.90
test_scalarMethod · 0.90
test_arrayMethod · 0.90
test_sizeMethod · 0.90
test_pickleMethod · 0.90

Calls 7

iscomplexobjFunction · 0.90
realFunction · 0.90
imagFunction · 0.90
isscalarFunction · 0.90
build_err_msgFunction · 0.85
isnanFunction · 0.85
assert_array_equalFunction · 0.70

Tested by 15

test_seedsequenceFunction · 0.72
test_rawMethod · 0.72
test_uniform_doubleMethod · 0.72
test_uniform_floatMethod · 0.72
test_pickleMethod · 0.72
test_state_tupleMethod · 0.72
test_scalarMethod · 0.72
test_arrayMethod · 0.72
test_sizeMethod · 0.72
test_pickleMethod · 0.72