Skip to content

Commit

Permalink
Merge branch 'main' into ig/io_module
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Sep 23, 2024
2 parents 2afc94a + d4ec872 commit 8a70868
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/release-notes/1685.dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove `shall_` from variable names in `settings` {user}`ilan-gold`
2 changes: 1 addition & 1 deletion src/anndata/_core/anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ def raw(self) -> Raw:
The :attr:`raw` attribute is initialized with the current content
of an object by setting::
adata.raw = adata
adata.raw = adata.copy()
Its content can be deleted::
Expand Down
4 changes: 2 additions & 2 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_setting_dim_index(dim):
mapping_attr = f"{dim}m"

orig = gen_adata((5, 5))
orig.raw = orig
orig.raw = orig.copy()
curr = orig.copy()
view = orig[:, :]
new_idx = pd.Index(list("abcde"), name="letters")
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_convenience():
adata = adata_sparse.copy()
adata.layers["x2"] = adata.X * 2
adata.var["anno2"] = ["p1", "p2", "p3"]
adata.raw = adata
adata.raw = adata.copy()
adata.X = adata.X / 2
adata_dense = adata.copy()
adata_dense.X = adata_dense.X.toarray()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ def test_concatenate_with_raw():
layers=dict(Xs=X4),
)

adata1.raw = adata1
adata2.raw = adata2
adata3.raw = adata3
adata1.raw = adata1.copy()
adata2.raw = adata2.copy()
adata3.raw = adata3.copy()

adata_all = AnnData.concatenate(adata1, adata2, adata3)
assert isinstance(adata_all.raw, Raw)
Expand All @@ -713,7 +713,7 @@ def test_concatenate_with_raw():
assert_equal(adata_all.raw.to_adata().obs, adata_all.obs)
assert np.array_equal(np.nan_to_num(adata_all.raw.X), np.nan_to_num(adata_all.X))

adata3.raw = adata4
adata3.raw = adata4.copy()
adata_all = AnnData.concatenate(adata1, adata2, adata3, join="outer")
assert isinstance(adata_all.raw, Raw)
assert set(adata_all.raw.var_names) == set("abcdz")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def adata():
obs=dict(obs_names=["s1", "s2"], anno1=["c1", "c2"]),
var=dict(var_names=["a", "b", "c"]),
)
adata.raw = adata
adata.raw = adata.copy()
adata.layers["x2"] = adata.X * 2
adata.var["anno2"] = ["p1", "p2", "p3"]
adata.X = adata.X / 2
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_amgibuous_keys():
),
)

adata.raw = adata
adata.raw = adata.copy()

for k in var_keys:
# These are mostly to check that the test is working
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_adata_raw_gpu():
adata = AnnData(
X=cupy_sparse.random(500, 50, density=0.01, format="csr", dtype=cp.float32)
)
adata.raw = adata
adata.raw = adata.copy()
assert isinstance(adata.raw.X, sparse.csr_matrix)


Expand Down
6 changes: 3 additions & 3 deletions tests/test_io_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_sparse_to_dense_disk(tmp_path, mtx_format, to_convert):
dense_from_mem_pth = tmp_path / "dense_mem.h5ad"
dense_from_disk_pth = tmp_path / "dense_disk.h5ad"
mem = gen_adata((50, 50), mtx_format)
mem.raw = mem
mem.raw = mem.copy()

mem.write_h5ad(mem_pth)
disk = ad.read_h5ad(mem_pth, backed="r")
Expand All @@ -66,7 +66,7 @@ def test_sparse_to_dense_disk(tmp_path, mtx_format, to_convert):
def test_sparse_to_dense_inplace(tmp_path, spmtx_format):
pth = tmp_path / "adata.h5ad"
orig = gen_adata((50, 50), spmtx_format)
orig.raw = orig
orig.raw = orig.copy()
orig.write(pth)
backed = ad.read_h5ad(pth, backed="r+")
backed.write(as_dense=("X", "raw/X"))
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_sparse_to_dense_errors(tmp_path):
def test_dense_to_sparse_memory(tmp_path, spmtx_format, to_convert):
dense_path = tmp_path / "dense.h5ad"
orig = gen_adata((50, 50), np.array)
orig.raw = orig
orig.raw = orig.copy()
orig.write_h5ad(dense_path)
assert not isinstance(orig.X, sparse.spmatrix)
assert not isinstance(orig.raw.X, sparse.spmatrix)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_io_elementwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_write_indptr_dtype_override(store, sparse_format):

def test_io_spec_raw(store):
adata = gen_adata((3, 2))
adata.raw = adata
adata.raw = adata.copy()

write_elem(store, "adata", adata)

Expand Down
11 changes: 9 additions & 2 deletions tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def adata_raw() -> ad.AnnData:
adata = ad.AnnData(
np.array(data, dtype="int32"), obs=obs_dict, var=var_dict, uns=uns_dict
)
adata.raw = adata
adata.raw = adata.copy()
# Make them different shapes
adata = adata[:, [0, 1]].copy()
return adata
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_raw_as_parent_view():
# https://github.com/scverse/anndata/issues/288
a = ad.AnnData(np.ones((4, 3)))
a.varm["PCs"] = np.ones((3, 3))
a.raw = a
a.raw = a.copy()
# create a Raw containing views. This used to trigger #288.
b = a.raw[:, "0"]
# actualize
Expand Down Expand Up @@ -165,3 +165,10 @@ def test_to_adata_populates_obs():
from_raw = adata_w_raw.raw.to_adata()

assert_equal(adata, from_raw)


def test_no_copy():
adata = gen_adata((20, 10), X_type=np.asarray)
adata.raw = adata # no .copy() herer
np.log1p(adata.X, out=adata.X)
assert adata.X is adata.raw.X
4 changes: 2 additions & 2 deletions tests/test_readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_readwrite_kitchensink(tmp_path, storage, typ, backing_h5ad, dataset_kwa
X = typ(X_list)
adata_src = ad.AnnData(X, obs=obs_dict, var=var_dict, uns=uns_dict)
assert not isinstance(adata_src.obs["oanno1"].dtype, pd.CategoricalDtype)
adata_src.raw = adata_src
adata_src.raw = adata_src.copy()

if storage == "h5ad":
adata_src.write(backing_h5ad, **dataset_kwargs)
Expand Down Expand Up @@ -242,7 +242,7 @@ def test_readwrite_equivalent_h5ad_zarr(tmp_path, typ):

M, N = 100, 101
adata = gen_adata((M, N), X_type=typ)
adata.raw = adata
adata.raw = adata.copy()

adata.write_h5ad(h5ad_pth)
adata.write_zarr(zarr_pth)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_transpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_transpose_orig():

def _add_raw(adata, *, var_subset=slice(None)):
new = adata[:, var_subset].copy()
new.raw = adata
new.raw = adata.copy()
return new


Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def test_layers_view():
# TODO: This can be flaky. Make that stop
def test_view_of_view(matrix_type, subset_func, subset_func2):
adata = gen_adata((30, 15), X_type=matrix_type)
adata.raw = adata
adata.raw = adata.copy()
if subset_func is single_subset:
pytest.xfail("Other subset generating functions have trouble with this")
var_s1 = subset_func(adata.var_names, min_size=4)
Expand Down

0 comments on commit 8a70868

Please sign in to comment.