-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add Zip file functionality. Fixes #11413 #12103
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
Changes from 2 commits
7f3461c
2fc43b6
f5a641d
cf7c347
1b21456
b6939ea
56e55a6
40fe268
ee336f1
1c3ecd7
b3c21cf
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 |
---|---|---|
|
@@ -3809,12 +3809,36 @@ def test_decompression(self): | |
try: | ||
import gzip | ||
import bz2 | ||
import zipfile | ||
except ImportError: | ||
raise nose.SkipTest('need gzip and bz2 to run') | ||
raise nose.SkipTest('need zipfile, gzip and bz2 to run') | ||
|
||
data = open(self.csv1, 'rb').read() | ||
expected = self.read_csv(self.csv1) | ||
|
||
with tm.ensure_clean() as path: | ||
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. put the zipfile tests in a separate test. 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. pls split out the gzip/bz2 into separate tests as well, thanks 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. best would be to make a separate testing class for |
||
file_name = 'test_file' | ||
tmp = zipfile.ZipFile(path, mode='w') | ||
tmp.writestr(file_name, data) | ||
tmp.close() | ||
|
||
result = self.read_csv(path, compression='zip') | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = self.read_csv(open(path, 'rb'), compression='zip') | ||
tm.assert_frame_equal(result, expected) | ||
|
||
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. need a test for multiple files in a zip (e.g. assert that the |
||
|
||
with tm.ensure_clean() as path: | ||
file_names = ['test_file', 'second_file'] | ||
tmp = zipfile.ZipFile(path, mode='w') | ||
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. add in another test using |
||
for file_name in file_names: | ||
tmp.writestr(file_name, data) | ||
tmp.close() | ||
|
||
self.assertRaises(ValueError, self.read_csv, | ||
path, compression='zip') | ||
|
||
with tm.ensure_clean() as path: | ||
tmp = gzip.GzipFile(path, mode='wb') | ||
tmp.write(data) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -563,6 +563,18 @@ cdef class TextReader: | |
else: | ||
raise ValueError('Python 2 cannot read bz2 from open file ' | ||
'handle') | ||
elif self.compression == 'zip': | ||
import zipfile | ||
zip_file = zipfile.ZipFile(source) | ||
zip_names = zip_file.namelist() | ||
|
||
if len(zip_names) == 1: | ||
file_name = zip_names.pop() | ||
source = zip_file.open(file_name) | ||
|
||
elif len(zip_names)>1: | ||
raise ValueError('Multiple files found in compressed ' | ||
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. maybe just do |
||
'zip file %s', str(zip_names)) | ||
else: | ||
raise ValueError('Unrecognized compression type: %s' % | ||
self.compression) | ||
|
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.
can you add an explanation about .zip is only a single file