title: Numpy load a memory-mapped array (mmap_mode) from google cloud storage
body: <p>I want to load a <strong>.npy</strong> from google storage (gs://project/file.npy) into my google ml-job as training data. Since the file is +10GB big, I want to use the <strong>mmap_mode</strong> option of numpy.load() to not run out of memory. </p>
  
  <p>Background: I use Keras with fit_generator and Keras Sequence to load batches of data from the .npy that is stored on google storage. </p>
  
  <p>To access google storage I'm using BytesIO since not every lib can access google storage.
  This code works fine without mmap_mode = 'r':</p>
  
  <pre><code>from tensorflow.python.lib.io import file_io
  from io import BytesIO
  
  filename = 'gs://project/file'
  
  x_file = BytesIO(file_io.read_file_to_string(filename + '.npy', binary_mode = True))
  x = np.load(x_file)
  </code></pre>
  
  <p>If I activate mmap_mode, I get this error:</p>
  
  <blockquote>
    <p>TypeError: expected str, bytes or os.PathLike object, not BytesIO</p>
  </blockquote>
  
  <p>I don't understand why it now doesn't accept the BytesIO anymore. </p>
  
  <p>Code including mmap_mode:</p>
  
  <pre><code>x_file = BytesIO(file_io.read_file_to_string(filename + '.npy', binary_mode = True))
  x = np.load(x_file, mmap_mode = 'r')
  </code></pre>
  
  <p>Trace:</p>
  
  <blockquote>
    <p>File "[...]/numpy/lib/npyio.py", line 444, in load return
    format.open_memmap(file, mode=mmap_mode) File
    "[...]/numpy/lib/format.py", line 829, in open_memmap fp =
    open(os_fspath(filename), 'rb') File "[...]/numpy/compat/py3k.py",
    line 237, in os_fspath "not " + path_type.<strong>name</strong>) TypeError:
    expected str, bytes or os.PathLike object, not BytesIO</p>
  </blockquote>