MCPcopy Create free account
hub / github.com/dask/dask / test_insert

Function test_insert

dask/array/tests/test_routines.py:2346–2383  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2344
2345
2346def test_insert():
2347 rng = np.random.default_rng()
2348 x = rng.integers(10, size=(10, 10))
2349 a = da.from_array(x, chunks=(5, 5))
2350 y = rng.integers(10, size=(5, 10))
2351 b = da.from_array(y, chunks=(4, 4))
2352
2353 assert_eq(np.insert(x, 0, -1, axis=0), da.insert(a, 0, -1, axis=0))
2354 assert_eq(np.insert(x, 3, -1, axis=-1), da.insert(a, 3, -1, axis=-1))
2355 assert_eq(np.insert(x, 5, -1, axis=1), da.insert(a, 5, -1, axis=1))
2356 assert_eq(np.insert(x, -1, -1, axis=-2), da.insert(a, -1, -1, axis=-2))
2357 assert_eq(np.insert(x, [2, 3, 3], -1, axis=1), da.insert(a, [2, 3, 3], -1, axis=1))
2358 assert_eq(
2359 np.insert(x, [2, 3, 8, 8, -2, -2], -1, axis=0),
2360 da.insert(a, [2, 3, 8, 8, -2, -2], -1, axis=0),
2361 )
2362 assert_eq(
2363 np.insert(x, slice(1, 4), -1, axis=1), da.insert(a, slice(1, 4), -1, axis=1)
2364 )
2365 assert_eq(
2366 np.insert(x, [2] * 3 + [5] * 2, y, axis=0),
2367 da.insert(a, [2] * 3 + [5] * 2, b, axis=0),
2368 )
2369 assert_eq(np.insert(x, 0, y[0], axis=1), da.insert(a, 0, b[0], axis=1))
2370
2371 assert same_keys(
2372 da.insert(a, [2, 3, 8, 8, -2, -2], -1, axis=0),
2373 da.insert(a, [2, 3, 8, 8, -2, -2], -1, axis=0),
2374 )
2375
2376 with pytest.raises(NotImplementedError):
2377 da.insert(a, [4, 2], -1, axis=0)
2378
2379 with pytest.raises(AxisError):
2380 da.insert(a, [3], -1, axis=2)
2381
2382 with pytest.raises(AxisError):
2383 da.insert(a, [3], -1, axis=-3)
2384
2385
2386def test_append():

Callers

nothing calls this directly

Calls 3

assert_eqFunction · 0.90
same_keysFunction · 0.90
integersMethod · 0.45

Tested by

no test coverage detected