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
fixing gzip import issue 2774 #2783
Conversation
Thanks for the fix @abostroem--unfortunately I don't think this quite did it. This is tricky because really there are two So really what this needs is something at the top like:
and then replace all instances of It's ugly but it might have to do. |
For clarity the astropy gzip is called _astropy_gzip and the system gzip is called _system_gzip. All gzip.x statements have been changed to use the _astropy_gzip. All isinstances statements check both
Thanks to Matt Craig I ran this in python 2.6, all the io/fits tests passed |
Thanks, looks good. As one last thing would you mind implementing my suggestion of putting the two GzipFile types as a tuple in some global variable Then please also add a changelog entry under the 0.4.1 heading mentioning that this was fixed, along with the issue number (following the example of other entries). |
Oh, sorry, and if you don't mind could you add a regression test? Basically recreating the example from #2774 would suffice (just do the compression using the |
@embray I'm a little unclear on what regression test you want me to add. Should I zip one of the files in data in place, try to read it and then delete it at the end of the test? |
@embray I tried the above test using os.system call to gzip. Instead do you want me to do something like this? |
…er and passes for 0.4.1 and higher
@abostroem Take a look at the tests starting around https://github.com/astropy/astropy/blob/master/astropy/io/fits/tests/test_core.py#L588 which test other cases of reading and writing gzip files. This would be just one other such test but specifically implementing the case of #2774. In that issue @cdeil demonstrated the issue using a test data file that comes in the test suite--you can access it from within a test function using The trick would be to write the test first (without your fixes)--see that it fails--and then add your fixes on top and confirm that the test now passes. |
This test is a particularly good model since it's also a regression test for a bug: https://github.com/astropy/astropy/blob/master/astropy/io/fits/tests/test_core.py#L598 |
@embray I'm still a little confused, I think mostly because I'm not entirely clear on exactly what broke originally (what exactly is Table calling that is breaking), what _make_gzip does (how close to a real gzip object is this, is it a table?), what should be the length of the fits.open statement, and what does ignore_warnings do? This was the original test I wrote before you responded. It passes and fails in the correct places:
This is the function I wrote after your email, it passes in both 2.6 and 2.7. Suggestions?
I sound say my original code was a stand alone file while the second one is included in test_core.py |
The The original test you wrote is mostly fine. It should just make a few changes when integrating in with the the other tests:
|
Is this what you had in mind?
So now I have another problem. I've put the following on line 647 in test_core.py. I'm trying to run my test using astropy.test('io') but it doesn't seem to be picking it up my new test (when I delete the function is still runs the same number of tests and when I put something blatantly wrong in there it doesn't break (like assert 1 == 2). I did accidentally break another function so I know its looking at the right file. Do I have to do something else? |
Try just running,
No need to run all the |
The following should suffice:
This doesn't need to invoke @abostroem Just lemme know when you have time and I can walk you through rebasing and stuff if need be :) |
I should add, earlier I wrote:
My bad--there's nothing about this that is exclusive to tables. It's just that this code path was being invoked originally by way of |
This tests the utils.compat.gzip function's ability to open files
@embray I removed a few trailing spaces from my test, let's see if it passes this time... |
@abostroem What editor are you using? I would recommend finding out how to configure it to do this automatically; especially on .py files. |
@embray I use TextWrangler, I've just enabled it to strip trailing whitespace. Having done that, when I do a git status, neither the test_core.py nor file.py show up as modified. Is there something that will tell me where the trailing whitespace is? Additionally, astropy_helpers does show up as modified (even though I haven't touched it) and a diff shows this: Kyras-MacBook-Pro:astropy abostroem$ git diff Thoughts? |
@abostroem You can look at the Travis build that failed here. It shows that there is trailing whitespace at Sorry about this--I know it's pretty annoying (and for once not even my idea!). But I think ultimately a good thing in the long term. Don't worry about |
@embray Done! |
@@ -204,6 +204,8 @@ Bug Fixes | |||
|
|||
- ``astropy.io.fits`` | |||
|
|||
- Fix ability to read gzipped fits files using Python 2.6 [#2783] |
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.
Sorry, one last thing--could you fix this to read something more specific to how the original problem manifested? Something like:
Fixed crash when reading gzip-compressed FITS tables through the Astropy
``Table`` interface. [#2783]
Then also rebase your branch on upstream/master
and delete the merge commits from the history. See http://docs.astropy.org/en/stable/development/workflow/additional_git_topics.html?highlight=rebasing#rebasing-on-trunk (it talks about "trunk" for people coming from SVN, but it should probably say "master" instead of "trunk"--I'll see about rewriting that at some point).
…er and passes for 0.4.1 and higher
This tests the utils.compat.gzip function's ability to open files
@embray Let me know if this looks right. I followed the directions: git fetch upstream Looking at the commits I didn't see any merge commits, so I didn't modify the commit history. Since you said the real issue was not the call from Tables, do you want the commit message to reference the real issue. For now I copied what you wrote. |
I have no idea what's going on anymore because now you're including commits from other issues as well. I'm just going to merge this manually. |
Merged manually via 5d7acd6 Thanks again @abostroem , and indeed next time you'll probably have an easier time if you start a separate branch to work on the issue. |
I'm not sure if it's something I did, or if it was a result of refreshing the page or what, but now the commit history in this PR doesn't look as messed up as it did a few minutes ago! Nevertheless, when I did the merge I also squashed a few commits down (typo fixes and things like that). There was also a tab character in the changelog :( |
Changed import from:
import gzip
to:
from ...utils.compat import gzip
ran setup.py test and all io/fits tests passed. I don't have Python 2.6 to test that this really fixed the problem, but it should based on the comments in issue #2774