Fix visualization of unsigned integer attributes - #698
Open
tandede wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I found
Issue #671 reports that custom visualization labels stored as
np.uint8are displayed as class zero, while the same labels work correctly asnp.int64.I traced the difference to
Model._convert_to_numpy(). Its integer check usesary.dtype.name.startswith("int"), which recognizes signed NumPy integer names such asint64but not unsigned names such asuint8. Unsigned label arrays therefore bypass thefloat32conversion applied to signed labels.What I changed
I replaced the dtype-name prefix check with the NumPy semantic integer subtype check:
This covers both signed and unsigned NumPy integer types while continuing to exclude floating-point and boolean arrays. The existing flattening and
float32conversion behavior remains unchanged.I also added a parameterized regression test covering
uint8,uint16,uint32, anduint64. It verifies both the resultingfloat32dtype and preservation of the original label values.Result
Before the change, all four unsigned integer types remained unsigned after
_convert_to_numpy(). With the change, they follow the same conversion path as signed integer labels and produce value-preservingfloat32arrays.Verification
pytest -q tests/test_visualizer.py— 4 passedpython ci/check_style.py --verbose— passedgit diff --check— passedFixes #671.