Skip to content

Commit 0d4ef7e

Browse files
author
Perrine Letellier
committed
make check_array raise in case of readonly memmap and copy=False
1 parent f72718c commit 0d4ef7e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

sklearn/utils/estimator_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _init_temp_memory(mmap_mode='r'):
309309
temp_folder = tempfile.mkdtemp(prefix='sklearn_checks_temp_')
310310
_TEMP_READONLY_MEMMAP_MEMORY = Memory(cachedir=temp_folder,
311311
mmap_mode=mmap_mode, verbose=0)
312-
# Cannot use atexit as it is called everytime a test end,
312+
# Cannot use atexit as it is called everytime a test ends,
313313
# thus forcing us to regenerate cache at every check
314314
# atexit.register(_clear_temp_memory(warn=True))
315315

sklearn/utils/validation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ def check_array(array, accept_sparse=None, dtype="numeric", order=None,
341341
X_converted : object
342342
The converted and validated X.
343343
"""
344+
if isinstance(array, np.memmap) and array.mode == "r" and not copy:
345+
raise ValueError('Can not modify inplace an array which is read-only')
346+
344347
if isinstance(accept_sparse, str):
345348
accept_sparse = [accept_sparse]
346349

0 commit comments

Comments
 (0)