This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: colorsys.rgb_to_hsv always returns saturation as 0 (python2.7 only)
Type: behavior Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Will Pittman, mark.dickinson
Priority: normal Keywords:

Created on 2017-02-22 19:31 by Will Pittman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg288380 - (view) Author: Will Pittman (Will Pittman) Date: 2017-02-22 19:31
colorsys.rgb_to_hsv appears to be broken on python2.7.13 (on archlinux).
Saturation is always reported as 0.

ex:

import colorsys
rgb_to_hsv( 127, 116, 18 )
>>> (0.16666666666666666, 0, 127)
msg288381 - (view) Author: Will Pittman (Will Pittman) Date: 2017-02-22 19:42
The bug appears to be caused by the difference in division
symbols between python3 vs python2.

The issue appears to be resolved if you add the following line to the
`/usr/lib/python2.7.13/colorsys.py` module (or if all arguments are converted to floats).

from __future__ import division

I noticed that this bug persists all the back to at least python2.7.10
msg288383 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2017-02-22 20:42
The arguments to rgb_to_hsv are supposed to be floating-point numbers in the range 0.0 to 1.0. That's documented here: https://docs.python.org/2/library/colorsys.html

> Coordinates in all of these color spaces are floating point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1.
msg288386 - (view) Author: Will Pittman (Will Pittman) Date: 2017-02-22 22:14
oh, thank you very much and sorry for my negligence!
msg288472 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2017-02-23 19:30
No problem. I did spend some time wondering whether `rgb_to_hsv` still gives the correct results if any of the inputs happens to be an integer (though still in the range [0, 1]). It looks as though it does, though.
History
Date User Action Args
2022-04-11 14:58:43adminsetgithub: 73811
2017-02-23 19:30:31mark.dickinsonsetmessages: + msg288472
2017-02-22 22:14:08Will Pittmansetstatus: open -> closed

messages: + msg288386
stage: resolved
2017-02-22 20:42:16mark.dickinsonsetnosy: + mark.dickinson
messages: + msg288383
2017-02-22 19:52:51Will Pittmansettitle: colorsys.rgb_to_hsv always returns saturation as 0 (python2.7.13 only) -> colorsys.rgb_to_hsv always returns saturation as 0 (python2.7 only)
2017-02-22 19:42:10Will Pittmansetmessages: + msg288381
2017-02-22 19:31:31Will Pittmancreate