REF: Avoid divide by zero warnings when denominator is zero#440
Merged
Conversation
Avoid divide by zero warnings when denominator is zero: check that
values are nonzero before dividing; else, set all values to zero.
Add the corresponding tests.
Fixes:
```
test/test_integration.py: 15 warnings
/home/runner/work/nifreeze/nifreeze/src/nifreeze/data/filtering.py:107:
RuntimeWarning: invalid value encountered in divide
data /= data.max()
```
raised for example at:
https://github.com/nipreps/nifreeze/actions/runs/24288044855/job/70920601980?pr=313
ab8b0a6 to
0344cee
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #440 +/- ##
==========================================
+ Coverage 84.30% 84.46% +0.16%
==========================================
Files 37 37
Lines 2134 2156 +22
Branches 239 243 +4
==========================================
+ Hits 1799 1821 +22
Misses 296 296
Partials 39 39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
arokem
reviewed
Apr 13, 2026
Contributor
arokem
left a comment
There was a problem hiding this comment.
Good idea, but a couple of comments on implementation
Rename variable to avoid name ambiguity with the random number generator variable name and improve clarity. Co-authored-by: Ariel Rokem <arokem@gmail.com>
da62de7 to
f0469ce
Compare
Raise typed `ClippingValueError` for `advanced_clip` degeneracies: `advanced_clip()` now fails fast with explicit errors for: - empty percentile selection after applying nonnegative/finite constraints - non-finite percentile thresholds - invalid percentile thresholds (`a_max <= a_min`) - degenerate dynamic range after clipping/shift (`den == 0` or non-finite) Add the corresponding unit tests.
f0469ce to
7a4ec7f
Compare
mnoergaard
approved these changes
Apr 30, 2026
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.
Avoid divide by zero warnings when denominator is zero: check that values are nonzero before dividing; else, set all values to zero.
Add the corresponding tests.
Fixes:
raised for example at:
https://github.com/nipreps/nifreeze/actions/runs/24288044855/job/70920601980?pr=313