From 05fa6e737f1ed9a0b0b34a9c90a3c386b600e121 Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Sat, 29 Nov 2008 12:08:29 +0000 Subject: Opening a memmap requires a filename. Raise an error otherwise. --- numpy/lib/format.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'numpy/lib/format.py') diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 32a23ae18..28444613c 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -381,7 +381,7 @@ def read_array(fp): def open_memmap(filename, mode='r+', dtype=None, shape=None, - fortran_order=False, version=(1,0)): + fortran_order=False, version=(1,0)): """ Open a .npy file as a memory-mapped array. @@ -390,7 +390,7 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, Parameters ---------- filename : str - The name of the file on disk. This may not be a filelike object. + The name of the file on disk. This may not be a file-like object. mode : str, optional The mode to open the file with. In addition to the standard file modes, 'c' is also accepted to mean "copy on write". See `numpy.memmap` for @@ -425,6 +425,10 @@ def open_memmap(filename, mode='r+', dtype=None, shape=None, numpy.memmap """ + if not isinstance(filename, basestring): + raise ValueError("Filename must be a string. Memmap cannot use" \ + " existing file handles.") + if 'w' in mode: # We are creating the file, not reading it. # Check if we ought to create the file. -- cgit v1.2.1