From 9a37d1a0c551c0db85c6817f3b14a882bc3ee4e0 Mon Sep 17 00:00:00 2001 From: Eric Prestat Date: Mon, 1 Nov 2021 14:20:25 +0000 Subject: [PATCH] Improve error message when plotting lazy signal of ragged array --- hyperspy/_signals/lazy.py | 2 ++ hyperspy/tests/drawing/test_plot_signal.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hyperspy/_signals/lazy.py b/hyperspy/_signals/lazy.py index 908f76af4c..ecab8c00a2 100644 --- a/hyperspy/_signals/lazy.py +++ b/hyperspy/_signals/lazy.py @@ -1102,6 +1102,8 @@ def post(a): print("\n".join([str(pr) for pr in to_print])) def plot(self, navigator='auto', **kwargs): + if self.axes_manager.ragged: + raise RuntimeError("Plotting ragged signal is not supported.") if isinstance(navigator, str): if navigator == 'spectrum': # We don't support the 'spectrum' option to keep it simple diff --git a/hyperspy/tests/drawing/test_plot_signal.py b/hyperspy/tests/drawing/test_plot_signal.py index 5f1dcd2e66..ee308dc23e 100644 --- a/hyperspy/tests/drawing/test_plot_signal.py +++ b/hyperspy/tests/drawing/test_plot_signal.py @@ -333,10 +333,13 @@ def test_plot_signal_scalar(): assert s._plot is None -def test_plot_ragged_array(): +@pytest.mark.parametrize('lazy', [True, False]) +def test_plot_ragged_array(lazy): data = np.empty((2, 5), dtype=object) data.fill(np.array([10, 20])) s = hs.signals.BaseSignal(data, ragged=True) + if lazy: + s = s.as_lazy() with pytest.raises(RuntimeError): s.plot()