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

Method _run_axis_tests

numpy/lib/tests/test_arraysetops.py:1156–1198  ·  view source on GitHub ↗
(self, dtype)

Source from the content-addressed store, hash-verified

1154 assert_array_equal(a, b, fmt % dt)
1155
1156 def _run_axis_tests(self, dtype):
1157 data = np.array([[0, 1, 0, 0],
1158 [1, 0, 0, 0],
1159 [0, 1, 0, 0],
1160 [1, 0, 0, 0]]).astype(dtype)
1161
1162 msg = 'Unique with 1d array and axis=0 failed'
1163 result = np.array([0, 1])
1164 assert_array_equal(unique(data), result.astype(dtype), msg)
1165
1166 msg = 'Unique with 2d array and axis=0 failed'
1167 result = np.array([[0, 1, 0, 0], [1, 0, 0, 0]])
1168 assert_array_equal(unique(data, axis=0), result.astype(dtype), msg)
1169
1170 msg = 'Unique with 2d array and axis=1 failed'
1171 result = np.array([[0, 0, 1], [0, 1, 0], [0, 0, 1], [0, 1, 0]])
1172 assert_array_equal(unique(data, axis=1), result.astype(dtype), msg)
1173
1174 msg = 'Unique with 3d array and axis=2 failed'
1175 data3d = np.array([[[1, 1],
1176 [1, 0]],
1177 [[0, 1],
1178 [0, 0]]]).astype(dtype)
1179 result = np.take(data3d, [1, 0], axis=2)
1180 assert_array_equal(unique(data3d, axis=2), result, msg)
1181
1182 uniq, idx, inv, cnt = unique(data, axis=0, return_index=True,
1183 return_inverse=True, return_counts=True)
1184 msg = "Unique's return_index=True failed with axis=0"
1185 assert_array_equal(data[idx], uniq, msg)
1186 msg = "Unique's return_inverse=True failed with axis=0"
1187 assert_array_equal(np.take(uniq, inv, axis=0), data)
1188 msg = "Unique's return_counts=True failed with axis=0"
1189 assert_array_equal(cnt, np.array([2, 2]), msg)
1190
1191 uniq, idx, inv, cnt = unique(data, axis=1, return_index=True,
1192 return_inverse=True, return_counts=True)
1193 msg = "Unique's return_index=True failed with axis=1"
1194 assert_array_equal(data[:, idx], uniq)
1195 msg = "Unique's return_inverse=True failed with axis=1"
1196 assert_array_equal(np.take(uniq, inv, axis=1), data)
1197 msg = "Unique's return_counts=True failed with axis=1"
1198 assert_array_equal(cnt, np.array([2, 1, 1]), msg)
1199
1200 def test_unique_nanequals(self):
1201 # issue 20326

Callers 1

test_unique_axisMethod · 0.95

Calls 4

assert_array_equalFunction · 0.90
uniqueFunction · 0.90
astypeMethod · 0.80
takeMethod · 0.80

Tested by

no test coverage detected