Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message initialisation SpanROI #2604

Merged
merged 6 commits into from Mar 4, 2021

Conversation

ericpre
Copy link
Member

@ericpre ericpre commented Dec 22, 2020

Progress of the PR

  • Improve error message when initialising ROI with left >= right.
  • add tests,
  • update changelog,
  • ready for review.

Minimal example of the bug fix or the new feature

import hyperspy.api as hs
hs.roi.SpanROI(30, 15)

raises an confusing message:

Traceback (most recent call last):

  File "<ipython-input-1-1e344269bc12>", line 2, in <module>
    hs.roi.SpanROI(30, 15)

  File "/home/eric/Dev/hyperspy/hyperspy/roi.py", line 688, in __init__
    self.left, self.right = left, right

  File "/opt/miniconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 346, in __call__
    handle_exception(object, trait_name, old, new)

  File "/opt/miniconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 148, in _handle_exception
    raise excp

  File "/opt/miniconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 340, in __call__
    self.handler(*args)

  File "/home/eric/Dev/hyperspy/hyperspy/roi.py", line 703, in _right_changed
    self.right = old

  File "/opt/miniconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 346, in __call__
    handle_exception(object, trait_name, old, new)

  File "/opt/miniconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 148, in _handle_exception
    raise excp

  File "/opt/miniconda3/lib/python3.8/site-packages/traits/trait_notifiers.py", line 340, in __call__
    self.handler(*args)

  File "/home/eric/Dev/hyperspy/hyperspy/roi.py", line 702, in _right_changed
    self.left is not t.Undefined and new <= self.left:

TypeError: '<=' not supported between instances of '_Undefined' and 'float'

With this PR:

Traceback (most recent call last):

  File "<ipython-input-1-1e344269bc12>", line 2, in <module>
    hs.roi.SpanROI(30, 15)

  File "/home/eric/Dev/hyperspy/hyperspy/roi.py", line 689, in __init__
    raise ValueError("`left` must be smaller than `right`.")

ValueError: `left` must be smaller than `right`.

@codecov
Copy link

codecov bot commented Dec 22, 2020

Codecov Report

Merging #2604 (93b9feb) into RELEASE_next_patch (8394ef0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##           RELEASE_next_patch    #2604   +/-   ##
===================================================
  Coverage               76.44%   76.44%           
===================================================
  Files                     202      202           
  Lines                   29686    29688    +2     
  Branches                 6492     6493    +1     
===================================================
+ Hits                    22694    22696    +2     
  Misses                   5223     5223           
  Partials                 1769     1769           
Impacted Files Coverage Δ
hyperspy/ui_registry.py 41.66% <ø> (ø)
hyperspy/utils/__init__.py 100.00% <ø> (ø)
hyperspy/misc/label_position.py 86.55% <100.00%> (ø)
hyperspy/roi.py 77.34% <100.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8394ef0...0ca2b39. Read the comment docs.

@ericpre
Copy link
Member Author

ericpre commented Feb 2, 2021

@magnunor, @thomasaarholt, this PR is simple, can one of you two please review it?

Copy link
Contributor

@magnunor magnunor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement! Good error messages are important.

Some comments in the code.

hyperspy/roi.py Outdated Show resolved Hide resolved
hyperspy/roi.py Outdated Show resolved Hide resolved
@ericpre
Copy link
Member Author

ericpre commented Feb 2, 2021

All done with a a few deprecation warning fixes.

@ericpre ericpre added this to the v1.6.2 milestone Feb 27, 2021
@ericpre ericpre merged commit b191b19 into hyperspy:RELEASE_next_patch Mar 4, 2021
@ericpre ericpre deleted the check_init_spanROI branch March 4, 2021 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants