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

numpy-svn@scip... numpy-svn@scip...
Fri Feb 22 02:58:44 CST 2008


Author: stefan
Date: 2008-02-22 02:58:25 -0600 (Fri, 22 Feb 2008)
New Revision: 4817

Modified:
   trunk/numpy/core/memmap.py
   trunk/numpy/core/tests/test_memmap.py
Log:
Deprecate 'sync' in favour of 'flush'.


Modified: trunk/numpy/core/memmap.py
===================================================================
--- trunk/numpy/core/memmap.py	2008-02-21 23:37:43 UTC (rev 4816)
+++ trunk/numpy/core/memmap.py	2008-02-22 08:58:25 UTC (rev 4817)
@@ -1,6 +1,7 @@
 __all__ = ['memmap']
 
 import mmap
+import warnings
 from numeric import uint8, ndarray, dtype
 
 dtypedescr = dtype
@@ -206,11 +207,16 @@
         else:
             self._mmap = None
 
-    def sync(self):
+    def flush(self):
         """Flush any changes in the array to the file on disk."""
         if self._mmap is not None:
             self._mmap.flush()
 
+    def sync(self):
+        """Flush any changes in the array to the file on disk."""
+        warnings.warn("Use ``flush``.", DeprecationWarning)
+        self.flush()
+
     def close(self):
         """Close the memmap file."""
         if (self.base is self._mmap):
@@ -220,7 +226,7 @@
                   "by another object."
 
     def __del__(self):
-        self.sync()
+        self.flush()
         try:
             self.close()
         except ValueError:

Modified: trunk/numpy/core/tests/test_memmap.py
===================================================================
--- trunk/numpy/core/tests/test_memmap.py	2008-02-21 23:37:43 UTC (rev 4816)
+++ trunk/numpy/core/tests/test_memmap.py	2008-02-22 08:58:25 UTC (rev 4817)
@@ -1,10 +1,11 @@
-
 from tempfile import NamedTemporaryFile
 
 from numpy.core import memmap
 from numpy import arange, allclose
 from numpy.testing import *
 
+import warnings
+
 class TestMemmap(NumpyTestCase):
     def setUp(self):
         self.tmpfp = NamedTemporaryFile(prefix='mmap')
@@ -14,14 +15,24 @@
         self.data.resize(self.shape)
 
     def test_RoundTrip(self):
-        fp = memmap(self.tmpfp.name, dtype=self.dtype, mode='w+', 
+        fp = memmap(self.tmpfp.name, dtype=self.dtype, mode='w+',
                     shape=self.shape)
         fp[:] = self.data[:]
         del fp
-        newfp = memmap(self.tmpfp.name, dtype=self.dtype, mode='r', 
+        newfp = memmap(self.tmpfp.name, dtype=self.dtype, mode='r',
                        shape=self.shape)
         assert allclose(self.data, newfp)
         assert_array_equal(self.data, newfp)
 
+    def test_flush(self):
+        fp = memmap(self.tmpfp.name, dtype=self.dtype, mode='w+',
+                    shape=self.shape)
+        fp[:] = self.data[:]
+        fp.flush()
+
+        warnings.simplefilter('ignore', DeprecationWarning)
+        fp.sync()
+        warnings.simplefilter('default', DeprecationWarning)
+
 if __name__ == '__main__':
     NumpyTest().run()



More information about the Numpy-svn mailing list