Skip to content

Compatibility layer for pandas3 changing fill_value for sparse from 0 to NaN#1118

Closed
timtreis wants to merge 3 commits intomainfrom
bugfix/issue1113-integration-testing-ci-test-failure-on-python-312
Closed

Compatibility layer for pandas3 changing fill_value for sparse from 0 to NaN#1118
timtreis wants to merge 3 commits intomainfrom
bugfix/issue1113-integration-testing-ci-test-failure-on-python-312

Conversation

@timtreis
Copy link
Member

pandas 3.0 changed DataFrame.sparse.from_spmatrix to use fill_value=NaN instead of fill_value=0 for float columns (pandas PR #59064). With fill_value=NaN, groupby().mean() excludes those zeros from the denominator, inflating means and producing wrong results in ligrec.

The fix wraps the from_spmatrix call in PermutationTestABC.__init__ with a small helper that resets any fill_value=NaN sparse columns back to fill_value=0. It's skipped on pandas <3.

@timtreis timtreis linked an issue Feb 18, 2026 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.21%. Comparing base (3c11223) to head (2ecac93).

Files with missing lines Patch % Lines
src/squidpy/gr/_utils.py 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1118      +/-   ##
==========================================
- Coverage   66.21%   66.21%   -0.01%     
==========================================
  Files          44       44              
  Lines        7163     7168       +5     
  Branches     1217     1218       +1     
==========================================
+ Hits         4743     4746       +3     
- Misses       1943     1944       +1     
- Partials      477      478       +1     
Files with missing lines Coverage Δ
src/squidpy/gr/_ligrec.py 77.28% <100.00%> (ø)
src/squidpy/gr/_utils.py 60.34% <60.00%> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@selmanozleyen selmanozleyen changed the title Compatibility layer for pandas3 changing fill_value for soarse from 0 to NaN Compatibility layer for pandas3 changing fill_value for sparse from 0 to NaN Feb 19, 2026
@selmanozleyen
Copy link
Member

hi I have an alternative solution to this. Normally something simpler is enough for this PR but I also wanted to get rid of an unreliable function so I created this PR: #1119

@timtreis
Copy link
Member Author

timtreis commented Feb 19, 2026

Closed in favor of #1119

@timtreis timtreis closed this Feb 19, 2026
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.

Integration Testing CI Test Failure on python 3.12

2 participants