diff --git a/bec_widgets/widgets/plots/image/image.py b/bec_widgets/widgets/plots/image/image.py index 14429080..89b25268 100644 --- a/bec_widgets/widgets/plots/image/image.py +++ b/bec_widgets/widgets/plots/image/image.py @@ -959,6 +959,8 @@ class Image(ImageBase): Returns: np.ndarray: The updated image buffer with adjusted shapes. """ + # Guard for wrong data shapes + new_data = np.atleast_1d(np.asarray(new_data)) new_len = new_data.shape[0] if not hasattr(image, "buffer"): image.buffer = [] diff --git a/tests/unit_tests/test_image_view_next_gen.py b/tests/unit_tests/test_image_view_next_gen.py index 4b2c8411..5749da44 100644 --- a/tests/unit_tests/test_image_view_next_gen.py +++ b/tests/unit_tests/test_image_view_next_gen.py @@ -1439,4 +1439,21 @@ def test_image_processor_log_is_finite_for_non_positive(): # maps to 0. assert out[0, 0] == pytest.approx(-1.0) assert out[1, 0] == pytest.approx(-1.0) - assert proc.log(np.array([[1.0]]))[0, 0] == pytest.approx(0.0) \ No newline at end of file + assert proc.log(np.array([[1.0]]))[0, 0] == pytest.approx(0.0) + + +############################################## +# Shape / dtype edge cases in the data path +############################################## + + +def test_adjust_image_buffer_coerces_list_and_scalar(qtbot, mocked_client): + """Non-ndarray payloads (python list, 0-d scalar) must not crash the + 1D buffer accumulation.""" + view = create_widget(qtbot, Image, client=mocked_client) + image = view.main_image + + buf = view.adjust_image_buffer(image, [1, 2, 3]) # python list + assert buf.shape == (1, 3) + buf = view.adjust_image_buffer(image, np.array(42.0)) # 0-d scalar + assert buf.shape[0] == 2 \ No newline at end of file