summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan van der Walt <stefan@sun.ac.za>2008-02-22 08:58:25 +0000
committerStefan van der Walt <stefan@sun.ac.za>2008-02-22 08:58:25 +0000
commit3a9c9221c44f226cb4b29922454e4608d82f9c3d (patch)
tree05a4e6c5fc9b83f9f47144cb5beb1d49dc639a81
parent16eddde4d400e82f00f59379228813885828b116 (diff)
downloadnumpy-3a9c9221c44f226cb4b29922454e4608d82f9c3d.tar.gz
Deprecate 'sync' in favour of 'flush'.
-rw-r--r--numpy/core/memmap.py10
-rw-r--r--numpy/core/tests/test_memmap.py17
2 files changed, 22 insertions, 5 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 4206ae7d9..a4baf5573 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -1,6 +1,7 @@
__all__ = ['memmap']
import mmap
+import warnings
from numeric import uint8, ndarray, dtype
dtypedescr = dtype
@@ -206,11 +207,16 @@ class memmap(ndarray):
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 @@ class memmap(ndarray):
"by another object."
def __del__(self):
- self.sync()
+ self.flush()
try:
self.close()
except ValueError:
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index 2886569e7..6ced034cb 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -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 @@ class TestMemmap(NumpyTestCase):
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()