Skip to content

Fix visualization of unsigned integer attributes - #698

Open
tandede wants to merge 1 commit into
isl-org:mainfrom
tandede:fix/visualizer-unsigned-labels
Open

Fix visualization of unsigned integer attributes#698
tandede wants to merge 1 commit into
isl-org:mainfrom
tandede:fix/visualizer-unsigned-labels

Conversation

@tandede

@tandede tandede commented Aug 24, 2026

Copy link
Copy Markdown

What I found

Issue #671 reports that custom visualization labels stored as np.uint8 are displayed as class zero, while the same labels work correctly as np.int64.

I traced the difference to Model._convert_to_numpy(). Its integer check uses ary.dtype.name.startswith("int"), which recognizes signed NumPy integer names such as int64 but not unsigned names such as uint8. Unsigned label arrays therefore bypass the float32 conversion applied to signed labels.

What I changed

I replaced the dtype-name prefix check with the NumPy semantic integer subtype check:

np.issubdtype(ary.dtype, np.integer)

This covers both signed and unsigned NumPy integer types while continuing to exclude floating-point and boolean arrays. The existing flattening and float32 conversion behavior remains unchanged.

I also added a parameterized regression test covering uint8, uint16, uint32, and uint64. It verifies both the resulting float32 dtype 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-preserving float32 arrays.

Verification

  • pytest -q tests/test_visualizer.py — 4 passed
  • python ci/check_style.py --verbose — passed
  • full repository pydocstyle check — passed
  • git diff --check — passed

Fixes #671.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error plotting custom data with np.uint8 dtype

1 participant