def create_memmap_backed_data(data, mmap_mode='r', return_folder=False): """ Parameters ---------- data mmap_mode return_folder """ temp_folder = tempfile.mkdtemp(prefix='sklearn_testing_') atexit.register(functools.partial(_delete_folder, temp_folder, warn=True)) filename = op.join(temp_folder, 'data.pkl') joblib.dump(data, filename) memmap_backed_data = joblib.load(filename, mmap_mode=mmap_mode) result = (memmap_backed_data if not return_folder else (memmap_backed_data, temp_folder)) return result