MCPcopy Index your code
hub / github.com/numpy/numpy / test_exceptions

Method test_exceptions

numpy/_core/tests/test_shape_base.py:255–293  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

253 assert b[0, 0] != a[0, 0]
254
255 def test_exceptions(self):
256 # test axis must be in bounds
257 for ndim in [1, 2, 3]:
258 a = np.ones((1,) * ndim)
259 np.concatenate((a, a), axis=0) # OK
260 assert_raises(AxisError, np.concatenate, (a, a), axis=ndim)
261 assert_raises(AxisError, np.concatenate, (a, a), axis=-(ndim + 1))
262
263 # Scalars cannot be concatenated
264 assert_raises(ValueError, concatenate, (0,))
265 assert_raises(ValueError, concatenate, (np.array(0),))
266
267 # dimensionality must match
268 assert_raises_regex(
269 ValueError,
270 r"all the input arrays must have same number of dimensions, but "
271 r"the array at index 0 has 1 dimension\(s\) and the array at "
272 r"index 1 has 2 dimension\(s\)",
273 np.concatenate, (np.zeros(1), np.zeros((1, 1))))
274
275 # test shapes must match except for concatenation axis
276 a = np.ones((1, 2, 3))
277 b = np.ones((2, 2, 3))
278 axis = list(range(3))
279 for i in range(3):
280 np.concatenate((a, b), axis=axis[0]) # OK
281 assert_raises_regex(
282 ValueError,
283 "all the input array dimensions except for the concatenation axis "
284 f"must match exactly, but along dimension {i}, the array at "
285 "index 0 has size 1 and the array at index 1 has size 2",
286 np.concatenate, (a, b), axis=axis[1])
287 assert_raises(ValueError, np.concatenate, (a, b), axis=axis[2])
288 a = np.moveaxis(a, -1, 0)
289 b = np.moveaxis(b, -1, 0)
290 axis.append(axis.pop(0))
291
292 # No arrays to concatenate raises ValueError
293 assert_raises(ValueError, concatenate, ())
294
295 @pytest.mark.slow
296 @pytest.mark.skipif(

Callers

nothing calls this directly

Calls 2

assert_raisesFunction · 0.90
assert_raises_regexFunction · 0.90

Tested by

no test coverage detected