8000 MRG: preparations for 1.9.3 release by matthew-brett · Pull Request #6332 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MRG: preparations for 1.9.3 release #6332

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

Merged
merged 8 commits into from
Sep 21, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MAINT: remove legacy monkeypatching of GzipFile
I'm not sure exactly when GzipFile.seek started supporting the whence=
argument by default -- sometime around python 2.5 from the looks of
http://bugs.python.org/issue1355023. But in any case it was definitely
there by 2.6, which is now the earliest version we support, so there's
no longer any need to monkeypatch it in. This also fixes an error in
python 3.5b2, which I haven't bothered to track down further because
these are the wages of monkeypatching.
  • Loading branch information
njsmith authored and matthew-brett committed Sep 18, 2015
commit 40a6085773c00d75783871bc545be7ad88b91fb6
51 changes: 2 additions & 49 deletions numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,6 @@
]


def seek_gzip_factory(f):
"""Use this factory to produce the class so that we can do a lazy
import on gzip.

"""
import gzip

class GzipFile(gzip.GzipFile):

def seek(self, offset, whence=0):
# figure out new position (we can only seek forwards)
if whence == 1:
offset = self.offset + offset

if whence not in [0, 1]:
raise IOError("Illegal argument")

if offset < self.offset:
# for negative seek, rewind and do positive seek
self.rewind()
count = offset - self.offset
for i in range(count // 1024):
self.read(1024)
self.read(count % 1024)

def tell(self):
return self.offset

if isinstance(f, str):
f = GzipFile(f)
elif isinstance(f, gzip.GzipFile):
# cast to our GzipFile if its already a gzip.GzipFile

try:
name = f.name
except AttributeError:
# Backward compatibility for <= 2.5
name = f.filename
mode = f.mode

f = GzipFile(fileobj=f.fileobj, filename=name)
f.mode = mode

return f


class BagObj(object):
"""
BagObj(obj)
Expand Down Expand Up @@ -368,8 +322,6 @@ def load(file, mmap_mode=None):
if isinstance(file, basestring):
fid = open(file, "rb")
own_fid = True
elif isinstance(file, gzip.GzipFile):
fid = seek_gzip_factory(file)
else:
fid = file

Expand Down Expand Up @@ -730,7 +682,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
if _is_string_like(fname):
fown = True
if fname.endswith('.gz'):
fh = iter(seek_gzip_factory(fname))
import gzip
fh = iter(gzip.GzipFile(fname))
elif fname.endswith('.bz2'):
import bz2
fh = iter(bz2.BZ2File(fname))
Expand Down
0