[Numpy-svn] r8325 - in trunk/numpy/core: . tests

numpy-svn@scip... numpy-svn@scip...
Mon Apr 12 15:35:59 CDT 2010


Author: charris
Date: 2010-04-12 15:35:59 -0500 (Mon, 12 Apr 2010)
New Revision: 8325

Modified:
   trunk/numpy/core/memmap.py
   trunk/numpy/core/tests/test_memmap.py
Log:
ENH: Add filename attribute to memmap.

Modified: trunk/numpy/core/memmap.py
===================================================================
--- trunk/numpy/core/memmap.py	2010-04-05 04:51:33 UTC (rev 8324)
+++ trunk/numpy/core/memmap.py	2010-04-12 20:35:59 UTC (rev 8325)
@@ -227,11 +227,13 @@
         self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
             offset=offset, order=order)
         self._mmap = mm
+        self.filename = filename
         return self
 
     def __array_finalize__(self, obj):
         if hasattr(obj, '_mmap'):
             self._mmap = obj._mmap
+            self.filename = obj.filename
         else:
             self._mmap = None
 

Modified: trunk/numpy/core/tests/test_memmap.py
===================================================================
--- trunk/numpy/core/tests/test_memmap.py	2010-04-05 04:51:33 UTC (rev 8324)
+++ trunk/numpy/core/tests/test_memmap.py	2010-04-12 20:35:59 UTC (rev 8325)
@@ -38,6 +38,18 @@
         del fp
         os.unlink(tmpname)
 
+    def test_filename(self):
+        tmpname = mktemp('','mmap')
+        fp = memmap(tmpname, dtype=self.dtype, mode='w+',
+                       shape=self.shape)
+        fp[:] = self.data[:]
+        self.assertEquals(tmpname, fp.filename)
+        b = fp[:1]
+        self.assertEquals(tmpname, b.filename)
+        del fp
+        os.unlink(tmpname)
+
+
     def test_flush(self):
         fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+',
                     shape=self.shape)



More information about the Numpy-svn mailing list