Skip to content
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

Closed

Conversation

pletelli
Copy link

will soon fix #5481 which has been opened to fix tests on #4807

This PR is based on #4807

@@ -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
Copy link
Member

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.

@amueller
Copy link
Member

Also see #4807 ?

@@ -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')

Copy link
Author

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()

@pletelli pletelli force-pushed the fix_read_only_mmap_tests branch 6 times, most recently from 06ba2a8 to 5bfb9f7 Compare October 21, 2015 15:57
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
Copy link
Contributor

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'

@arthurmensch
Copy link
Contributor

@pletelli are you still willing to work on this or should I take up ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Estimators should not try to modify X and y inplace in order to handle readonly memory maps
5 participants