plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Fix an IndexError in .../figure_factory/_trisurf.py::map_face2color

Open wilhelm-now opened this issue 4 years ago • 3 comments

The function map_face2color in _trisurf.py compared face value (face) to max face value (vmax) and if equal did a quick exit by returning the last element in a list. Later it would compare normalized face value to indexed values. Because of floating point errors the normalized value could be 1.0 and lead to attempted look up at an index past the end of a list. This would raise an IndexError.

The essence of the problem is

def map_face2color(face, colormap, scale, vmin, vmax):
    if face == vmax: return colormap[-1];
    t = (face - vmin) / (vmax - vmin)  # normalized position
    # t can be equal to 1.0 even when face != vmax.
    # when t is equal to 1.0 finding first element past t in a list fails with IndexError

Code PR

  • [x] I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the codegen files and not generated files.
  • [x] I have added tests (if submitting a new feature or correcting a bug) or modified existing tests.
  • [ ] For a new feature, I have added documentation examples in an existing or new tutorial notebook (please see the doc checklist as well).
  • [ ] I have added a CHANGELOG entry if fixing/changing/adding anything substantial.
  • [ ] For a new feature or a change in behaviour, I have updated the relevant docstrings in the code to describe the feature or behaviour (please see the doc checklist as well).

wilhelm-now avatar Jun 05 '21 14:06 wilhelm-now

Would this be more interesting to merge if the content was reorganized? If so, how?

wilhelm-now avatar Jun 30 '21 06:06 wilhelm-now

This solves issue #3323

wilhelm-now avatar Jul 30 '21 19:07 wilhelm-now

https://guides.github.com/features/mastering-markdown/

majed282 avatar Aug 03 '21 08:08 majed282

@wilhelm-now thank you again for submitting this - I'm very sorry it's taken us so long to get to it, but we are no longer enhancing figure factory, so I'm going to close this one as stale. Best regards - @gvwilson

gvwilson avatar Aug 23 '24 14:08 gvwilson