summaryrefslogtreecommitdiff
path: root/numpy/core/memmap.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2009-04-11 22:00:46 +0000
committerCharles Harris <charlesr.harris@gmail.com>2009-04-11 22:00:46 +0000
commit5e0e9559b9ec679b6902129bef46c84707abf865 (patch)
tree5dc100c581a3cc717d8580f36b167e5be2f5cf9f /numpy/core/memmap.py
parent5b466f329c536c2535ba867ff536062fcbaa5b60 (diff)
downloadnumpy-5e0e9559b9ec679b6902129bef46c84707abf865.tar.gz
Fix ticket #1053. Basically the patch from Sturla Molden.
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r--numpy/core/memmap.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 5bc314efc..72ce25b84 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -2,6 +2,7 @@ __all__ = ['memmap']
import warnings
from numeric import uint8, ndarray, dtype
+import sys
dtypedescr = dtype
valid_filemodes = ["r", "c", "r+", "w+"]
@@ -223,10 +224,17 @@ class memmap(ndarray):
else:
acc = mmap.ACCESS_WRITE
- mm = mmap.mmap(fid.fileno(), bytes, access=acc)
- self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
- offset=offset, order=order)
+ if sys.version_info[:2] >= (2,6):
+ # The offset keyword in mmap.mmap needs Python >= 2.6
+ bytes = bytes - offset
+ mm = mmap.mmap(fid.fileno(), bytes, access=acc, offset=offset)
+ self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
+ offset=0, order=order)
+ else:
+ mm = mmap.mmap(fid.fileno(), bytes, access=acc)
+ self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
+ offset=offset, order=order)
self._mmap = mm
return self