Skip to content

Commit a84949a

Browse files
authored
test: consolidate vlen F-contiguous regression tests (zarr-developers#4122)
Follow-up test-quality cleanup for the zarr-developersgh-3558 fix (zarr-developers#4116): - Merge test_vlen_string_f_contiguous and test_vlen_bytes_f_contiguous into one test parametrized over (dtype, fill_value, elements), matching the parametrized style of test_vlen_string in the same file. - Drop the chunks=(2,2) case: with (3,3) data it produces only partial chunks, which the codec pipeline recopies to C order before encoding, so it never exercised the F-contiguous path it claimed to cover. Use chunks == shape (a single complete chunk) so the F-contiguous buffer reaches the codec untouched. - Build the F-contiguous input directly via reshape(order="F") instead of wrapping a C-order reshape in np.asarray(..., order="F"), and assert data.flags.f_contiguous so a future simplification can't silently defeat the regression guard. - Add a docstring stating the verified behavior. Assisted-by: ClaudeCode:claude-opus-4.8
1 parent 1d06a82 commit a84949a

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

tests/test_codecs/test_vlen.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from zarr.abc.store import Store
1010
from zarr.codecs import ZstdCodec
1111
from zarr.codecs.vlen_utf8 import VLenBytesCodec, VLenUTF8Codec
12-
from zarr.core.dtype import VariableLengthBytes, get_data_type_from_native_dtype
12+
from zarr.core.dtype import get_data_type_from_native_dtype
1313
from zarr.core.metadata.v3 import ArrayV3Metadata
1414
from zarr.storage import StorePath
1515

@@ -67,30 +67,29 @@ def test_vlen_string(
6767
assert a.dtype == data.dtype
6868

6969

70-
@pytest.mark.parametrize("store", ["memory"], indirect=["store"])
71-
@pytest.mark.parametrize("chunks", [(3, 3), (2, 2)])
72-
def test_vlen_string_f_contiguous(store: Store, chunks: tuple[int, int]) -> None:
73-
# gh-3558: F-contiguous chunks were encoded in transposed element order
74-
data = np.asarray(
75-
np.array([f"S{i:05}" for i in range(9)], dtype=object).reshape(3, 3), order="F"
76-
)
77-
sp = StorePath(store, path="string-f-contiguous")
78-
a = zarr.create_array(sp, shape=data.shape, chunks=chunks, dtype=str, fill_value="")
79-
a[:, :] = data
80-
assert np.array_equal(data, np.asarray(a[:, :], dtype=object))
81-
82-
8370
@pytest.mark.filterwarnings("ignore::zarr.core.dtype.common.UnstableSpecificationWarning")
8471
@pytest.mark.parametrize("store", ["memory"], indirect=["store"])
85-
@pytest.mark.parametrize("chunks", [(3, 3), (2, 2)])
86-
def test_vlen_bytes_f_contiguous(store: Store, chunks: tuple[int, int]) -> None:
87-
# gh-3558: F-contiguous chunks were encoded in transposed element order
88-
data = np.asarray(
89-
np.array([b"%05d" % i for i in range(9)], dtype=object).reshape(3, 3), order="F"
90-
)
91-
sp = StorePath(store, path="bytes-f-contiguous")
72+
@pytest.mark.parametrize(
73+
("dtype", "fill_value", "elements"),
74+
[
75+
pytest.param("string", "", [f"S{i:05}" for i in range(9)], id="string"),
76+
pytest.param("variable_length_bytes", b"", [b"%05d" % i for i in range(9)], id="bytes"),
77+
],
78+
)
79+
def test_vlen_f_contiguous(
80+
store: Store, dtype: str, fill_value: str | bytes, elements: list[str] | list[bytes]
81+
) -> None:
82+
"""An F-contiguous chunk written through a vlen codec round-trips in the original
83+
element order rather than the transposed memory order (gh-3558)."""
84+
# reshape(order="F") gives an F-contiguous view directly, so the whole-array write
85+
# below hands an F-contiguous chunk to the codec; assert it to guard the precondition.
86+
data = np.array(elements, dtype=object).reshape((3, 3), order="F")
87+
assert data.flags.f_contiguous
88+
sp = StorePath(store, path="vlen-f-contiguous")
89+
# chunks == shape so the write is a single complete chunk, which the codec pipeline
90+
# forwards to the codec untouched; a partial-chunk layout would be recopied to C order.
9291
a = zarr.create_array(
93-
sp, shape=data.shape, chunks=chunks, dtype=VariableLengthBytes(), fill_value=b""
92+
sp, shape=data.shape, chunks=data.shape, dtype=dtype, fill_value=fill_value
9493
)
9594
a[:, :] = data
9695
assert np.array_equal(data, np.asarray(a[:, :], dtype=object))

0 commit comments

Comments
 (0)