|
1 | 1 | import pytest |
2 | | -import zarr |
3 | 2 |
|
4 | 3 | import cubed |
5 | 4 | import cubed as xp |
|
29 | 28 | "expected_max_output_blocks", |
30 | 29 | ), |
31 | 30 | [ |
32 | | - (None, 5, 7, 9), # multistage rechunk - more stages, lower fan in/out |
| 31 | + (None, 3, 16, 15), # multistage rechunk - more stages, lower fan in/out |
33 | 32 | (0, 1, 3771, 3460), # single stage rechunk - very high fan in/out |
34 | 33 | ], |
35 | 34 | ) |
@@ -97,11 +96,9 @@ def test_rechunk_era5_chunk_sizes(spec): |
97 | 96 |
|
98 | 97 | rechunk_plan = list(_rechunk_plan(a, target_chunks)) |
99 | 98 | assert rechunk_plan == [ |
100 | | - ((93, 721, 1440), (93, 240, 480)), |
101 | | - ((465, 240, 480), (465, 120, 240)), |
102 | | - ((2325, 120, 240), (2325, 40, 120)), |
103 | | - ((11625, 40, 120), (11625, 20, 60)), |
104 | | - ((58125, 20, 60), (58125, 10, 30)), |
| 99 | + ((93, 721, 1440), (93, 173, 396)), |
| 100 | + ((1447, 173, 396), (1447, 41, 109)), |
| 101 | + ((22528, 41, 109), (22528, 10, 30)), |
105 | 102 | ((350640, 10, 30), (350640, 10, 10)), |
106 | 103 | ] |
107 | 104 |
|
@@ -140,32 +137,32 @@ def test_rechunk_hypothesis_generated_bug(): |
140 | 137 | from cubed.core.ops import _rechunk_plan |
141 | 138 |
|
142 | 139 | rechunk_plan = list(_rechunk_plan(a, target_chunks)) |
143 | | - assert rechunk_plan == [((30, 376), (15, 376)), ((15, 1001), (5, 146))] |
144 | | - for copy_chunks, target_chunks in rechunk_plan: |
145 | | - verify_chunk_compatibility(shape, copy_chunks, target_chunks) |
| 140 | + assert rechunk_plan == [((38, 376), (15, 376)), ((15, 1001), (5, 146))] |
146 | 141 |
|
147 | 142 | b = a.rechunk((5, 146)) |
148 | 143 |
|
149 | 144 | assert_array_equal(b.compute(), nxp.ones(shape)) |
150 | 145 |
|
151 | 146 |
|
152 | | -@pytest.mark.skipif( |
153 | | - zarr.__version__[0] == "2", |
154 | | - reason="irregular chunking is not supported for Zarr Python v2", |
155 | | -) |
156 | | -def test_rechunk_hypothesis_generated_bug_allow_irregular(): |
157 | | - rechunk_shapes = (tuple([1001, 1001]), (38, 376), (5, 146)) |
158 | | - shape, source_chunks, target_chunks = rechunk_shapes |
| 147 | +def test_rechunk_allow_irregular_false(): |
| 148 | + # Verify the regular planner still works when allow_irregular=False is |
| 149 | + # passed explicitly. Regular intermediates must be integer multiples of |
| 150 | + # target chunks, so copy_chunks[0]=30 (multiple of 15) instead of 38. |
| 151 | + shape = (1001, 1001) |
| 152 | + source_chunks = (38, 376) |
| 153 | + target_chunks = (5, 146) |
159 | 154 |
|
160 | 155 | spec = cubed.Spec(allowed_mem=8000000 / 10) |
161 | 156 | a = xp.ones(shape, chunks=source_chunks, spec=spec) |
162 | 157 |
|
163 | 158 | from cubed.core.ops import _rechunk_plan |
164 | 159 |
|
165 | | - rechunk_plan = list(_rechunk_plan(a, target_chunks, allow_irregular=True)) |
166 | | - assert rechunk_plan == [((38, 376), (15, 376)), ((15, 1001), (5, 146))] |
| 160 | + rechunk_plan = list(_rechunk_plan(a, target_chunks, allow_irregular=False)) |
| 161 | + assert rechunk_plan == [((30, 376), (15, 376)), ((15, 1001), (5, 146))] |
| 162 | + for copy_chunks, store_chunks in rechunk_plan: |
| 163 | + verify_chunk_compatibility(shape, copy_chunks, store_chunks) |
167 | 164 |
|
168 | | - b = a.rechunk((5, 146), allow_irregular=True) |
| 165 | + b = a.rechunk(target_chunks, allow_irregular=False) |
169 | 166 |
|
170 | 167 | assert_array_equal(b.compute(), nxp.ones(shape)) |
171 | 168 |
|
|
0 commit comments