diff options
-rw-r--r-- | numpy/core/memmap.py | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_memmap.py | 17 |
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() |