-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Improved error message for scale units in FITS. #2023
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,11 @@ | |
from . import utils | ||
from ...utils.misc import did_you_mean | ||
|
||
class UnitScaleError(ValueError): | ||
""" | ||
Used to catch the errors involving scaled units, | ||
which are not recognized by FITS format. | ||
""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdboom - is there a better place to keep this kind of exception? It could be more general than FITS, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and no. The FITS unit format is the only one that doesn't support scale. However, it might make more sense to put it in |
||
class Fits(generic.Generic): | ||
""" | ||
|
@@ -119,7 +124,7 @@ def to_string(self, unit): | |
|
||
if isinstance(unit, core.CompositeUnit): | ||
if unit.scale != 1: | ||
raise ValueError( | ||
raise UnitScaleError( | ||
"The FITS unit format is not able to represent scale. " | ||
"Multiply your data by {0:e}.".format(unit.scale)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor esthetic changes. You only use
col_unit
once, so I think you could just leave:since you don't gain anything from defining the intermediate variable
col_unit
.For
scale
, it does make sense to define it because it does help the readability in the exception, but you can move theline inside the
except
clause, because it's only needed then. That is:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That had actually been my suggestion in the first place; earlier the exception message I suggested used the unit name in the message, so it was used twice. But now I agree it's not needed more than once.