|
35 | 35 | from zarr.util import buffer_size
|
36 | 36 | from zarr.tests.util import skip_test_env_var, have_fsspec
|
37 | 37 |
|
38 |
| - |
39 | 38 | # noinspection PyMethodMayBeStatic
|
| 39 | + |
| 40 | + |
40 | 41 | class TestArray(unittest.TestCase):
|
41 | 42 |
|
42 | 43 | def test_array_init(self):
|
@@ -1079,7 +1080,7 @@ def test_structured_array_nested(self):
|
1079 | 1080 | (1, (1, ((1, 2), (2, 3), (3, 4)), 1), b'bbb'),
|
1080 | 1081 | (2, (2, ((2, 3), (3, 4), (4, 5)), 2), b'ccc')],
|
1081 | 1082 | dtype=[('foo', 'i8'), ('bar', [('foo', 'i4'), ('bar', '(3, 2)f4'),
|
1082 |
| - ('baz', 'u1')]), ('baz', 'S3')]) |
| 1083 | + ('baz', 'u1')]), ('baz', 'S3')]) |
1083 | 1084 | fill_values = None, b'', (0, (0, ((0, 0), (1, 1), (2, 2)), 0), b'zzz')
|
1084 | 1085 | self.check_structured_array(d, fill_values)
|
1085 | 1086 |
|
@@ -1802,7 +1803,7 @@ def test_structured_array_nested(self):
|
1802 | 1803 | (1, (1, ((1, 2), (2, 3), (3, 4)), 1), b'bbb'),
|
1803 | 1804 | (2, (2, ((2, 3), (3, 4), (4, 5)), 2), b'ccc')],
|
1804 | 1805 | dtype=[('foo', 'i8'), ('bar', [('foo', 'i4'), ('bar', '(3, 2)f4'),
|
1805 |
| - ('baz', 'u1')]), ('baz', 'S3')]) |
| 1806 | + ('baz', 'u1')]), ('baz', 'S3')]) |
1806 | 1807 | fill_values = None, b'', (0, (0, ((0, 0), (1, 1), (2, 2)), 0), b'zzz')
|
1807 | 1808 | with pytest.raises(TypeError):
|
1808 | 1809 | self.check_structured_array(d, fill_values)
|
@@ -2469,36 +2470,50 @@ class TestArrayWithFSStore(TestArray):
|
2469 | 2470 | def create_array(read_only=False, **kwargs):
|
2470 | 2471 | path = mkdtemp()
|
2471 | 2472 | atexit.register(shutil.rmtree, path)
|
2472 |
| - store = FSStore(path) |
| 2473 | + key_separator = kwargs.pop('key_separator', ".") |
| 2474 | + store = FSStore(path, key_separator=key_separator, auto_mkdir=True) |
2473 | 2475 | cache_metadata = kwargs.pop('cache_metadata', True)
|
2474 | 2476 | cache_attrs = kwargs.pop('cache_attrs', True)
|
2475 | 2477 | kwargs.setdefault('compressor', Blosc())
|
2476 | 2478 | init_array(store, **kwargs)
|
2477 | 2479 | return Array(store, read_only=read_only, cache_metadata=cache_metadata,
|
2478 | 2480 | cache_attrs=cache_attrs)
|
2479 | 2481 |
|
| 2482 | + def expected(self): |
| 2483 | + return [ |
| 2484 | + "ab753fc81df0878589535ca9bad2816ba88d91bc", |
| 2485 | + "c16261446f9436b1e9f962e57ce3e8f6074abe8a", |
| 2486 | + "c2ef3b2fb2bc9dcace99cd6dad1a7b66cc1ea058", |
| 2487 | + "6e52f95ac15b164a8e96843a230fcee0e610729b", |
| 2488 | + "091fa99bc60706095c9ce30b56ce2503e0223f56", |
| 2489 | + ] |
| 2490 | + |
2480 | 2491 | def test_hexdigest(self):
|
| 2492 | + found = [] |
| 2493 | + |
2481 | 2494 | # Check basic 1-D array
|
2482 | 2495 | z = self.create_array(shape=(1050,), chunks=100, dtype='<i4')
|
2483 |
| - assert 'f710da18d45d38d4aaf2afd7fb822fdd73d02957' == z.hexdigest() |
| 2496 | + found.append(z.hexdigest()) |
2484 | 2497 |
|
2485 | 2498 | # Check basic 1-D array with different type
|
2486 | 2499 | z = self.create_array(shape=(1050,), chunks=100, dtype='<f4')
|
2487 |
| - assert '1437428e69754b1e1a38bd7fc9e43669577620db' == z.hexdigest() |
| 2500 | + found.append(z.hexdigest()) |
2488 | 2501 |
|
2489 | 2502 | # Check basic 2-D array
|
2490 | 2503 | z = self.create_array(shape=(20, 35,), chunks=10, dtype='<i4')
|
2491 |
| - assert '6c530b6b9d73e108cc5ee7b6be3d552cc994bdbe' == z.hexdigest() |
| 2504 | + found.append(z.hexdigest()) |
2492 | 2505 |
|
2493 | 2506 | # Check basic 1-D array with some data
|
2494 | 2507 | z = self.create_array(shape=(1050,), chunks=100, dtype='<i4')
|
2495 | 2508 | z[200:400] = np.arange(200, 400, dtype='i4')
|
2496 |
| - assert '4c0a76fb1222498e09dcd92f7f9221d6cea8b40e' == z.hexdigest() |
| 2509 | + found.append(z.hexdigest()) |
2497 | 2510 |
|
2498 | 2511 | # Check basic 1-D array with attributes
|
2499 | 2512 | z = self.create_array(shape=(1050,), chunks=100, dtype='<i4')
|
2500 | 2513 | z.attrs['foo'] = 'bar'
|
2501 |
| - assert '05b0663ffe1785f38d3a459dec17e57a18f254af' == z.hexdigest() |
| 2514 | + found.append(z.hexdigest()) |
| 2515 | + |
| 2516 | + assert self.expected() == found |
2502 | 2517 |
|
2503 | 2518 |
|
2504 | 2519 | @pytest.mark.skipif(have_fsspec is False, reason="needs fsspec")
|
@@ -2573,3 +2588,144 @@ def test_read_from_all_blocks(self):
|
2573 | 2588 | z[2:99_000] = 1
|
2574 | 2589 | b = Array(z.store, read_only=True, partial_decompress=True)
|
2575 | 2590 | assert (b[2:99_000] == 1).all()
|
| 2591 | + |
| 2592 | + |
| 2593 | +@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec") |
| 2594 | +class TestArrayWithFSStoreNested(TestArray): |
| 2595 | + |
| 2596 | + @staticmethod |
| 2597 | + def create_array(read_only=False, **kwargs): |
| 2598 | + path = mkdtemp() |
| 2599 | + atexit.register(shutil.rmtree, path) |
| 2600 | + key_separator = kwargs.pop('key_separator', "/") |
| 2601 | + store = FSStore(path, key_separator=key_separator, auto_mkdir=True) |
| 2602 | + cache_metadata = kwargs.pop('cache_metadata', True) |
| 2603 | + cache_attrs = kwargs.pop('cache_attrs', True) |
| 2604 | + kwargs.setdefault('compressor', Blosc()) |
| 2605 | + init_array(store, **kwargs) |
| 2606 | + return Array(store, read_only=read_only, cache_metadata=cache_metadata, |
| 2607 | + cache_attrs=cache_attrs) |
| 2608 | + |
| 2609 | + def expected(self): |
| 2610 | + return [ |
| 2611 | + "94884f29b41b9beb8fc99ad7bf9c0cbf0f2ab3c9", |
| 2612 | + "077aa3bd77b8d354f8f6c15dce5ae4f545788a72", |
| 2613 | + "22be95d83c097460adb339d80b2d7fe19c513c16", |
| 2614 | + "85131cec526fa46938fd2c4a6083a58ee11037ea", |
| 2615 | + "c3167010c162c6198cb2bf3c1da2c46b047c69a1", |
| 2616 | + ] |
| 2617 | + |
| 2618 | + def test_hexdigest(self): |
| 2619 | + found = [] |
| 2620 | + |
| 2621 | + # Check basic 1-D array |
| 2622 | + z = self.create_array(shape=(1050,), chunks=100, dtype='<i4') |
| 2623 | + found.append(z.hexdigest()) |
| 2624 | + |
| 2625 | + # Check basic 1-D array with different type |
| 2626 | + z = self.create_array(shape=(1050,), chunks=100, dtype='<f4') |
| 2627 | + found.append(z.hexdigest()) |
| 2628 | + |
| 2629 | + # Check basic 2-D array |
| 2630 | + z = self.create_array(shape=(20, 35,), chunks=10, dtype='<i4') |
| 2631 | + found.append(z.hexdigest()) |
| 2632 | + |
| 2633 | + # Check basic 1-D array with some data |
| 2634 | + z = self.create_array(shape=(1050,), chunks=100, dtype='<i4') |
| 2635 | + z[200:400] = np.arange(200, 400, dtype='i4') |
| 2636 | + found.append(z.hexdigest()) |
| 2637 | + |
| 2638 | + # Check basic 1-D array with attributes |
| 2639 | + z = self.create_array(shape=(1050,), chunks=100, dtype='<i4') |
| 2640 | + z.attrs['foo'] = 'bar' |
| 2641 | + found.append(z.hexdigest()) |
| 2642 | + |
| 2643 | + assert self.expected() == found |
| 2644 | + |
| 2645 | + |
| 2646 | +@pytest.mark.skipif(have_fsspec is False, reason="needs fsspec") |
| 2647 | +class TestArrayWithFSStoreNestedPartialRead(TestArray): |
| 2648 | + @staticmethod |
| 2649 | + def create_array(read_only=False, **kwargs): |
| 2650 | + path = mkdtemp() |
| 2651 | + atexit.register(shutil.rmtree, path) |
| 2652 | + key_separator = kwargs.pop('key_separator', "/") |
| 2653 | + store = FSStore(path, key_separator=key_separator, auto_mkdir=True) |
| 2654 | + cache_metadata = kwargs.pop("cache_metadata", True) |
| 2655 | + cache_attrs = kwargs.pop("cache_attrs", True) |
| 2656 | + kwargs.setdefault("compressor", Blosc()) |
| 2657 | + init_array(store, **kwargs) |
| 2658 | + return Array( |
| 2659 | + store, |
| 2660 | + read_only=read_only, |
| 2661 | + cache_metadata=cache_metadata, |
| 2662 | + cache_attrs=cache_attrs, |
| 2663 | + partial_decompress=True, |
| 2664 | + ) |
| 2665 | + |
| 2666 | + def expected(self): |
| 2667 | + return [ |
| 2668 | + "94884f29b41b9beb8fc99ad7bf9c0cbf0f2ab3c9", |
| 2669 | + "077aa3bd77b8d354f8f6c15dce5ae4f545788a72", |
| 2670 | + "22be95d83c097460adb339d80b2d7fe19c513c16", |
| 2671 | + "85131cec526fa46938fd2c4a6083a58ee11037ea", |
| 2672 | + "c3167010c162c6198cb2bf3c1da2c46b047c69a1", |
| 2673 | + ] |
| 2674 | + |
| 2675 | + def test_hexdigest(self): |
| 2676 | + found = [] |
| 2677 | + |
| 2678 | + # Check basic 1-D array |
| 2679 | + z = self.create_array(shape=(1050,), chunks=100, dtype="<i4") |
| 2680 | + found.append(z.hexdigest()) |
| 2681 | + |
| 2682 | + # Check basic 1-D array with different type |
| 2683 | + z = self.create_array(shape=(1050,), chunks=100, dtype="<f4") |
| 2684 | + found.append(z.hexdigest()) |
| 2685 | + |
| 2686 | + # Check basic 2-D array |
| 2687 | + z = self.create_array( |
| 2688 | + shape=( |
| 2689 | + 20, |
| 2690 | + 35, |
| 2691 | + ), |
| 2692 | + chunks=10, |
| 2693 | + dtype="<i4", |
| 2694 | + ) |
| 2695 | + found.append(z.hexdigest()) |
| 2696 | + |
| 2697 | + # Check basic 1-D array with some data |
| 2698 | + z = self.create_array(shape=(1050,), chunks=100, dtype="<i4") |
| 2699 | + z[200:400] = np.arange(200, 400, dtype="i4") |
| 2700 | + found.append(z.hexdigest()) |
| 2701 | + |
| 2702 | + # Check basic 1-D array with attributes |
| 2703 | + z = self.create_array(shape=(1050,), chunks=100, dtype="<i4") |
| 2704 | + z.attrs["foo"] = "bar" |
| 2705 | + found.append(z.hexdigest()) |
| 2706 | + |
| 2707 | + assert self.expected() == found |
| 2708 | + |
| 2709 | + def test_non_cont(self): |
| 2710 | + z = self.create_array(shape=(500, 500, 500), chunks=(50, 50, 50), dtype="<i4") |
| 2711 | + z[:, :, :] = 1 |
| 2712 | + # actually go through the partial read by accessing a single item |
| 2713 | + assert z[0, :, 0].any() |
| 2714 | + |
| 2715 | + def test_read_nitems_less_than_blocksize_from_multiple_chunks(self): |
| 2716 | + '''Tests to make sure decompression doesn't fail when `nitems` is |
| 2717 | + less than a compressed block size, but covers multiple blocks |
| 2718 | + ''' |
| 2719 | + z = self.create_array(shape=1000000, chunks=100_000) |
| 2720 | + z[40_000:80_000] = 1 |
| 2721 | + b = Array(z.store, read_only=True, partial_decompress=True) |
| 2722 | + assert (b[40_000:80_000] == 1).all() |
| 2723 | + |
| 2724 | + def test_read_from_all_blocks(self): |
| 2725 | + '''Tests to make sure `PartialReadBuffer.read_part` doesn't fail when |
| 2726 | + stop isn't in the `start_points` array |
| 2727 | + ''' |
| 2728 | + z = self.create_array(shape=1000000, chunks=100_000) |
| 2729 | + z[2:99_000] = 1 |
| 2730 | + b = Array(z.store, read_only=True, partial_decompress=True) |
| 2731 | + assert (b[2:99_000] == 1).all() |
0 commit comments