Fix render_images(norm=LogNorm()) crash on zero/non-positive data#672
Merged
Conversation
render_images(norm=LogNorm()) crashed with an opaque matplotlib "Invalid vmin or vmax" when the image data was all zeros (or otherwise left LogNorm's vmin/vmax non-positive after autoscale). The default colorbar="auto" hit the crash without unusual args. Add a narrow guard at the start of _draw_colorbar: when the mappable norm is LogNorm and its (already autoscaled) bounds are invalid, emit a UserWarning pointing to colorbar=False / data clipping and skip the colorbar. The image artist itself still renders. Guard is class-specific so SymLogNorm (which legitimately supports zero/negative values) is unaffected. Closes #604
vmax <= 0 is implied by vmin <= 0 combined with vmin >= vmax (if vmin > 0 and vmin < vmax, then vmax > 0).
Drop the mixed-positives and SymLogNorm tests — they guarded against hypothetical future regressions rather than the actual bug. Keep just the zeros-only LogNorm regression test.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #672 +/- ##
==========================================
+ Coverage 77.63% 77.64% +0.01%
==========================================
Files 11 11
Lines 3612 3619 +7
Branches 850 853 +3
==========================================
+ Hits 2804 2810 +6
Misses 485 485
- Partials 323 324 +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.
Summary
render_images(norm=LogNorm())crashed with an opaque matplotlibValueError: Invalid vmin or vmaxwhenever the autoscaledvmin/vmaxended up non-positive (e.g. all-zero data, all-negative data, user-suppliedLogNorm(vmin=0,…)). The defaultcolorbar="auto"made this hit the standard call path._draw_colorbar(basic.py): if the mappable's norm isLogNormand its bounds are invalid, emit aUserWarningpointing tocolorbar=False/ data clipping and skip the colorbar. The image artist itself still draws.SymLogNorm(which legitimately handles zero/negative data via its linear region) is unaffected.Closes #604