summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorThouis (Ray) Jones <thouis@gmail.com>2012-07-06 23:42:57 +0200
committerThouis (Ray) Jones <thouis@gmail.com>2012-07-06 23:42:57 +0200
commitaeff403ff868e822ebebdb8e6fb02055cd6ccf5b (patch)
tree8022d135b2154b2a90366704addb99442fba1993 /numpy/lib
parent5b5a0f4999dfac66c9c27160737352c727a3517b (diff)
parent3b9a0fea12ae89fe6ce745d9af0beb3df17260b8 (diff)
downloadnumpy-aeff403ff868e822ebebdb8e6fb02055cd6ccf5b.tar.gz
Merge remote-tracking branch 'upstream/master' into malloc_hooks
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py12
-rw-r--r--numpy/lib/npyio.py3
-rw-r--r--numpy/lib/tests/test_io.py45
-rw-r--r--numpy/lib/twodim_base.py6
4 files changed, 50 insertions, 16 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 6d9e65697..f3df3b96b 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -778,7 +778,7 @@ def select(condlist, choicelist, default=0):
S = S*ones(asarray(pfac).shape, S.dtype)
return choose(S, tuple(choicelist))
-def copy(a, order='C', maskna=None):
+def copy(a, order='C'):
"""
Return an array copy of the given object.
@@ -791,10 +791,6 @@ def copy(a, order='C', maskna=None):
'F' means F-order, 'A' means 'F' if `a` is Fortran contiguous,
'C' otherwise. 'K' means match the layout of `a` as closely
as possible.
- maskna : bool, optional
- If specifies, forces the copy to have or to not have an
- NA mask. This is a way to remove an NA mask from an array
- while making a copy.
Returns
-------
@@ -824,7 +820,7 @@ def copy(a, order='C', maskna=None):
False
"""
- return array(a, order=order, copy=True, maskna=maskna)
+ return array(a, order=order, copy=True)
# Basic operations
@@ -3377,7 +3373,6 @@ def delete(arr, obj, axis=None):
"invalid entry")
newshape[axis]-=1;
new = empty(newshape, arr.dtype, arr.flags.fnc)
- new.flags.maskna = arr.flags.maskna
slobj[axis] = slice(None, obj)
new[slobj] = arr[slobj]
slobj[axis] = slice(obj,None)
@@ -3394,7 +3389,6 @@ def delete(arr, obj, axis=None):
return arr.copy()
newshape[axis] -= numtodel
new = empty(newshape, arr.dtype, arr.flags.fnc)
- new.flags.maskna = arr.flags.maskna
# copy initial chunk
if start == 0:
pass
@@ -3526,7 +3520,6 @@ def insert(arr, obj, values, axis=None):
"in dimension %d" % (obj, N, axis))
newshape[axis] += 1;
new = empty(newshape, arr.dtype, arr.flags.fnc)
- new.flags.maskna = arr.flags.maskna
slobj[axis] = slice(None, obj)
new[slobj] = arr[slobj]
slobj[axis] = obj
@@ -3553,7 +3546,6 @@ def insert(arr, obj, values, axis=None):
index2 = setdiff1d(arange(numnew+N),index1)
newshape[axis] += numnew
new = empty(newshape, arr.dtype, arr.flags.fnc)
- new.flags.maskna = arr.flags.maskna
slobj2 = [slice(None)]*ndim
slobj[axis] = index1
slobj2[axis] = index2
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 221529929..cb14e4963 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -359,7 +359,6 @@ def load(file, mmap_mode=None):
own_fid = True
elif isinstance(file, gzip.GzipFile):
fid = seek_gzip_factory(file)
- own_fid = True
else:
fid = file
@@ -371,7 +370,7 @@ def load(file, mmap_mode=None):
fid.seek(-N, 1) # back-up
if magic.startswith(_ZIP_PREFIX): # zip-file (assume .npz)
own_fid = False
- return NpzFile(fid, own_fid=True)
+ return NpzFile(fid, own_fid=own_fid)
elif magic == format.MAGIC_PREFIX: # .npy file
if mmap_mode:
return format.open_memmap(file, mode=mmap_mode)
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 8922070df..c539c040a 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -167,6 +167,51 @@ class TestSavezLoad(RoundtripTest, TestCase):
if errors:
raise AssertionError(errors)
+ def test_not_closing_opened_fid(self):
+ # Test that issue #2178 is fixed:
+ # verify could seek on 'loaded' file
+
+ fd, tmp = mkstemp(suffix='.npz')
+ os.close(fd)
+ try:
+ fp = open(tmp, 'wb')
+ np.savez(fp, data='LOVELY LOAD')
+ fp.close()
+
+ fp = open(tmp, 'rb', 10000)
+ fp.seek(0)
+ assert_(not fp.closed)
+ _ = np.load(fp)['data']
+ assert_(not fp.closed) # must not get closed by .load(opened fp)
+ fp.seek(0)
+ assert_(not fp.closed)
+
+ finally:
+ os.remove(tmp)
+
+ def test_closing_fid(self):
+ # Test that issue #1517 (too many opened files) remains closed
+ # It might be a "week" test since failed to get triggered on
+ # e.g. Debian sid of 2012 Jul 05 but was reported to
+ # trigger the failure on Ubuntu 10.04:
+ # http://projects.scipy.org/numpy/ticket/1517#comment:2
+ fd, tmp = mkstemp(suffix='.npz')
+ os.close(fd)
+
+ try:
+ fp = open(tmp, 'wb')
+ np.savez(fp, data='LOVELY LOAD')
+ fp.close()
+
+ for i in range(1, 1025):
+ try:
+ np.load(tmp)["data"]
+ except Exception, e:
+ raise AssertionError("Failed to load data from a file: %s" % e)
+ finally:
+ os.remove(tmp)
+
+
class TestSaveTxt(TestCase):
def test_array(self):
a = np.array([[1, 2], [3, 4]], float)
diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py
index eab8f867a..c1f75c630 100644
--- a/numpy/lib/twodim_base.py
+++ b/numpy/lib/twodim_base.py
@@ -166,7 +166,7 @@ def rot90(m, k=1):
# k == 3
return fliplr(m.swapaxes(0,1))
-def eye(N, M=None, k=0, dtype=float, maskna=False):
+def eye(N, M=None, k=0, dtype=float):
"""
Return a 2-D array with ones on the diagonal and zeros elsewhere.
@@ -182,8 +182,6 @@ def eye(N, M=None, k=0, dtype=float, maskna=False):
to a lower diagonal.
dtype : data-type, optional
Data-type of the returned array.
- maskna : boolean
- If this is true, the returned array will have an NA mask.
Returns
-------
@@ -209,7 +207,7 @@ def eye(N, M=None, k=0, dtype=float, maskna=False):
"""
if M is None:
M = N
- m = zeros((N, M), dtype=dtype, maskna=maskna)
+ m = zeros((N, M), dtype=dtype)
if k >= M:
return m
if k >= 0: