Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/test_backed_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,32 @@ def test_return_to_memory_mode(adata: ad.AnnData, backing_h5ad: Path):
bdata.filename = None


@pytest.mark.parametrize(
"x",
[
pytest.param(np.arange(12).reshape(3, 4), id="dense"),
pytest.param(sparse.csr_matrix(np.arange(12).reshape(3, 4)), id="csr"),
pytest.param(sparse.csc_matrix(np.arange(12).reshape(3, 4)), id="csc"),
],
)
def test_return_to_memory_mode_after_read_h5ad(
tmp_path: Path, x: np.ndarray | sparse.spmatrix
):
pth = tmp_path / "tmp.h5ad"
expected = np.arange(12).reshape(3, 4)
ad.AnnData(X=x).write_h5ad(pth)

backed = ad.read_h5ad(pth, backed="r+")
assert backed.isbacked

backed.filename = None
assert not backed.isbacked
assert backed.X is not None

got = backed.X.toarray() if sparse.issparse(backed.X) else backed.X
np.testing.assert_array_equal(got, expected)


def test_backed_modification(adata: ad.AnnData, backing_h5ad: Path):
adata.X[:, 1] = 0 # Make it a little sparse
adata.X = sparse.csr_matrix(adata.X)
Expand Down
Loading