Skip to content

Fix index types#2067

Merged
flying-sheep merged 10 commits into
mainfrom
pa/index-types
Jul 31, 2025
Merged

Fix index types#2067
flying-sheep merged 10 commits into
mainfrom
pa/index-types

Conversation

@flying-sheep
Copy link
Copy Markdown
Member

@flying-sheep flying-sheep commented Jul 31, 2025

Ilan made some good progress here, so this is intended to finish things up.

We have two “deal with indices” helpers in anndata._core: .index._normalize_index which accepts broad user-supplied types and unifies them into simple versions, and .views._resolve_idxs which simplifies multiple successive indexing operations (views of views).

Currently we have several “1D” (along the obs or var axis) index types which I’ll refer to by their name in the code:

  1. Index1D: to capture user-supplied values like list[str], int, pd.Series[bool] and so on.
  2. Index1DNorm (new): stored in anndata views as _oidx/_vidx: Can be a slice or np.ndarray with dtype np.bool_ or np.integer
  3. what we pass to _init_as_actual: can be Index1DNorm or an int/np.integer. We should probably get rid of this and sliceify 0D indices in _normalize_index

TODO:

  • check if all advertised types work and clarify (e.g. which pd.Index[???] do we support?)
  • check if subsetting views works in all permutations (e.g. mask → slice or mask → ndarray)

Comment thread src/anndata/compat/__init__.py Outdated
Comment on lines +47 to +48
| pd.Series # bool, int, str
| pd.Index
Copy link
Copy Markdown
Member Author

@flying-sheep flying-sheep Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think we test these (at least not via subset_func and therefore with test_views_of_views)

@flying-sheep flying-sheep marked this pull request as ready for review July 31, 2025 12:15
@flying-sheep flying-sheep added this to the 0.12.2 milestone Jul 31, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 91.07143% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.55%. Comparing base (7ff7e3b) to head (66d90f1).
⚠️ Report is 49 commits behind head on main.

Files with missing lines Patch % Lines
src/anndata/tests/helpers.py 81.81% 4 Missing ⚠️
src/anndata/_core/views.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2067      +/-   ##
==========================================
- Coverage   86.81%   85.55%   -1.26%     
==========================================
  Files          46       46              
  Lines        7052     7067      +15     
==========================================
- Hits         6122     6046      -76     
- Misses        930     1021      +91     
Files with missing lines Coverage Δ
src/anndata/_core/anndata.py 83.07% <100.00%> (+0.17%) ⬆️
src/anndata/_core/index.py 92.65% <100.00%> (ø)
src/anndata/_core/raw.py 75.53% <100.00%> (-4.32%) ⬇️
src/anndata/_core/xarray.py 98.39% <100.00%> (+21.39%) ⬆️
src/anndata/compat/__init__.py 80.90% <100.00%> (+0.17%) ⬆️
src/anndata/_core/views.py 85.83% <87.50%> (-5.31%) ⬇️
src/anndata/tests/helpers.py 82.72% <81.81%> (-10.83%) ⬇️

... and 6 files with indirect coverage changes

@flying-sheep flying-sheep merged commit 89fbfdc into main Jul 31, 2025
16 of 19 checks passed
@flying-sheep flying-sheep deleted the pa/index-types branch July 31, 2025 12:57
meeseeksmachine pushed a commit to meeseeksmachine/anndata that referenced this pull request Jul 31, 2025
flying-sheep added a commit that referenced this pull request Jul 31, 2025
Co-authored-by: Philipp A <flying-sheep@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant