diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2010-04-12 20:35:59 +0000 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2010-04-12 20:35:59 +0000 |
| commit | 4d821188c3baeefccaff0d8074ea0ee838327f66 (patch) | |
| tree | dd69dac3189200e532fbef8809cf25c3b4ad7fc3 /numpy | |
| parent | 375542b2dd182dce0af0c32579645e7b30659bb0 (diff) | |
| download | numpy-4d821188c3baeefccaff0d8074ea0ee838327f66.tar.gz | |
ENH: Add filename attribute to memmap.
Diffstat (limited to 'numpy')
| -rw-r--r-- | numpy/core/memmap.py | 2 | ||||
| -rw-r--r-- | numpy/core/tests/test_memmap.py | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index ed888a040..b4a25cf9c 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -227,11 +227,13 @@ class memmap(ndarray): 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 diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py index d80724dea..fb1d7fa46 100644 --- a/numpy/core/tests/test_memmap.py +++ b/numpy/core/tests/test_memmap.py @@ -38,6 +38,18 @@ class TestMemmap(TestCase): 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) |
