Skip to content

Fix lazy dataframe reindexing with unloaded annotation indexes - #2565

Open
ShreyanshGoyal wants to merge 1 commit into
scverse:mainfrom
ShreyanshGoyal:fix/concat-xarray-string-fill
Open

Fix lazy dataframe reindexing with unloaded annotation indexes#2565
ShreyanshGoyal wants to merge 1 commit into
scverse:mainfrom
ShreyanshGoyal:fix/concat-xarray-string-fill

Conversation

@ShreyanshGoyal

Copy link
Copy Markdown

Summary

Fix lazy concatenation of dataframe annotations when load_annotation_index=False and the datasets require outer reindexing.

Root cause

Lazy dataframe annotations retain a temporary range index while their real annotation index is stored separately as the true index. Dataset2D.reindex aligned against that temporary range index. With pandas 3 string dtypes, xarray then attempted to fill the string index variable with np.nan and raised DTypePromotionError.

Reindexing now works on a shallow copy whose computational index has first been switched to the true annotation index. The original lazy dataset remains unchanged.

Test plan

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.87%. Comparing base (b2e6177) to head (34da1cc).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2565      +/-   ##
==========================================
- Coverage   87.81%   85.87%   -1.95%     
==========================================
  Files          49       49              
  Lines        7799     7803       +4     
==========================================
- Hits         6849     6701     -148     
- Misses        950     1102     +152     
Files with missing lines Coverage Δ
src/anndata/_core/xarray.py 97.10% <100.00%> (+0.05%) ⬆️

... and 8 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pandas>=3 breaks with xarray.Dataset in obsm/varm when using anndata.concat and load_annotation_index

1 participant