diff --git a/zarrs/tests/data/v2_str0.py b/zarrs/tests/data/v2_str0.py new file mode 100755 index 00000000..162724ee --- /dev/null +++ b/zarrs/tests/data/v2_str0.py @@ -0,0 +1,42 @@ +#!/usr/bin/env -S uv run +# /// script +# requires-python = ">=3.12" +# dependencies = [ +# "zarr==3.0.1", +# ] +# /// + +import zarr + +path_out = "tests/data/zarr_python_compat/str_v2_fv_0.zarr" +array = zarr.create_array( + path_out, + dtype=str, + shape=(5,), + chunks=(2,), + filters=zarr.codecs.vlen_utf8.VLenUTF8(), + compressors=[None], + fill_value=0, + zarr_format=2, + overwrite=True, +) +array[:3] = ["a", "bb", ""] +print(array.info) +# assert (array[:] == ["a", "bb", "", "", ""]).all() # FAILURE + +path_out = "tests/data/zarr_python_compat/str_v2_fv_null.zarr" +array = zarr.create_array( + path_out, + dtype=str, + shape=(5,), + chunks=(2,), + filters=zarr.codecs.vlen_utf8.VLenUTF8(), + compressors=[None], + fill_value=None, + zarr_format=2, + overwrite=True, +) +array[:3] = ["a", "bb", ""] +print(array.info) +print(array[:]) +assert (array[:] == ["a", "bb", "", "", ""]).all() \ No newline at end of file diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/.zarray b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/.zarray new file mode 100644 index 00000000..aae1beed --- /dev/null +++ b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/.zarray @@ -0,0 +1,19 @@ +{ + "shape": [ + 5 + ], + "chunks": [ + 2 + ], + "fill_value": 0, + "order": "C", + "filters": [ + { + "id": "vlen-utf8" + } + ], + "dimension_separator": ".", + "compressor": null, + "zarr_format": 2, + "dtype": "|O" +} \ No newline at end of file diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/.zattrs b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/.zattrs new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/.zattrs @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/0 b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/0 new file mode 100644 index 00000000..72190f21 Binary files /dev/null and b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/0 differ diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/1 b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/1 new file mode 100644 index 00000000..3ae16874 Binary files /dev/null and b/zarrs/tests/data/zarr_python_compat/str_v2_fv_0.zarr/1 differ diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/.zarray b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/.zarray new file mode 100644 index 00000000..a1b39c04 --- /dev/null +++ b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/.zarray @@ -0,0 +1,19 @@ +{ + "shape": [ + 5 + ], + "chunks": [ + 2 + ], + "fill_value": null, + "order": "C", + "filters": [ + { + "id": "vlen-utf8" + } + ], + "dimension_separator": ".", + "compressor": null, + "zarr_format": 2, + "dtype": "|O" +} \ No newline at end of file diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/.zattrs b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/.zattrs new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/.zattrs @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/0 b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/0 new file mode 100644 index 00000000..72190f21 Binary files /dev/null and b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/0 differ diff --git a/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/1 b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/1 new file mode 100644 index 00000000..3ae16874 Binary files /dev/null and b/zarrs/tests/data/zarr_python_compat/str_v2_fv_null.zarr/1 differ diff --git a/zarrs/tests/zarr_python_compat.rs b/zarrs/tests/zarr_python_compat.rs index 54b4d195..7f1974ca 100644 --- a/zarrs/tests/zarr_python_compat.rs +++ b/zarrs/tests/zarr_python_compat.rs @@ -43,3 +43,31 @@ fn zarr_python_compat_fletcher32_v2() -> Result<(), Box> { Ok(()) } + +#[test] +fn zarr_python_v2_compat_str_fv_0() -> Result<(), Box> { + let store = Arc::new(FilesystemStore::new( + "tests/data/zarr_python_compat/str_v2_fv_0.zarr", + )?); + let array = zarrs::array::Array::open(store.clone(), "/")?; + let subset_all = array.subset_all(); + let elements = array.retrieve_array_subset_elements::(&subset_all)?; + + assert_eq!(elements, &["a", "bb", "", "", ""]); + + Ok(()) +} + +#[test] +fn zarr_python_v2_compat_str_fv_null() -> Result<(), Box> { + let store = Arc::new(FilesystemStore::new( + "tests/data/zarr_python_compat/str_v2_fv_null.zarr", + )?); + let array = zarrs::array::Array::open(store.clone(), "/")?; + let subset_all = array.subset_all(); + let elements = array.retrieve_array_subset_elements::(&subset_all)?; + + assert_eq!(elements, &["a", "bb", "", "", ""]); + + Ok(()) +}