summaryrefslogtreecommitdiff
path: root/numpy/core/memmap.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2012-03-10 13:28:32 -0700
committerCharles Harris <charlesr.harris@gmail.com>2012-03-12 07:46:18 -0600
commit2655a68b15f582eca294072e87be51caf9ca0d7c (patch)
treede8542e5751b5ea32d5e30c1a39c4592e74da351 /numpy/core/memmap.py
parentb379fd7422257fcac463699288fb541e71240974 (diff)
downloadnumpy-2655a68b15f582eca294072e87be51caf9ca0d7c.tar.gz
PY3: Fix memmap "ResourceWarning: unclosed file".
Diffstat (limited to 'numpy/core/memmap.py')
-rw-r--r--numpy/core/memmap.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index 53f9a3f07..fe52b3a09 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -203,8 +203,10 @@ class memmap(ndarray):
if hasattr(filename,'read'):
fid = filename
+ own_file = False
else:
fid = open(filename, (mode == 'c' and 'r' or mode)+'b')
+ own_file = True
if (mode == 'w+') and shape is None:
raise ValueError("shape must be given")
@@ -263,6 +265,9 @@ class memmap(ndarray):
elif hasattr(filename, "name"):
self.filename = os.path.abspath(filename.name)
+ if own_file:
+ fid.close()
+
return self
def __array_finalize__(self, obj):