diff --git a/anndata/_io/specs/methods.py b/anndata/_io/specs/methods.py index b63a7d04f..5452f7bb6 100644 --- a/anndata/_io/specs/methods.py +++ b/anndata/_io/specs/methods.py @@ -427,6 +427,11 @@ def write_vlen_string_array_zarr( ): import numcodecs + # Workaround for https://github.com/zarr-developers/numcodecs/issues/514 + # TODO: Warn to upgrade numcodecs if fixed + if not elem.flags.writeable: + elem = elem.copy() + f.create_dataset( k, shape=elem.shape, diff --git a/anndata/tests/test_io_elementwise.py b/anndata/tests/test_io_elementwise.py index 51ca106d5..e2999cd01 100644 --- a/anndata/tests/test_io_elementwise.py +++ b/anndata/tests/test_io_elementwise.py @@ -11,6 +11,7 @@ import pandas as pd import pytest import zarr +from packaging.version import Version from scipy import sparse import anndata as ad @@ -333,3 +334,15 @@ def test_dataframe_column_uniqueness(store): result = read_elem(store["index_shared_okay"]) assert_equal(result, index_shared_okay) + + +@pytest.mark.parametrize("copy_on_write", [True, False]) +def test_io_pd_cow(store, copy_on_write): + if Version(pd.__version__) < Version("2"): + pytest.xfail("copy_on_write option is not available in pandas < 2") + # https://github.com/zarr-developers/numcodecs/issues/514 + with pd.option_context("mode.copy_on_write", copy_on_write): + orig = gen_adata((3, 2)) + write_elem(store, "adata", orig) + from_store = read_elem(store["adata"]) + assert_equal(orig, from_store) diff --git a/docs/release-notes/0.10.7.md b/docs/release-notes/0.10.7.md index abdb08924..ea1929040 100644 --- a/docs/release-notes/0.10.7.md +++ b/docs/release-notes/0.10.7.md @@ -1,8 +1,10 @@ -### 0.10.6 {small}`the future` +### 0.10.7 {small}`the future` ```{rubric} Bugfix ``` +* Handle upstream `numcodecs` bug where read-only string arrays cannot be encoded {user}`ivirshup` {pr}`1421` + ```{rubric} Documentation ```