Skip to content

Commit 5b1a8c5

Browse files
authored
fix: allow membership test for 2D GraphAcc (#2350)
1 parent 800df81 commit 5b1a8c5

5 files changed

Lines changed: 21 additions & 14 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55

66
- [ ] Closes #
77
- [ ] Tests added
8-
- [ ] Release note added (or unnecessary)
8+
9+
<!-- only check the following checkbox (and add a reason) if you want to skip release notes -->
10+
- [ ] Release note not necessary because:

.github/workflows/check-pr.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,27 @@ jobs:
3434
uses: flying-sheep/check@v1
3535
with:
3636
success: ${{ github.event.pull_request.user.login == 'pre-commit-ci[bot]' || github.event.pull_request.milestone != null || contains(env.LABELS, 'no milestone') }}
37-
- name: Check if the “Release notes” checkbox is checked and filled
37+
- name: Check if release notes are necessary
3838
uses: kaisugi/action-regex-match@v1.0.2
3939
id: checked-relnotes
4040
with:
4141
text: ${{ github.event.pull_request.body }}
42-
regex: '^\s*- \[x\].*Release note'
42+
regex: '^\s*- \[x\].*Release note not necessary because:\s*(.*)$'
4343
flags: m
4444
- name: Check if PR title is valid
4545
id: check-title
4646
uses: amannn/action-semantic-pull-request@v6
4747
env: # Needs repo options: “Squash and merge” with commit message set to “PR title”
4848
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4949
outputs:
50-
allow-no-relnotes: ${{ steps.checked-relnotes.outputs.match && true || false }}
50+
no-relnotes-reason: ${{ steps.checked-relnotes.outputs.group1 }}
5151
type: ${{ steps.check-title.outputs.type }}
5252
# This job verifies that the relevant release notes file has been modified.
5353
check-relnotes:
5454
name: Check for release notes
5555
runs-on: ubuntu-latest
5656
needs: check-milestone
57-
if: github.event.pull_request.user.login != 'pre-commit-ci[bot]' && needs.check-milestone.outputs.allow-no-relnotes && !contains(fromJSON('["style","refactor","test","build","ci"]'), needs.check-milestone.outputs.type)
57+
if: github.event.pull_request.user.login != 'pre-commit-ci[bot]' && needs.check-milestone.outputs.no-relnotes-reason == '' && !contains(fromJSON('["style","refactor","test","build","ci"]'), needs.check-milestone.outputs.type)
5858
steps:
5959
- uses: actions/checkout@v6
6060
with: { filter: 'blob:none', fetch-depth: 0 }

src/anndata/acc/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,11 @@ def isin(self, adata: AnnData, idx: Idx2D | None = None) -> bool:
499499
return False
500500
if idx is None:
501501
return True
502-
[i] = (i for i in idx if isinstance(i, str))
503-
return i in getattr(adata, self.dim).index
502+
match [i for i in idx if isinstance(i, str)]:
503+
case []:
504+
return True
505+
case [i]:
506+
return i in getattr(adata, self.dim).index
504507

505508
def get(self, adata: AnnData, idx: Idx2D, /) -> InMemoryArray:
506509
df = cast("pd.DataFrame", getattr(adata, self.dim))

tests/accessors/test_accessors.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from collections.abc import Callable, Collection
1818
from typing import Literal
1919

20-
from anndata.acc import AdRef
20+
from anndata.acc import AdRef, MapAcc
2121

2222

2323
type AdRefSer = Sequence[str | int | None]
@@ -36,6 +36,7 @@
3636
(A.layers["a"]["cell-77", :], ["layers", "a", "cell-77", None]),
3737
(A.obsm["umap"][0], ["obsm", "umap", 0]),
3838
(A.obsm["umap"][1], ["obsm", "umap", 1]),
39+
(A.varp["cons"][:, :], ["varp", "cons", None, None]),
3940
(A.varp["cons"]["gene-46", :], ["varp", "cons", "gene-46", None]),
4041
(A.varp["cons"][:, "gene-46"], ["varp", "cons", None, "gene-46"]),
4142
]
@@ -216,7 +217,7 @@ def test_special[C](
216217

217218

218219
@pytest.mark.parametrize(
219-
"ad_ref",
220+
"ref_or_acc",
220221
[
221222
*(p[0] for p in PATHS),
222223
A.X,
@@ -230,12 +231,12 @@ def test_special[C](
230231
],
231232
ids=str,
232233
)
233-
def test_in(adata: AnnData, ad_ref: AdRef) -> None:
234-
assert ad_ref in adata
234+
def test_in(adata: AnnData, ref_or_acc: AdRef | MapAcc) -> None:
235+
assert ref_or_acc in adata
235236

236237

237238
@pytest.mark.parametrize(
238-
"ad_ref",
239+
"ref_or_acc",
239240
[
240241
A.layers["a"]["gene-0", :], # not an obs name
241242
A.layers["a"][:, "cell-3"], # not a var name
@@ -250,8 +251,8 @@ def test_in(adata: AnnData, ad_ref: AdRef) -> None:
250251
],
251252
ids=str,
252253
)
253-
def test_not_in(adata: AnnData, ad_ref: AdRef) -> None:
254-
assert ad_ref not in adata
254+
def test_not_in(adata: AnnData, ref_or_acc: AdRef | MapAcc) -> None:
255+
assert ref_or_acc not in adata
255256

256257

257258
def test_not_in_empty(ad_ref: AdRef) -> None:

tests/accessors/test_get.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
(A.layers["a"]["cell-77", :], lambda ad: ad["cell-77"].layers["a"]),
4848
(A.obsm["umap"][0], lambda ad: asarray(ad.obsm["umap"])[:, 0]),
4949
(A.obsm["umap"][1], lambda ad: asarray(ad.obsm["umap"])[:, 1]),
50+
(A.varp["cons"][:, :], lambda ad: asarray(ad.varp["cons"])),
5051
(A.varp["cons"]["gene-46", :], lambda ad: asarray(ad.varp["cons"])[46, :]),
5152
(A.varp["cons"][:, "gene-46"], lambda ad: asarray(ad.varp["cons"])[:, 46]),
5253
]

0 commit comments

Comments
 (0)