[MRG+1] Deprecate Imputer.axis argument#9672
[MRG+1] Deprecate Imputer.axis argument#9672petrushev wants to merge 3 commits intoscikit-learn:masterfrom
Imputer.axis argument#9672Conversation
dee866d to
c900dd5
Compare
glemaitre
left a comment
There was a problem hiding this comment.
This changes should make the CI happy.
Also edit the title with [WIP] when working on the PR and change it to [MRG] when this is ready for revision.
|
|
||
| - A scorer based on :func:`metrics.brier_score_loss` is also available. | ||
| :issue:`9521` by :user:`Hanmin Qin <qinhanmin2014>`. | ||
| - The ``axis`` parameter in |
sklearn/preprocessing/imputation.py
Outdated
| self.copy = copy | ||
|
|
||
| self.axis = axis | ||
| if axis is not None: |
There was a problem hiding this comment.
The warning should be raised in fit method. The validation is postponed for the SearhCV: object: http://scikit-learn.org/stable/developers/contributing.html#instantiation
sklearn/preprocessing/imputation.py
Outdated
|
|
||
| def _sparse_fit(self, X, strategy, missing_values, axis): | ||
| """Fit the transformer on sparse data.""" | ||
| if axis is None: |
There was a problem hiding this comment.
no need if using since self.axis_ will be 0 or 1 already
sklearn/preprocessing/imputation.py
Outdated
|
|
||
| # Imputation is done "by column", so if we want to do it | ||
| # by row we only need to convert the matrix to csr format. | ||
|
|
There was a problem hiding this comment.
remove the blank line. we try to minimize the diff which bring nothing
sklearn/preprocessing/imputation.py
Outdated
|
|
||
| def _dense_fit(self, X, strategy, missing_values, axis): | ||
| """Fit the transformer on dense data.""" | ||
| if axis is None: |
There was a problem hiding this comment.
no need if using since self.axis_ will be 0 or 1 already
sklearn/preprocessing/imputation.py
Outdated
| The input data to complete. | ||
| """ | ||
| if self.axis == 0: | ||
| if self.axis is None or self.axis == 0: |
There was a problem hiding this comment.
no need if using since self.axis_ will be 0 or 1 already
sklearn/preprocessing/imputation.py
Outdated
| missing = np.arange(X.shape[not self.axis])[invalid_mask] | ||
|
|
||
| if self.axis == 0 and invalid_mask.any(): | ||
| if (self.axis is None or self.axis == 0) and invalid_mask.any(): |
There was a problem hiding this comment.
no need if using since self.axis_ will be 0 or 1 already
sklearn/preprocessing/imputation.py
Outdated
| values = np.repeat(valid_statistics, n_missing) | ||
|
|
||
| if self.axis == 0: | ||
| if self.axis is None or self.axis == 0: |
There was a problem hiding this comment.
no need if using since self.axis_ will be 0 or 1 already
sklearn/preprocessing/imputation.py
Outdated
| # transform(X), the imputation data will be computed in transform() | ||
| # when the imputation is done per sample (i.e., when axis=1). | ||
| if self.axis == 0: | ||
| if self.axis == 0 or self.axis is None: |
There was a problem hiding this comment.
no need if using since self.axis_ will be 0 or 1 already
sklearn/preprocessing/imputation.py
Outdated
|
|
||
| .. deprecated:: 0.20 | ||
| ``axis`` will be removed from ``Imputer``, and it will only impute | ||
| along columns (axis=0) in 0.22. |
There was a problem hiding this comment.
(axis=0) -> (i.e., ``axis=0``)
…and equals to 0 when axis is None.
|
LGTM @jnothman could yo have a look. |
Imputer.axis argumentImputer.axis argument
sklearn/preprocessing/imputation.py
Outdated
|
|
||
| if self.axis not in [0, 1]: | ||
| if self.axis is None: | ||
| self.axis_ = 0 |
There was a problem hiding this comment.
This attribute implicitly becomes part of the public API. Either use a private attribute (beginning _) or use a local variable
There was a problem hiding this comment.
Ups my bad ... I should have advise to make it private
|
LGTM |
Imputer.axis argumentImputer.axis argument
lesteve
left a comment
There was a problem hiding this comment.
Small comment in the deprecation message.
It would be great to add a test to make sure we get the DeprecationWarning when axis is set explicitly (test either to axis=0 or axis=1 or both)
| if self.axis is None: | ||
| self._axis = 0 | ||
| else: | ||
| warnings.warn("'axis' will be removed from Imputer, and it will " |
There was a problem hiding this comment.
The convention is to add the version the deprecation happened as well as the on it will be removed.
From http://scikit-learn.org/stable/developers/contributing.html#deprecation:
As in these examples, the warning message should always give both the version in which the deprecation happened and the version in which the old behavior will be removed.
qinhanmin2014
left a comment
There was a problem hiding this comment.
ping @petrushev This looks good overall. Could you please (please also refer to the comments above)
(1) Solve the conflict
(2) Improve the deprecation message
(3) Add a test to ensure the warning is raised
(4) Move what's new entry to API changes summary
Thanks :)
|
@petrushev Would you be able to address minor comments above, this is almost good to merge )
@qinhanmin2014 Do we really want to add a test at each deprecation warning? |
@rth I don't know too much about the history but we have tests for most API changes in 0.20. I think at least it's not harmful to test the deprecation warning. WDYT? Also see lesteve's comment above (#9672 (review)): |
Good to know, thanks, I missed that. |
|
@petrushev I've continued the work in #10558 since we've not heard from you for several months, hope you won't mind. |
Reference Issue
Fixes: #9463
What does this implement/fix? Explain your changes.
Deprecated the argument
axison theImputerclass.