From dc5a39863f3cb6d10c2f12c120a788373d7ae87e Mon Sep 17 00:00:00 2001 From: tandede <1090179959@qq.com> Date: Mon, 24 Aug 2026 23:03:46 +0800 Subject: [PATCH] Fix visualization of unsigned integer attributes --- ml3d/vis/visualizer.py | 2 +- tests/test_visualizer.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/test_visualizer.py diff --git a/ml3d/vis/visualizer.py b/ml3d/vis/visualizer.py index 11116f5c1..f3eadf9f3 100644 --- a/ml3d/vis/visualizer.py +++ b/ml3d/vis/visualizer.py @@ -141,7 +141,7 @@ def _convert_to_numpy(self, ary): elif isinstance(ary, np.ndarray): if len(ary.shape) == 2 and ary.shape[0] == 1: ary = ary[0] # "1D" array as 2D: [[1, 2, 3,...]] - if ary.dtype.name.startswith('int'): + if np.issubdtype(ary.dtype, np.integer): return np.array(ary, dtype='float32') else: return ary diff --git a/tests/test_visualizer.py b/tests/test_visualizer.py new file mode 100644 index 000000000..39e8fbc55 --- /dev/null +++ b/tests/test_visualizer.py @@ -0,0 +1,14 @@ +import numpy as np +import pytest + +from ml3d.vis.visualizer import Model + + +@pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32, np.uint64]) +def test_unsigned_integer_attributes_are_converted_to_float32(dtype): + values = np.array([0, 1, 2], dtype=dtype) + + converted = Model()._convert_to_numpy(values) + + assert converted.dtype == np.float32 + np.testing.assert_array_equal(converted, values)