-
-
Notifications
You must be signed in to change notification settings - Fork 26.2k
[WIP] Fix read only mmap tests #5507
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
Changes from all commits
80ec85a
75b093e
f72718c
deeb156
d291d89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,8 @@ def fit(self, X, y=None): | |
------- | ||
self | ||
""" | ||
X = check_array(X, copy=self.copy, dtype=np.float64) | ||
copy = not X.flags.writable or self.copy | ||
X = check_array(X, copy=copy, dtype=np.float64) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem 'on_readonly' in check_array ?
I wouldn't understand what that means from the name.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
n_samples, n_features = X.shape | ||
n_components = self.n_components | ||
|
@@ -247,14 +248,15 @@ def transform(self, X): | |
""" | ||
check_is_fitted(self, 'components_') | ||
|
||
X = check_array(X) | ||
copy = copy if copy is not None else self.copy | ||
X = check_array(X, copy=copy) | ||
Ih = np.eye(len(self.components_)) | ||
|
||
X_transformed = X - self.mean_ | ||
X -= self.mean_ | ||
|
||
Wpsi = self.components_ / self.noise_variance_ | ||
cov_z = linalg.inv(Ih + np.dot(Wpsi, self.components_.T)) | ||
tmp = fast_dot(X_transformed, Wpsi.T) | ||
tmp = fast_dot(X, Wpsi.T) | ||
X_transformed = fast_dot(tmp, cov_z) | ||
|
||
return X_transformed | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,7 +305,7 @@ def partial_fit(self, X, y=None): | |
raise TypeError("MinMaxScaler does no support sparse input. " | ||
"You may consider to use MaxAbsScaler instead.") | ||
|
||
X = check_array(X, copy=self.copy, ensure_2d=False, warn_on_dtype=True, | ||
X = check_array(X, copy=False, ensure_2d=False, warn_on_dtype=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy=False is default, should it be explicit ? |
||
estimator=self, dtype=FLOAT_DTYPES) | ||
|
||
if X.ndim == 1: | ||
|
@@ -332,7 +332,7 @@ def partial_fit(self, X, y=None): | |
self.data_range_ = data_range | ||
return self | ||
|
||
def transform(self, X): | ||
def transform(self, X, copy=None): | ||
"""Scaling features of X according to feature_range. | ||
|
||
Parameters | ||
|
@@ -341,16 +341,16 @@ def transform(self, X): | |
Input data that will be transformed. | ||
""" | ||
check_is_fitted(self, 'scale_') | ||
|
||
X = check_array(X, copy=self.copy, ensure_2d=False, dtype=FLOAT_DTYPES) | ||
copy = copy if copy is not None else self.copy | ||
X = check_array(X, copy=copy, ensure_2d=False, dtype=FLOAT_DTYPES) | ||
if X.ndim == 1: | ||
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning) | ||
|
||
X *= self.scale_ | ||
X += self.min_ | ||
return X | ||
|
||
def inverse_transform(self, X): | ||
def inverse_transform(self, X, copy=None): | ||
"""Undo the scaling of X according to feature_range. | ||
|
||
Parameters | ||
|
@@ -359,8 +359,8 @@ def inverse_transform(self, X): | |
Input data that will be transformed. It cannot be sparse. | ||
""" | ||
check_is_fitted(self, 'scale_') | ||
|
||
X = check_array(X, copy=self.copy, ensure_2d=False, dtype=FLOAT_DTYPES) | ||
copy = copy if copy is not None else self.copy | ||
X = check_array(X, copy=copy, ensure_2d=False, dtype=FLOAT_DTYPES) | ||
if X.ndim == 1: | ||
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning) | ||
|
||
|
@@ -557,7 +557,7 @@ def partial_fit(self, X, y=None): | |
|
||
y: Passthrough for ``Pipeline`` compatibility. | ||
""" | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=False, | ||
ensure_2d=False, warn_on_dtype=True, | ||
estimator=self, dtype=FLOAT_DTYPES) | ||
|
||
|
@@ -748,7 +748,7 @@ def partial_fit(self, X, y=None): | |
|
||
y: Passthrough for ``Pipeline`` compatibility. | ||
""" | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=False, | ||
ensure_2d=False, estimator=self, dtype=FLOAT_DTYPES) | ||
|
||
if X.ndim == 1: | ||
|
@@ -772,7 +772,7 @@ def partial_fit(self, X, y=None): | |
self.scale_ = _handle_zeros_in_scale(max_abs) | ||
return self | ||
|
||
def transform(self, X, y=None): | ||
def transform(self, X, y=None, copy=None): | ||
"""Scale the data | ||
|
||
Parameters | ||
|
@@ -781,7 +781,8 @@ def transform(self, X, y=None): | |
The data that should be scaled. | ||
""" | ||
check_is_fitted(self, 'scale_') | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, | ||
copy = copy if copy is not None else self.copy | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=copy, | ||
ensure_2d=False, estimator=self, dtype=FLOAT_DTYPES) | ||
|
||
if X.ndim == 1: | ||
|
@@ -796,7 +797,7 @@ def transform(self, X, y=None): | |
X /= self.scale_ | ||
return X | ||
|
||
def inverse_transform(self, X): | ||
def inverse_transform(self, X, copy=None): | ||
"""Scale back the data to the original representation | ||
|
||
Parameters | ||
|
@@ -805,6 +806,7 @@ def inverse_transform(self, X): | |
The data that should be transformed back. | ||
""" | ||
check_is_fitted(self, 'scale_') | ||
copy = copy if copy is not None else self.copy | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, | ||
ensure_2d=False, estimator=self, dtype=FLOAT_DTYPES) | ||
if X.ndim == 1: | ||
|
@@ -934,9 +936,9 @@ def __init__(self, with_centering=True, with_scaling=True, copy=True): | |
self.with_scaling = with_scaling | ||
self.copy = copy | ||
|
||
def _check_array(self, X, copy): | ||
def _check_array(self, X, copy=False): | ||
"""Makes sure centering is not enabled for sparse matrices.""" | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy, | ||
X = check_array(X, accept_sparse=('csr', 'csc'), copy=copy, | ||
ensure_2d=False, estimator=self, dtype=FLOAT_DTYPES) | ||
|
||
if X.ndim == 1: | ||
|
@@ -960,7 +962,7 @@ def fit(self, X, y=None): | |
""" | ||
if sparse.issparse(X): | ||
raise TypeError("RobustScaler cannot be fitted on sparse inputs") | ||
X = self._check_array(X, self.copy) | ||
X = self._check_array(X, copy=False) | ||
if X.ndim == 1: | ||
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning) | ||
if self.with_centering: | ||
|
@@ -972,7 +974,7 @@ def fit(self, X, y=None): | |
self.scale_ = _handle_zeros_in_scale(self.scale_, copy=False) | ||
return self | ||
|
||
def transform(self, X, y=None): | ||
def transform(self, X, y=None, copy=None): | ||
"""Center and scale the data | ||
|
||
Parameters | ||
|
@@ -984,7 +986,8 @@ def transform(self, X, y=None): | |
check_is_fitted(self, 'center_') | ||
if self.with_scaling: | ||
check_is_fitted(self, 'scale_') | ||
X = self._check_array(X, self.copy) | ||
copy = copy if copy is not None else self.copy | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
X = self._check_array(X, copy) | ||
if X.ndim == 1: | ||
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning) | ||
|
||
|
@@ -1001,7 +1004,7 @@ def transform(self, X, y=None): | |
X /= self.scale_ | ||
return X | ||
|
||
def inverse_transform(self, X): | ||
def inverse_transform(self, X, copy=None): | ||
"""Scale back the data to the original representation | ||
|
||
Parameters | ||
|
@@ -1013,7 +1016,8 @@ def inverse_transform(self, X): | |
check_is_fitted(self, 'center_') | ||
if self.with_scaling: | ||
check_is_fitted(self, 'scale_') | ||
X = self._check_array(X, self.copy) | ||
copy = copy if copy is not None else self.copy | ||
X = self._check_array(X, copy) | ||
if X.ndim == 1: | ||
warnings.warn(DEPRECATION_MSG_1D, DeprecationWarning) | ||
|
||
|
@@ -1449,7 +1453,7 @@ def fit(self, X, y=None): | |
This method is just there to implement the usual API and hence | ||
work in pipelines. | ||
""" | ||
check_array(X, accept_sparse='csr') | ||
check_array(X, accept_sparse='csr', copy=False) | ||
return self | ||
|
||
def transform(self, X, y=None, copy=None): | ||
|
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'