summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorSveinung Gundersen <sveinugu@gmail.com>2012-07-03 11:31:40 +0200
committerThouis (Ray) Jones <thouis@gmail.com>2012-07-03 11:31:40 +0200
commit731cf3aaaa95c714361f4062e6929f5a324586cc (patch)
tree191aa9162f6275be62330ba10c991f1d945228ea /numpy/core
parente15d0bdd3cc0bc0928e1f4d0b419a2fb3de02af9 (diff)
downloadnumpy-731cf3aaaa95c714361f4062e6929f5a324586cc.tar.gz
BUG: fix incorrect references to parents in memmap children.
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/memmap.py9
-rw-r--r--numpy/core/tests/test_memmap.py19
2 files changed, 25 insertions, 3 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index fe52b3a09..f068c7b6c 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -4,7 +4,7 @@ import warnings
from numeric import uint8, ndarray, dtype
import sys
-from numpy.compat import asbytes
+import numpy as np
dtypedescr = dtype
valid_filemodes = ["r", "c", "r+", "w+"]
@@ -235,7 +235,7 @@ class memmap(ndarray):
if mode == 'w+' or (mode == 'r+' and flen < bytes):
fid.seek(bytes - 1, 0)
- fid.write(asbytes('\0'))
+ fid.write(np.compat.asbytes('\0'))
fid.flush()
if mode == 'c':
@@ -271,13 +271,16 @@ class memmap(ndarray):
return self
def __array_finalize__(self, obj):
- if hasattr(obj, '_mmap'):
+ if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
self._mmap = obj._mmap
self.filename = obj.filename
self.offset = obj.offset
self.mode = obj.mode
else:
self._mmap = None
+ self.filename = None
+ self.offset = None
+ self.mode = None
def flush(self):
"""
diff --git a/numpy/core/tests/test_memmap.py b/numpy/core/tests/test_memmap.py
index add714f89..7f134ee91 100644
--- a/numpy/core/tests/test_memmap.py
+++ b/numpy/core/tests/test_memmap.py
@@ -85,5 +85,24 @@ class TestMemmap(TestCase):
fp_base[0] = 6
assert_equal(fp_base[0], 6)
+ def test_arithmetic_drops_references(self):
+ fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+',
+ shape=self.shape)
+ tmp = (fp + 10)
+ if isinstance(tmp, memmap):
+ assert tmp._mmap is not fp._mmap
+
+ def test_indexing_drops_references(self):
+ fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+',
+ shape=self.shape)
+ tmp = fp[[(1, 2), (2, 3)]]
+ if isinstance(tmp, memmap):
+ assert tmp._mmap is not fp._mmap
+
+ def test_slicing_keeps_references(self):
+ fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+',
+ shape=self.shape)
+ assert fp[:2, :2]._mmap is fp._mmap
+
if __name__ == "__main__":
run_module_suite()