python-visualization / python-visualization/branca

Colors given as tuple of ints are not working anymore for LinearColormap and StepColormap since v0.8.0

Open
#190 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
134
Forks
69
Avg merge
1h 10m
Merged PRs (30d)
1

Description

When I create a LinearColormap or a StepColormap with a list of tuples of ints as argument for the colors parameter, it is no longer converted to floats and leads to incorrect results.

Current behaviour (v0.8.0 v0.8.1):

>>> from branca.colormap import LinearColormap
>>> colormap = LinearColormap(colors=[(128, 64, 255), (255, 128, 0)])
>>> colormap.colors
[(128, 64, 255, 1.0), (255, 128, 0, 1.0)]
>>> colormap.rgb_bytes_tuple(0)
(32767, 16383, 65279)
>>> colormap.rgba_floats_tuple(1)
(255, 128, 0, 1.0)

Expected behaviour (v0.7.2):

>>> from branca.colormap import LinearColormap
>>> colormap = LinearColormap(colors=[(128, 64, 255), (255, 128, 0)])
>>> colormap.colors
[(0.5019607843137255, 0.25098039215686274, 1.0, 1.0), (1.0, 0.5019607843137255, 0.0, 1.0)]
>>> colormap.rgb_bytes_tuple(0)
(128, 64, 255)
>>> colormap.rgba_floats_tuple(1)
(1.0, 0.5019607843137255, 0.0, 1.0)

This seems to be due to the internal _parse_color function that was broken in https://github.com/python-visualization/branca/commit/8a8a2141c13947f6afaaf65a8c29c4417cd3a5a3#diff-6886114fc8e4fd6197705978c768e1f49469e2455fb1c4a8efda26a7b11bfa0bL51.

Current behaviour (v0.8.0 v0.8.1):

>>> from branca.colormap import _parse_color
>>> _parse_color((128, 64, 255))
(128, 64, 255, 1.0)

Expected behaviour (v0.7.2):

>>> from branca.colormap import _parse_color
>>> _parse_color((128, 64, 255))
(0.5019607843137255, 0.25098039215686274, 1.0, 1.0)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at branca.colormap._parse_color and trace how LinearColormap and StepColormap pass their colors through it. Reproduce the integer-tuple examples from the issue, then verify that tuples are normalized to float color values and that rgb_bytes_tuple and rgba_floats_tuple produce the expected results for both colormap types.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.