Package: python-numpy
Version: 1:1.6.2-1
Severity: important
Tags: upstream patch

This bug causes FTBFS of pyNN due to being triggered by the tests (built fine
before).

I have reported it upstream
http://projects.scipy.org/numpy/ticket/2178
and  sent a tentative unittest + patch (diffs attached) 
https://github.com/numpy/numpy/pull/328

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (900, 'testing'), (600, 'unstable'), (300, 'experimental'), (100, 
'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.1.0-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages python-numpy depends on:
ii  libblas3gf [libblas.so.3gf]      1.2.20110419-2
ii  libc6                            2.13-33
ii  libgcc1                          1:4.7.1-2
ii  libgfortran3                     4.7.1-2
ii  liblapack3gf [liblapack.so.3gf]  3.3.1-1
ii  libquadmath0                     4.7.1-2
ii  python                           2.7.2-10
ii  python-support                   1.0.14

python-numpy recommends no packages.

Versions of packages python-numpy suggests:
ii  gcc               4:4.7.1-1
ii  gfortran          4:4.6.1-2
ii  python-dev        2.7.2-10
ii  python-nose       1.1.2-3
ii  python-numpy-dbg  1:1.6.2-1
ii  python-numpy-doc  1:1.5.1-4

-- no debconf information
>From 4df244465c3db3a8e9e624d17ed2982f595e2b8a Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <[email protected]>
Date: Mon, 2 Jul 2012 16:03:53 -0400
Subject: [PATCH 1/2] BUG: do not "own" the FID for GzipFile and file if
 provided to load already opened (ticket #2178)

Also made all assignments of own_file go in pair with assignments to fid to 
make things clearer
---
 numpy/lib/npyio.py |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 2215299..e16485f 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -2,6 +2,9 @@ __all__ = ['savetxt', 'loadtxt', 'genfromtxt', 'ndfromtxt', 
'mafromtxt',
            'recfromtxt', 'recfromcsv', 'load', 'loads', 'save', 'savez',
            'savez_compressed', 'packbits', 'unpackbits', 'fromregex', 
'DataSource']
 
+# Price to pay for overloading standard keywords
+import __builtin__
+
 import numpy as np
 import format
 import sys
@@ -353,14 +356,19 @@ def load(file, mmap_mode=None):
     """
     import gzip
 
-    own_fid = False
     if isinstance(file, basestring):
-        fid = open(file, "rb")
         own_fid = True
+        fid = open(file, "rb")
     elif isinstance(file, gzip.GzipFile):
+        # we were provided an existing handle which we should close
+        # only if it was closed already
+        own_fid = file.closed
         fid = seek_gzip_factory(file)
-        own_fid = True
+    elif isinstance(file, __builtin__.file):
+        own_fid = file.closed
+        fid = file
     else:
+        own_fid = False
         fid = file
 
     try:
@@ -371,7 +379,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)
-- 
1.7.10

>From 0e3a3d96c7a8e522184c7ca0388cd9d401e902cd Mon Sep 17 00:00:00 2001
From: Yaroslav Halchenko <[email protected]>
Date: Mon, 2 Jul 2012 16:38:09 -0400
Subject: [PATCH 2/2] ENH: unittest for preceeding commit fixing #2178

---
 numpy/lib/tests/test_io.py |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 8922070..e9158ba 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -167,6 +167,27 @@ 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, 'w')
+            np.savez(fp, data='LOVELY LOAD')
+            fp.close()
+
+            fp = open(tmp, 'r', 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)
+
 class TestSaveTxt(TestCase):
     def test_array(self):
         a = np.array([[1, 2], [3, 4]], float)
-- 
1.7.10

_______________________________________________
Python-modules-team mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/python-modules-team

Reply via email to