diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-02-08 21:37:23 -0800 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-09-23 09:36:50 -0700 |
commit | 6ad76178b59372739d1c256ffdb735c89c654637 (patch) | |
tree | 7542c9fbbf06302a68ccd76dcfa88a6221b617ac | |
parent | 1c0ebd808ede34d384a44ed19093afc109ba0cd8 (diff) | |
download | numpy-6ad76178b59372739d1c256ffdb735c89c654637.tar.gz |
BUG: Don't leave the file open if a bad shape argument is passed to memmap
-rw-r--r-- | numpy/core/memmap.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py index 536fa6094..190de2a77 100644 --- a/numpy/core/memmap.py +++ b/numpy/core/memmap.py @@ -211,6 +211,9 @@ class memmap(ndarray): raise ValueError("mode must be one of %s" % (valid_filemodes + list(mode_equivalents.keys()))) + if mode == 'w+' and shape is None: + raise ValueError("shape must be given") + if hasattr(filename, 'read'): fid = filename own_file = False @@ -221,9 +224,6 @@ class memmap(ndarray): 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") - fid.seek(0, 2) flen = fid.tell() descr = dtypedescr(dtype) |