Fix read-only error in NaN reorder test under pandas >=3#85
Merged
Conversation
test_reorder_categories_with_nan_values injected a NaN via an in-place `adata.obs.loc[idx, "leiden"] = np.nan`. The fixture builds its AnnData and runs sc.pp.filter_cells, which subsets the object and leaves obs backing arrays read-only. pandas >=3 strictly refuses in-place mutation of read-only arrays, so the assignment raised "ValueError: assignment destination is read-only" (seen only in the py3.14-pre / pre-release-deps CI job). Inject the NaN on a writable copy and reassign the whole column, which avoids the in-place write. The test's intent (reorder_categories must preserve NaNs) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #85 +/- ##
==========================================
- Coverage 80.83% 80.75% -0.08%
==========================================
Files 15 15
Lines 1372 1372
==========================================
- Hits 1109 1108 -1
- Misses 263 264 +1 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix
test_reorder_categories_with_nan_values, which fails only in thepy3.14-pre (PRE-RELEASE DEPENDENCIES)CI job with:Root cause
The test injected a NaN with an in-place write:
The fixture (
get_example_data) runssc.pp.filter_cells, which subsets the AnnData; anndata leaves the resultingobsbacking arrays read-only. pandas >= 3 strictly refuses in-place mutation of read-only arrays, so the assignment raises. (On pandas 2.x the in-place write silently copied, so it passed — hence this only surfaced once a pandas 3 pre-release entered the pre-release matrix.)This is a real forward-compatibility issue with the test's mutation pattern, not a masking workaround. The package code itself is unaffected —
reorder_categoriesreassigns whole columns viacat.set_categories.Fix
Inject the NaN on a writable copy and reassign the whole column:
Test intent (reorder must preserve NaNs) is unchanged.
Verification
Reproduced faithfully (AnnData +
sc.pp.filter_cells+ the assignment) on pandas 3.0.3: the old pattern raisesassignment destination is read-only; the new pattern succeeds (nan_count == 1). CI on this PR exercises the realpy3.14-prejob.🤖 Generated with Claude Code