-
-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Fix read only mmap tests #5507
Conversation
47bea48
to
0d4ef7e
Compare
@@ -381,7 +386,10 @@ def check_array(array, accept_sparse=None, dtype="numeric", order=None, | |||
array = _ensure_sparse_format(array, accept_sparse, dtype, copy, | |||
force_all_finite) | |||
else: | |||
array = np.array(array, dtype=dtype, order=order, copy=copy) | |||
# Do not physically copy memory map : if type(array) == np.memmap: | |||
# type(array) == np.array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is numpy.ndarray
, never numpy.array
.
Also see #4807 ? |
sklearn/utils/validation.py
Outdated
@@ -341,9 +341,14 @@ def check_array(array, accept_sparse=None, dtype="numeric", order=None, | |||
X_converted : object | |||
The converted and validated X. | |||
""" | |||
if isinstance(array, np.memmap) and array.mode == "r" and not copy: | |||
raise ValueError('Can not modify inplace an array which is read-only') | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this appears not to be the right place to raise that error.
check_array()
can be called in both fit()
and transform()
as in RobustScaler for example.
The returned array is modified inplace in transform()
but no modification is ever performed in fit()
.
Could we make this check at the beginning of each transform()
method ? WDYT @ogrisel
This may be in the mother class's method fit_transform() and used calling super()
06ba2a8
to
5bfb9f7
Compare
5bfb9f7
to
d291d89
Compare
X = check_array(X, dtype=np.float64, copy=self.copy) | ||
Y = check_array(Y, dtype=np.float64, copy=self.copy, ensure_2d=False) | ||
Xcopy = not X.flags.writable or self.copy | ||
Ycopy = not Y.flags.writable or self.copy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should maybe factored into check_array:
Parameters copy=False|True|'on_readonly'
@pletelli are you still willing to work on this or should I take up ? |
will soon fix #5481 which has been opened to fix tests on #4807
This PR is based on #4807