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

Function test_partitions_indexer

dask/array/tests/test_array_core.py:5473–5505  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5471
5472
5473def test_partitions_indexer():
5474 # .partitions is an alias of .blocks for dask arrays
5475 x = da.arange(10, chunks=2)
5476
5477 assert isinstance(x.partitions[0], da.Array)
5478
5479 assert_eq(x.partitions[0], x[:2])
5480 assert_eq(x.partitions[-1], x[-2:])
5481 assert_eq(x.partitions[:3], x[:6])
5482 assert_eq(x.partitions[[0, 1, 2]], x[:6])
5483 assert_eq(x.partitions[[3, 0, 2]], np.array([6, 7, 0, 1, 4, 5]))
5484
5485 x = da.random.default_rng().random((20, 20), chunks=(4, 5))
5486 assert_eq(x.partitions[0], x[:4])
5487 assert_eq(x.partitions[0, :3], x[:4, :15])
5488 assert_eq(x.partitions[:, :3], x[:, :15])
5489
5490 x = da.ones((40, 40, 40), chunks=(10, 10, 10))
5491 assert_eq(x.partitions[0, :, 0], np.ones((10, 40, 10)))
5492
5493 x = da.ones((2, 2), chunks=1)
5494 with pytest.raises(ValueError):
5495 x.partitions[[0, 1], [0, 1]]
5496 with pytest.raises(ValueError):
5497 x.partitions[np.array([0, 1]), [0, 1]]
5498 with pytest.raises(ValueError) as info:
5499 x.partitions[np.array([0, 1]), np.array([0, 1])]
5500 assert "list" in str(info.value)
5501 with pytest.raises(ValueError) as info:
5502 x.partitions[None, :, :]
5503 assert "newaxis" in str(info.value) and "not supported" in str(info.value)
5504 with pytest.raises(IndexError) as info:
5505 x.partitions[100, 100]
5506
5507
5508@pytest.mark.filterwarnings("ignore:the matrix subclass:PendingDeprecationWarning")

Callers

nothing calls this directly

Calls 4

assert_eqFunction · 0.90
arangeMethod · 0.45
randomMethod · 0.45
onesMethod · 0.45

Tested by

no test coverage detected