Skip to content
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

BUG: fix scipy.io.mmread() of gzipped files under Python3 #3314

Merged
merged 2 commits into from
Feb 24, 2014

Conversation

andreas-h
Copy link
Contributor

fixes #2152

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8daf621 on andreas-h:gh2152 into * on scipy:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8daf621 on andreas-h:gh2152 into * on scipy:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8daf621 on andreas-h:gh2152 into * on scipy:master*.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 8daf621 on andreas-h:gh2152 into * on scipy:master*.

@@ -451,9 +452,14 @@ def _parse_body(self, stream):
return coo_matrix((rows, cols), dtype=dtype)

try:
# passing a gzipped file to fromfile/fromstring doesn't work
# with Python3
if sys.version_info >= (3, 0) and isinstance(stream, gzip.GzipFile):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably the same occurs with bz2, zip and xz files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpy uses np.compat.isfileobj to determine if fromfile can be used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on second thought that function is too restrictive it rejects io based file objects which are default in python3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore the last comment, I opened files in write modes, it seems to work if they are binary read mode.

@andreas-h
Copy link
Contributor Author

added checking for bzip2 files. couldn't find xz support in mmread at all.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling e634d59 on andreas-h:gh2152 into 7cefb25 on scipy:master.

@pv
Copy link
Member

pv commented Feb 19, 2014

Test?

@andreas-h
Copy link
Contributor Author

can we assume that gzip and bz2 modules are available on all platforms? if not, how can I mark the tests accordingly?

@andreas-h
Copy link
Contributor Author

I just saw that Py3.3 has a lzma module. Should we add support for .xz files to mmread, which would then only be available on Python >= 3.3?

@pv
Copy link
Member

pv commented Feb 19, 2014

AFAIK at least the bz2 module is not necessarily present in all Python builds.
Maybe you can try-expect guard the imports?

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 14cb83d on andreas-h:gh2152 into 7cefb25 on scipy:master.

@pv pv added PR labels Feb 19, 2014
@andreas-h
Copy link
Contributor Author

The BZ2File and GzipFile classes don't support with statements in Python2.6. Fixed that now.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling ac31bd8 on andreas-h:gh2152 into c08dd62 on scipy:master.

def test_bzip2_py3(self):
# test if fix for #2152 works
try:
import bz2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a comment on when the module is/isn't available

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific? I'm not sure how such things are handled in
the tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just above the import I would just put # bz2 module isn't always built when building Python. Otherwise one always wonders why the import is guarded. The stdlib docs at http://docs.python.org/2/library/bz2.html don't even explain this:(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I add the same note to the gzip import? Or is gzip always present
and I can remove the try/except?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, gzip can also be missing. Adding same note makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@rgommers
Copy link
Member

removing needs-work label, looks like previous comments were addressed.

@rgommers rgommers added this to the 0.14.0 milestone Feb 23, 2014
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 541dcc4 on andreas-h:gh2152 into 0da153e on scipy:master.

rgommers added a commit that referenced this pull request Feb 24, 2014
BUG: fix scipy.io.mmread() of gzipped files under Python3
@rgommers rgommers merged commit 46d7a3f into scipy:master Feb 24, 2014
@rgommers
Copy link
Member

Merging, looks fine now. Thanks @andreas-h

@pv
Copy link
Member

pv commented Feb 24, 2014

One remaining buglet fixed in 86d3722 (pushed to master).

I don't really like checking for "bad classes" manually, but on the other hand, I'm not sure if it's even possible to do this checking in a generic way.

@rgommers
Copy link
Member

Thanks

@andreas-h andreas-h deleted the gh2152 branch June 4, 2014 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix mmio/fromfile on gzip on Python 3 (Trac #1627)
5 participants