-
-
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
Conversation
table=Table.read(infile, format='ipac') | ||
table.write('table.fits',format='fits', overwrite=True) | ||
out = table.vstack([t1, t2, t4], join_type='outer') | ||
assert exc.__class__.__name__ == 'UnitScaleError' |
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.
The indentation is inconsistent here.
@krngrvr09 - it looks like the tests are failing. You can run the test suite locally bby doing:
do you get it to pass on your computer? |
"The column ' {0} ' could not be stored in FITS format " | ||
"because it has a scale ' ({1}) ' that " | ||
"is not recognized by the FITS standard. Either scale " | ||
"the data or change the units.".format(col.name, str(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.
This message looks great. Only one minor nitpick: I don't think we need the extra spaces inside the single quotes, i.e.: '{0}'
is fine, and I don't think we need the extra single quotes around {1}
, i.e.: ({1})
is fine.
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.
I usually don't make the quotes part of the format string at all and just use {0!r}
; then Python will use the appropriate quotes around the string.
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.
The problem with {0!r}
is that you can get u
prefixes on Python 2. Not terrible, but a little user unfriendly.
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.
Ah, true. That's why I also sometimes do repr(foo).lstrip('bu')
but that's probably almost uglier :) It's better practice in general in case the string you're inserting contains quotes itself but that isn't really an issue here I guess.
@astrofrog Yes, the tests were failing on my system too. I have fixed them. Hopefully everything seems good now. |
try: | ||
col.unit = col_unit.to_string(format='fits') | ||
except UnitScaleError: | ||
raise UnitScaleError( |
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:
col.unit = input[col.name].unit.to_string(format='fits')
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 the
scale = ...
line inside the except
clause, because it's only needed then. That is:
except:
scale = ...
raise UnitScaleError(...)
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.
@krngrvr09 - this is almost ready, I left a few comments above. |
@astrofrog I have deleted the line |
c = ['x', 'y', 'z'] | ||
t = Table([a, b, c], names=('a', 'b', 'c'), meta={'name': 'first table'}) | ||
t['a'].unit='percent' | ||
t.format='ipac' |
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 saw this line, which is not needed (t.format='ipac'
) - can you remove it?
@astrofrog Done. |
@krngrvr09 - this is looking good. It looks like there is a conflict in the changes compared to the latest version of Astropy, so you will need to rebase on the latest master of the main repository. Have you done this before? There are instructions provided here: http://docs.astropy.org/en/stable/development/workflow/development_workflow.html#rebase-on-trunk but if you have any issues it might be easier to chat about it live on IRC. I am not available right now, but you could go on during the week and ask if you have any issues. In any case, if you do mess up, then don't open a new pull request, because there is always a way we can recover. |
------- | ||
is_fits : bool | ||
Returns `True` if the given file is a FITS file. | ||
""" |
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.
It looks like this docstring has lost its indentation here. Each of these lines should have 4 spaces at the beginning.
@keflavich I have made the required changes. I hope, everything is now, Ok. But still if there are any other changes, to be made. Please suggest. @astrofrog I have been able to do the rebase. Apologies for the noise commits. Is there anything else, I have to do? |
@krngrvr09 - please look at the file diffs and eliminate any diffs that are not specifically related to the patch you are applying. There are still a number of diffs that are just noise and which incorrectly change the formatting. At this point the number of commits has gone over 50 during your learning process, so I think it's time for you to start over from scratch from the current master and apply your patch cleanly in a few commits. It's not too hard when you look at the file diffs. |
@krngrvr09 - by "start over" I mean:
Now based on the file diffs you currently see here, edit the appropriate files to replicate those diffs. Run tests locally to make sure everything works. Then:
Make sure that the only changes are ones related to your fix, and make sure that all the diffs you see in this branch currently on github are in your new patch. No extra whitespace or formatting changes. Finally, commit your changes and do a force push to github:
BTW, you could also squash all the 50 commits into 1. You can google on "git squash" to find some tutorials on how to do this. This will also require a force push to github. |
@taldcroft Thank you very much for your help. Honestly, I think, what we just did was very cool! |
Look good to me! |
Improved error message for scale units in FITS.
@krngrvr09 - merged, thanks! |
Thanks to the AstroPy community. I learned a lot! |
Improved error message for scale units in FITS. Conflicts: astropy/io/fits/connect.py astropy/io/fits/tests/test_connect.py
Fix for issue #1979.
Improved the error message and added a test case.
Please review the changes.