-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Raise ValueError for RGB values outside the [0, 1] range in rgb_to_hsv function #28948
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
lib/matplotlib/colors.py
Outdated
# Check if input is in the expected range | ||
if np.any(arr_max > 1) or np.any(arr < 0): | ||
raise ValueError("Input RGB values must be in the range [0, 1]. " | ||
f"Found values out of range in array: {arr}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Displaying the whole array generally does not make sense. Either leave out the value completely or state the offending max or min value; for example "Input RGB values must be in the range [0, 1]. Found a maximum of 253" may be a useful hint. When going with the values, you want to do two separate if statements and issue tailored messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I will change the code to address the issue with the error messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approval was premature. Please fix the above issue.
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
Co-authored-by: Tim Hoffmann <[email protected]>
I believe I've now addressed all raised points. Please let me know if any further adjustments are required. |
…v function (matplotlib#28948) * initial error correction * Remove unintentional white-space * Reorder closer to original * Remove unwanted whitespace * flake8 compliance * Improved Error messages * Update lib/matplotlib/colors.py Co-authored-by: Tim Hoffmann <[email protected]> * Update lib/matplotlib/colors.py Co-authored-by: Tim Hoffmann <[email protected]> * Update lib/matplotlib/colors.py Co-authored-by: Tim Hoffmann <[email protected]> * remove unnecessary arr_min calculation --------- Co-authored-by: Tim Hoffmann <[email protected]>
This change improves the
rgb_to_hsv
function by adding a clear and explicit error message when the input RGB values are outside the valid range [0, 1]. Previously, the error raised by NumPy was not intuitive, making it difficult for users to understand the issue. This update ensures that users are notified of the value range requirements upfront, enhancing usability and debugging experience.Fix #28941