| 5437 | |
| 5438 | |
| 5439 | def test_blocks_indexer(): |
| 5440 | x = da.arange(10, chunks=2) |
| 5441 | |
| 5442 | assert isinstance(x.blocks[0], da.Array) |
| 5443 | |
| 5444 | assert_eq(x.blocks[0], x[:2]) |
| 5445 | assert_eq(x.blocks[-1], x[-2:]) |
| 5446 | assert_eq(x.blocks[:3], x[:6]) |
| 5447 | assert_eq(x.blocks[[0, 1, 2]], x[:6]) |
| 5448 | assert_eq(x.blocks[[3, 0, 2]], np.array([6, 7, 0, 1, 4, 5])) |
| 5449 | |
| 5450 | x = da.random.default_rng().random((20, 20), chunks=(4, 5)) |
| 5451 | assert_eq(x.blocks[0], x[:4]) |
| 5452 | assert_eq(x.blocks[0, :3], x[:4, :15]) |
| 5453 | assert_eq(x.blocks[:, :3], x[:, :15]) |
| 5454 | |
| 5455 | x = da.ones((40, 40, 40), chunks=(10, 10, 10)) |
| 5456 | assert_eq(x.blocks[0, :, 0], np.ones((10, 40, 10))) |
| 5457 | |
| 5458 | x = da.ones((2, 2), chunks=1) |
| 5459 | with pytest.raises(ValueError): |
| 5460 | x.blocks[[0, 1], [0, 1]] |
| 5461 | with pytest.raises(ValueError): |
| 5462 | x.blocks[np.array([0, 1]), [0, 1]] |
| 5463 | with pytest.raises(ValueError) as info: |
| 5464 | x.blocks[np.array([0, 1]), np.array([0, 1])] |
| 5465 | assert "list" in str(info.value) |
| 5466 | with pytest.raises(ValueError) as info: |
| 5467 | x.blocks[None, :, :] |
| 5468 | assert "newaxis" in str(info.value) and "not supported" in str(info.value) |
| 5469 | with pytest.raises(IndexError) as info: |
| 5470 | x.blocks[100, 100] |
| 5471 | |
| 5472 | |
| 5473 | def test_partitions_indexer(): |