diff --git a/CHANGES.rst b/CHANGES.rst index 53da0e9053..c6f6ccfc33 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,6 +23,7 @@ RELEASE_next_patch (Unreleased) * Fix ``find_peaks`` GUIs call with laplacian/difference of gaussian methods (`#2622 `_ and `#2647 `_) * Added lazy reading support for FFT and DPC datasets in FEI emd datasets (`#2651 `_). * Fix various future and deprecation warnings from numpy and scikit-learn (`#2646 `_) +* Improve error message when initialising SpanROI with left >= right (`#2604 `_) Changelog diff --git a/hyperspy/misc/label_position.py b/hyperspy/misc/label_position.py index 2aba307abf..ed5a260bdc 100644 --- a/hyperspy/misc/label_position.py +++ b/hyperspy/misc/label_position.py @@ -219,9 +219,8 @@ def _text_parser(self, text_edge): element, subshell = text_edge.split('_') if subshell[-1].isdigit(): - formatted = element+' '+'$\mathregular{'+subshell[0]+'_'+\ - subshell[-1]+'}$' + formatted = f"{element} {subshell[0]}$_{subshell[-1]}$" else: - formatted = element+' '+'$\mathregular{'+subshell[0]+'}$' + formatted = f"{element} {subshell[0]}" return formatted diff --git a/hyperspy/roi.py b/hyperspy/roi.py index 2b55ab5c9f..c7c150139c 100644 --- a/hyperspy/roi.py +++ b/hyperspy/roi.py @@ -702,16 +702,16 @@ class SpanROI(BaseInteractiveROI): _ndim = 1 def __init__(self, left, right): - super(SpanROI, self).__init__() - self._bounds_check = True # Use reponsibly! + super().__init__() + self._bounds_check = True # Use responsibly! + if left >= right: + raise ValueError(f"`left` ({left}) must be smaller than `right` ({right}).") self.left, self.right = left, right def __getitem__(self, *args, **kwargs): _tuple = (self.left, self.right) return _tuple.__getitem__(*args, **kwargs) - - def is_valid(self): return (t.Undefined not in (self.left, self.right) and self.right >= self.left) diff --git a/hyperspy/tests/utils/test_roi.py b/hyperspy/tests/utils/test_roi.py index daf1f03d18..9f5415de4c 100644 --- a/hyperspy/tests/utils/test_roi.py +++ b/hyperspy/tests/utils/test_roi.py @@ -104,6 +104,12 @@ def test_point2d_getitem(self): r = Point2DROI(1, 2) assert tuple(r) == (1, 2) + def test_span_roi_init(self): + with pytest.raises(ValueError): + SpanROI(30, 15) + with pytest.raises(ValueError): + SpanROI(15, 15) + def test_span_spectrum_nav(self): s = self.s_s r = SpanROI(15, 30) diff --git a/hyperspy/ui_registry.py b/hyperspy/ui_registry.py index 86566818c0..72207be9db 100644 --- a/hyperspy/ui_registry.py +++ b/hyperspy/ui_registry.py @@ -18,7 +18,7 @@ """Registry of user interface widgets. -Format {"tool_key" : {"toolkit" : }} +Format {"tool_key" : {"toolkit" : }} The ``tool_key`` is defined by the "model function" to which the widget provides and user interface. That function gets the widget function from this registry diff --git a/hyperspy/utils/__init__.py b/hyperspy/utils/__init__.py index a7407de172..a713d1f444 100644 --- a/hyperspy/utils/__init__.py +++ b/hyperspy/utils/__init__.py @@ -48,7 +48,7 @@ def print_known_signal_types(): - """Print all known `signal_type`\s + r"""Print all known `signal_type`\s This includes `signal_type`\s from all installed packages that extend HyperSpy.