Validates that rechunking an array from ``old_chunks`` to ``new_chunks`` is possible, raises an error if otherwise. Notes ----- This function expects ``old_chunks`` and ``new_chunks`` to have matching dimensionality and will not raise an informative error if they don't.
(old_chunks, new_chunks)
| 241 | |
| 242 | |
| 243 | def _validate_rechunk(old_chunks, new_chunks): |
| 244 | """Validates that rechunking an array from ``old_chunks`` to ``new_chunks`` |
| 245 | is possible, raises an error if otherwise. |
| 246 | |
| 247 | Notes |
| 248 | ----- |
| 249 | This function expects ``old_chunks`` and ``new_chunks`` to have matching |
| 250 | dimensionality and will not raise an informative error if they don't. |
| 251 | """ |
| 252 | assert len(old_chunks) == len(new_chunks) |
| 253 | |
| 254 | old_shapes = tuple(map(sum, old_chunks)) |
| 255 | new_shapes = tuple(map(sum, new_chunks)) |
| 256 | |
| 257 | for old_shape, old_dim, new_shape, new_dim in zip( |
| 258 | old_shapes, old_chunks, new_shapes, new_chunks |
| 259 | ): |
| 260 | if old_shape != new_shape: |
| 261 | if not ( |
| 262 | math.isnan(old_shape) and math.isnan(new_shape) |
| 263 | ) or not np.array_equal(old_dim, new_dim, equal_nan=True): |
| 264 | raise ValueError( |
| 265 | "Chunks must be unchanging along dimensions with missing values.\n\n" |
| 266 | "A possible solution:\n x.compute_chunk_sizes()" |
| 267 | ) |
| 268 | |
| 269 | |
| 270 | def rechunk( |