MCPcopy Create free account
hub / github.com/ColdGrub1384/Pyto / assert_numpy_array_equal

Function assert_numpy_array_equal

site-packages/pandas/util/testing.py:1098–1171  ·  view source on GitHub ↗

Checks that 'np.ndarray' is equivalent Parameters ---------- left : np.ndarray or iterable right : np.ndarray or iterable strict_nan : bool, default False If True, consider NaN and None to be different. check_dtype: bool, default True check dtype if both a a

(left, right, strict_nan=False,
                             check_dtype=True, err_msg=None,
                             check_same=None, obj='numpy array')

Source from the content-addressed store, hash-verified

1096
1097
1098def assert_numpy_array_equal(left, right, strict_nan=False,
1099 check_dtype=True, err_msg=None,
1100 check_same=None, obj='numpy array'):
1101 """ Checks that 'np.ndarray' is equivalent
1102
1103 Parameters
1104 ----------
1105 left : np.ndarray or iterable
1106 right : np.ndarray or iterable
1107 strict_nan : bool, default False
1108 If True, consider NaN and None to be different.
1109 check_dtype: bool, default True
1110 check dtype if both a and b are np.ndarray
1111 err_msg : str, default None
1112 If provided, used as assertion message
1113 check_same : None|'copy'|'same', default None
1114 Ensure left and right refer/do not refer to the same memory area
1115 obj : str, default 'numpy array'
1116 Specify object name being compared, internally used to show appropriate
1117 assertion message
1118 """
1119 __tracebackhide__ = True
1120
1121 # instance validation
1122 # Show a detailed error message when classes are different
1123 assert_class_equal(left, right, obj=obj)
1124 # both classes must be an np.ndarray
1125 _check_isinstance(left, right, np.ndarray)
1126
1127 def _get_base(obj):
1128 return obj.base if getattr(obj, 'base', None) is not None else obj
1129
1130 left_base = _get_base(left)
1131 right_base = _get_base(right)
1132
1133 if check_same == 'same':
1134 if left_base is not right_base:
1135 msg = "{left!r} is not {right!r}".format(
1136 left=left_base, right=right_base)
1137 raise AssertionError(msg)
1138 elif check_same == 'copy':
1139 if left_base is right_base:
1140 msg = "{left!r} is {right!r}".format(
1141 left=left_base, right=right_base)
1142 raise AssertionError(msg)
1143
1144 def _raise(left, right, err_msg):
1145 if err_msg is None:
1146 if left.shape != right.shape:
1147 raise_assert_detail(obj, '{obj} shapes are different'
1148 .format(obj=obj), left.shape, right.shape)
1149
1150 diff = 0
1151 for l, r in zip(left, right):
1152 # count up differences
1153 if not array_equivalent(l, r, strict_nan=strict_nan):
1154 diff += 1
1155

Calls 7

array_equivalentFunction · 0.90
assert_class_equalFunction · 0.85
_check_isinstanceFunction · 0.85
_get_baseFunction · 0.85
assert_attr_equalFunction · 0.85
_raiseFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected