You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should LinearColormap.to_step(n=1) create a one-step colormap? #222
LinearColormap(...).to_step(n=1) raises a ZeroDivisionError.
In map/choropleth workflows, after filtering or classification, there may be only one bucket/class to display, and a one-step colormap seems semantically reasonable.
The API says n is the expected number of colors in the output StepColormap. When no index/data is supplied it constructs a regular grid from n; later, it computes colors using n - 1.0, which fails at n=1.
Possibilities:
Could to_step(n=1) to return a StepColormap with one color/bin?
Or should n <= 1 be explicitly rejected with a clear ValueError?
Or a mention in the docs stating that callers need to special-case single-class data?
Opened #227 for this, taking the first of your three options (return a one-bin StepColormap).
One thing worth noting for anyone hitting this: it isn't limited to to_step(n=1). n is recomputed as len(index) - 1 before the color loop, so any call producing a two-element index raises the same ZeroDivisionError — an explicit index=[0, 1], and the data= variants for the linear, log and quantiles methods. Five paths in total, all covered by the tests in that PR.
As a workaround until it lands, passing index with three entries and discarding the extra bin avoids the crash.
Activity
Htet-Kaung-San commentedon Jul 25, 2026
Opened #227 for this, taking the first of your three options (return a one-bin
StepColormap).One thing worth noting for anyone hitting this: it isn't limited to
to_step(n=1).nis recomputed aslen(index) - 1before the color loop, so any call producing a two-element index raises the sameZeroDivisionError— an explicitindex=[0, 1], and thedata=variants for the linear, log and quantiles methods. Five paths in total, all covered by the tests in that PR.As a workaround until it lands, passing
indexwith three entries and discarding the extra bin avoids the crash.