|
11 | 11 | from zarr import config, create_array, open_array |
12 | 12 | from zarr.abc.numcodec import _is_numcodec, _is_numcodec_cls |
13 | 13 | from zarr.codecs import numcodecs as _numcodecs |
| 14 | +from zarr.codecs.transpose import TransposeCodec |
14 | 15 | from zarr.errors import UnknownCodecError |
15 | 16 | from zarr.registry import get_codec_class, get_numcodec |
16 | 17 |
|
@@ -192,6 +193,45 @@ def test_generic_filter_f_contiguous( |
192 | 193 | np.testing.assert_array_equal(data, a[:, :]) |
193 | 194 |
|
194 | 195 |
|
| 196 | +def test_generic_filter_flattened_output_reshaped() -> None: |
| 197 | + # gh-4553: numcodecs filters return a flattened array; `_encode_sync` must |
| 198 | + # reshape it back to the chunk shape, so downstream codecs receive chunks |
| 199 | + # with the shape the pipeline promised them |
| 200 | + data = np.arange(256, dtype="int64").reshape(16, 16) |
| 201 | + |
| 202 | + a = create_array( |
| 203 | + {}, |
| 204 | + shape=data.shape, |
| 205 | + chunks=(16, 16), |
| 206 | + dtype=data.dtype, |
| 207 | + fill_value=0, |
| 208 | + filters=[_numcodecs.Delta(dtype="int64"), TransposeCodec(order=(1, 0))], |
| 209 | + ) |
| 210 | + |
| 211 | + a[:, :] = data |
| 212 | + with codec_conf(): |
| 213 | + b = open_array(a.store, mode="r") |
| 214 | + np.testing.assert_array_equal(data, b[:, :]) |
| 215 | + |
| 216 | + |
| 217 | +def test_generic_filter_packedbits_output_shape() -> None: |
| 218 | + # PackBits changes the size of the chunk, so `_encode_sync` must reshape its |
| 219 | + # output to the shape from `resolve_metadata`, not the input chunk shape |
| 220 | + data = np.tril(np.ones((16, 16), dtype=bool)) |
| 221 | + |
| 222 | + a = create_array( |
| 223 | + {}, |
| 224 | + shape=data.shape, |
| 225 | + chunks=(16, 16), |
| 226 | + dtype=data.dtype, |
| 227 | + fill_value=0, |
| 228 | + filters=[_numcodecs.PackBits()], |
| 229 | + ) |
| 230 | + |
| 231 | + a[:, :] = data |
| 232 | + np.testing.assert_array_equal(data, a[:, :]) |
| 233 | + |
| 234 | + |
195 | 235 | def test_generic_filter_bitround() -> None: |
196 | 236 | data = np.linspace(0, 1, 256, dtype="float32").reshape((16, 16)) |
197 | 237 |
|
|
0 commit comments