-
-
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
Improve error message for scaled units in FITS #1979
Comments
Hey I am new to open source development, and am very excited about working with astropy. Since, I might not be qualified enough to fix most of the issues, this seems relatively easy. I have been doing research for about 2 days now, and I cannot seem to figure it out. Can you suggest me how to go about this. I am willing to learn anything i don't yet know. Thank you! |
@krngrvr09 - welcome! This particular error message is generated in
I think it is also a good idea to include a pointer to documentation, but am actually not sure where to find this (does it exist?). So, that might be part of the PR... |
@mhvk - I was chatting with @krngrvr09 on IRC and we thought it would be handy to have the exception be raised in |
@mhvk - the low level error message is not terrible, since normally a user would hit this when specifically doing |
I have been trying to understand the codebase of astropy. I have been successfully able to pass the column name, units, scale and link to the documentation in the error raised. The only question remains, what should I check for? |
@krngrvr09 - this exception will be raised for any unit which has a scale that is not just given by a prefix; so, e.g., Generally, I do not think you should be checking whether a unit may fail higher up -- the check should only happen in one location (after all, the fits standard may evolve or we manage to solve it another way; e.g., the example above we could already solve within the fits standard). Instead, I think it is better to try to catch the exception, as in:
(Note: I have not looked how the code higher up actually works and thus do not know how practical this is.) |
@krngrvr09 - following on from what @mhvk said, I've outlined a couple of key elements for a solution to get you going in the right direction. I made a local branch and edited entirely via the web interface (nice!). You can see the lines at: https://github.com/taldcroft/astropy/compare/scale-error-demo#diff-0 The idea is to make a specific exception class in the low level routine, and catch only that error in the high level one. |
Note also this is purposely rough and might have errors! :-) |
Alright, so finally, I have made all the required changes, and pushed it to my forked repository. I want you all to review it once, and suggest any changes. https://github.com/krngrvr09/astropy/compare/astropy:master...master Should I send the pull request? |
@krngrvr09 - looking at that branch it looks mostly OK except for some minor issues:
For the final issue you can try squashing with git, or else just start over with a new branch (based off the most recent master) and make the changes over again. Sometimes the manual approach ends up being faster. |
One more thing is that you will eventually need to add a test case which shows that the new error handling works as expected. |
Note: we need to make sure that the tar file doesn't end up in the final commits for this PR. |
Everything done. just need to add the test case. |
Looks good enough for a pull request. |
I have been searching the net, but couldn't find any valuable resource. Can anyone guide me on how to write test cases for this particular fix. Although, I am well acquainted with python, it seems necessary to take help, when working with such a big project, for the first time. Thank You! |
Maybe something like this might work for you?
|
Another standard option is to use pytest.raises. There is a very brief introduction here: So I think you'll want to make a Table object that has the unit as |
In general use |
The standard in most of the rest of astropy is:
|
We should probably describe this in the developer docs btw. |
Thank you everyone for your advice. |
@astrofrog -- there is a mention of testing, including how to check for an error in the rearrangement at #1712 , though it is a little buried. You can find it in the worked example of contributing code. |
@astrofrog See I didn't even know you could do that. Or if I did I forgot :) |
Actually I usually do:
because I think that |
@embray @taldcroft @astrofrog Why is this issue still open? #2023 was merged and at least seems to fix it (looking at the name not at the code). One of the GSoC students intends to work on this and wants to see if this is still viable. |
Actually I'm not sure. I feel like maybe #2023 didn't fully implement the desired fix, but reading through things I'm not sure. I'll just close it for now, but if anyone thinks the current fix is insufficient they can open a new issue I guess. |
Issue #1976 highlighted some confusion when trying to write (to FITS) a table with scaled units. In this case it was a field with
%
as the unit. The error message in this case is:This is essentially correct, but misses a lot of the information a user actually needs to understand what is happening and how to fix it. This is particularly the case for users without a deep understanding of units and what
scale
means in that context.Suggest improving the error message to include:
Marked as Easy and milestoned for 0.3.1.
The text was updated successfully, but these errors were encountered: