Skip to content

docs: correct/complete NaN, masked, and infinity docs - #149

Open
matthiasschabel wants to merge 2 commits into
pyapp-kit:mainfrom
matthiasschabel:docs/exceptional-values
Open

docs: correct/complete NaN, masked, and infinity docs#149
matthiasschabel wants to merge 2 commits into
pyapp-kit:mainfrom
matthiasschabel:docs/exceptional-values

Conversation

@matthiasschabel

@matthiasschabel matthiasschabel commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Depends on #148. This branch assumes that PR, so the diff below contains both. Only the second commit, e53f057, belongs to this one; #148 should be reviewed and merged first.

The bad parameter is documented as the color for "bad (NaN, inf) values" (src/cmap/_colormap.py:137), but infinities never reach it. Verified routing on main:

input uses when that color is unset
below 0, and negative infinity under_color first ramp color
above 1, and positive infinity over_color last ramp color
NaN, and masked entries bad_color transparent

Infinity is not special-cased anywhere; it falls out of the xa < 0 and xa >= N comparisons.

Corrected in the four places a reader looks: the constructor parameters, the under_color / over_color / bad_color attributes, lut (which omitted masked values), and __call__, which was silent on all of this.

Two details that shaped the wording:

  • The __call__ text is scoped to float input. Integer input indexes the LUT directly, so an integer 2 with N=4 is a ramp color, not over; only an index at or beyond N leaves the ramp, and a negative index uses under_color rather than wrapping.
  • "When no under color is set" rather than "if not provided", since a catalog entry can supply one (napari:HiLo carries under and over, napari:nan carries bad).

Documentation only. The masked-entry line is accurate once #148 lands; it matches what docs/faq.md already promises.

This PR doesn't touch the question of adding separate infinity colors from #144.

matthiasschabel and others added 2 commits August 9, 2026 14:51
The mask and the nan test were exclusive, so a masked array's unmasked
nans were never found. Such a value survived to the int cast, where it
became INT_MIN, and take(..., mode="clip") clipped it to index 0: nan
rendered as the colormap's first ramp color instead of `bad`, silently
and plausibly. The same values in a plain ndarray render correctly, so
the two input types disagreed about identical data.

`bad` is documented as the color for values that are "NaN or masked"
(docs/faq.md), so this restores the stated contract.

The nan test is applied only to float dtypes on the masked path,
keeping object-dtype masked arrays working, and the mask is combined
with `|` rather than `|=` so the caller's own mask is left alone.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reviewed-By: Codex (gpt-5.6-sol, reasoning effort xhigh)
The `bad` parameter was documented as the color for "(NaN, inf)"
values, but infinities are not routed there: negative infinity uses
`under` and positive infinity uses `over`, falling back to the first
and last ramp colors when unset. `__call__`, the primary API, said
nothing about exceptional values at all.

Documents the routing where a reader looks for it: the constructor
parameters, the under/over/bad attributes, `__call__`, and `lut`. The
`__call__` text is scoped to float input, since integer input indexes
the LUT directly and only leaves the ramp at or beyond N, or below 0.
"When no ... color is set" rather than "if not provided", because a
catalog entry can supply one (napari:HiLo, napari:nan).

Documentation only; no behavior change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Reviewed-By: Codex (gpt-5.6-sol, reasoning effort xhigh)
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.57%. Comparing base (8040ef7) to head (e53f057).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #149   +/-   ##
=======================================
  Coverage   95.56%   95.57%           
=======================================
  Files         168      168           
  Lines        2186     2190    +4     
=======================================
+ Hits         2089     2093    +4     
  Misses         97       97           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matthiasschabel matthiasschabel changed the title docs: correct and complete the NaN, masked, and infinity documentation docs: correct/complete NaN, masked, and infinity docs Aug 9, 2026
@matthiasschabel
matthiasschabel marked this pull request as ready for review August 9, 2026 22:48
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.

1 participant