New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
to_rgb(float) or to_rgb(str(flot)) #2609
Comments
I don't immediately see any harm in making this accept a float. Hopefully the test suite will tell us if it's a problem.... |
Careful! I think this is a bad idea. Please just fix the documentation to make it consistent with the colors.py module docstring. Long ago we allowed both a float and a string, and it caused major problems--specifically, it makes it impossible to distinguish between an array of three greys and a single RGB tuple. Therefore we decreed that only a string representation of a float would be allowed to represent a grey value. |
Note that the existing to_rgb docstring does show the float as a string--the only ambiguity is whether that is done to set it apart from the rest of the sentence, or whether it means "a string representation of a float", which was the intention. So, you could explicitly disambiguate this, replacing "a float" with "a string representation of a float". |
Even if the docstring was saing it, emphasis that to_rgb/to_rgba do not accept float as input, but string representation of a float. As one might be tempted to had float->gray conversion add failing test in case the functionality is added. Side fixes : change tuple([value]*3) to (value,)*3 for speed In [18]: %timeit tuple([0.4]*3) 1000000 loops, best of 3: 505 ns per loop In [19]: %timeit (0.4,)*3 10000000 loops, best of 3: 23.5 ns per loop In [20]: (0.4,)*3 == tuple([0.4]*3) Out[20]: True Closes matplotlibgh-2609
Even if the docstring was saing it, emphasis that to_rgb/to_rgba do not accept float as input, but string representation of a float. As one might be tempted to had float->gray conversion add failing test in case the functionality is added. Side fixes : change tuple([value]*3) to (value,)*3 for speed In [18]: %timeit tuple([0.4]*3) 1000000 loops, best of 3: 505 ns per loop In [19]: %timeit (0.4,)*3 10000000 loops, best of 3: 23.5 ns per loop In [20]: (0.4,)*3 == tuple([0.4]*3) Out[20]: True Closes matplotlibgh-2609
According to the doc of
matplotlib.colors.ColorConverter.to_rgb
but
Should I correct/improve the doc ? or fix
to_rgb
to accept floats too ?Or am I missing something ?
pretty recent version:
The text was updated successfully, but these errors were encountered: