Skip to content

Commit

Permalink
Backport PR #1421 on branch 0.10.x (Handle numcodecs bug for encoding…
Browse files Browse the repository at this point in the history
… read-only string array) (#1422)

Co-authored-by: Isaac Virshup <[email protected]>
  • Loading branch information
meeseeksmachine and ivirshup authored Mar 14, 2024
1 parent aefc914 commit edb62f5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions anndata/_io/specs/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions anndata/tests/test_io_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion docs/release-notes/0.10.7.md
Original file line number Diff line number Diff line change
@@ -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
```

Expand Down

0 comments on commit edb62f5

Please sign in to comment.