Skip to content

Revert "fix layer use_raw" #3154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion docs/release-notes/1.10.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
```

* Prevent empty control gene set in {func}`~scanpy.tl.score_genes` {pr}`2875` {smaller}`M Müller`
* Prevent `raw` conflict with `layer` in {func}`~scanpy.tl.score_genes` {pr}`3150` {smaller}`S Dicks`
* Fix `subset=True` of {func}`~scanpy.pp.highly_variable_genes` when `flavor` is `seurat` or `cell_ranger`, and `batch_key!=None` {pr}`3042` {smaller}`E Roellin`
* Add compatibility with {mod}`numpy` 2.0 {pr}`3065` and {pr}`3115` {smaller}`P Angerer`

Expand Down
6 changes: 1 addition & 5 deletions src/scanpy/_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,14 @@ def _check_array_function_arguments(**kwargs):
)


def _check_use_raw(
adata: AnnData, use_raw: None | bool, layer: str | None = None
) -> bool:
def _check_use_raw(adata: AnnData, use_raw: None | bool) -> bool:
"""
Normalize checking `use_raw`.

My intentention here is to also provide a single place to throw a deprecation warning from in future.
"""
if use_raw is not None:
return use_raw
if layer is not None:
return False
return adata.raw is not None


Expand Down
2 changes: 1 addition & 1 deletion src/scanpy/tools/_score_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def score_genes(
"""
start = logg.info(f"computing score {score_name!r}")
adata = adata.copy() if copy else adata
use_raw = _check_use_raw(adata, use_raw, layer)
use_raw = _check_use_raw(adata, use_raw)
if is_backed_type(adata.X) and not use_raw:
raise NotImplementedError(
f"score_genes is not implemented for matrices of type {type(adata.X)}"
Expand Down
18 changes: 0 additions & 18 deletions tests/test_score_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,6 @@ def test_layer():
np.testing.assert_array_equal(adata.obs["X_score"], adata.obs["test_score"])


def test_layer_with_raw():
adata = _create_adata(100, 1000, p_zero=0, p_nan=0)

sc.pp.normalize_per_cell(adata, counts_per_cell_after=1e4)
sc.pp.log1p(adata)

# score X
gene_set = adata.var_names[:10]
sc.tl.score_genes(adata, gene_set, score_name="X_score")
# score layer (`del` makes sure it actually uses the layer)
adata.layers["test"] = adata.X.copy()
adata.raw = adata
del adata.X
sc.tl.score_genes(adata, gene_set, score_name="test_score", layer="test")

np.testing.assert_array_equal(adata.obs["X_score"], adata.obs["test_score"])


@pytest.mark.parametrize("gene_pool", [[], ["foo", "bar"]])
def test_invalid_gene_pool(gene_pool):
adata = _create_adata(100, 1000, p_zero=0, p_nan=0)
Expand Down
Loading