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

MNT clean futurewarning for 1.0 | _deprecate_positional_args #20002

Merged
merged 15 commits into from
May 14, 2021

Conversation

TomDLT
Copy link
Member

@TomDLT TomDLT commented Apr 28, 2021

Remove @_deprecate_positional_args for 1.0 (part of #19335).
These decorators have been added in 0.23 (see #15005).

Now that positional arguments are not allowed, we can safely reorder parameters when appropriate (maybe better in a separate issue though).

Commands used
git ls-files | xargs sed -i -e ':a;N;$!ba;s/        @_deprecate_positional_args\n//g'
git ls-files | xargs sed -i -e ':a;N;$!ba;s/    @_deprecate_positional_args\n//g'
git ls-files | xargs sed -i -e ':a;N;$!ba;s/@_deprecate_positional_args\n//g'
git ls-files | xargs sed -i -e ':a;N;$!ba;s/from ...utils.validation import _deprecate_positional_args\n//g'
git ls-files | xargs sed -i -e ':a;N;$!ba;s/from ..utils.validation import _deprecate_positional_args\n//g' 
git ls-files | xargs sed -i -e ':a;N;$!ba;s/from .utils.validation import _deprecate_positional_args\n//g' 
git ls-files | xargs sed -i -e ':a;N;$!ba;s/from .validation import _deprecate_positional_args\n//g' 
git ls-files | xargs sed -i -e ':a;N;$!ba;s/, _deprecate_positional_args//g'  
git ls-files | xargs sed -i -e ':a;N;$!ba;s/import _deprecate_positional_args,/import/g' 
# Then manual checks with 
git grep "_deprecate_positional_args"

@TomDLT TomDLT added this to the 1.0 milestone Apr 28, 2021
@TomDLT
Copy link
Member Author

TomDLT commented Apr 28, 2021

I simply silenced mypy errors by adding # type: ignore here and there.

mypy errors
sklearn/decomposition/tests/test_sparse_pca.py:192: error: List item 0 has incompatible type "Type[SparsePCA]"; expected "Type[SparsePCA]"
sklearn/feature_selection/_univariate_selection.py:853: error: Dict entry 0 has incompatible type "str": "Type[SelectPercentile]"; expected "str": "Type[_BaseFilter]"
sklearn/feature_selection/_univariate_selection.py:854: error: Dict entry 1 has incompatible type "str": "Type[SelectKBest]"; expected "str": "Type[_BaseFilter]"
sklearn/svm/tests/test_svm.py:530: error: List item 1 has incompatible type "Tuple[Type[NuSVC], str]"; expected "Tuple[Type[BaseSVC], str]"
sklearn/svm/tests/test_svm.py:550: error: List item 1 has incompatible type "Tuple[Type[NuSVC], Dict[str, List[float]]]"; expected "Tuple[Type[BaseSVC], Dict[str, List[float]]]"
sklearn/svm/tests/test_svm.py:1133: error: List item 0 has incompatible type "Type[SVC]"; expected "Type[BaseSVC]"
sklearn/svm/tests/test_svm.py:1144: error: List item 0 has incompatible type "Type[SVC]"; expected "Type[BaseSVC]"
sklearn/model_selection/tests/test_split.py:347: error: List item 0 has incompatible type "Type[StratifiedKFold]"; expected "Type[_BaseKFold]"
sklearn/model_selection/tests/test_split.py:372: error: List item 0 has incompatible type "Type[StratifiedKFold]"; expected "Type[_BaseKFold]"
sklearn/model_selection/tests/test_split.py:407: error: List item 0 has incompatible type "Type[StratifiedKFold]"; expected "Type[_BaseKFold]"
sklearn/model_selection/tests/test_split.py:450: error: List item 0 has incompatible type "Type[KFold]"; expected "Type[_BaseKFold]"
sklearn/model_selection/tests/test_split.py:450: error: List item 1 has incompatible type "Type[StratifiedKFold]"; expected "Type[_BaseKFold]"
sklearn/tree/tests/test_tree.py:68: error: Argument 1 to "update" of "dict" has incompatible type "Dict[str, Type[DecisionTreeRegressor]]"; expected "Mapping[str, Type[DecisionTreeClassifier]]"
sklearn/decomposition/tests/test_dict_learning.py:606: error: List item 0 has incompatible type "Type[DictionaryLearning]"; expected "Type[_BaseSparseCoding]"
sklearn/ensemble/tests/test_gradient_boosting.py:1225: error: List item 2 has incompatible type <tuple: 3 items>; expected "Tuple[ABCMeta, function, Type[MultiOutputMixin]]"
Found 15 errors in 7 files (checked 499 source files)

@amueller
Copy link
Member

You're not removing the actual helper, right? Wouldn't it be good to do that, so we can make sure we got them all?

@TomDLT
Copy link
Member Author

TomDLT commented Apr 30, 2021

You're not removing the actual helper, right?

The helper is still there, it is required until 1.1 for this function:

@_deprecate_positional_args(version="1.1")
def plot(self, *, ax=None, n_cols=3, line_kw=None, contour_kw=None):
"""Plot partial dependence plots.

so we can make sure we got them all?

Result of git grep @_deprecate_positional_args on this branch:

sklearn/inspection/_plot/partial_dependence.py:    @_deprecate_positional_args(version="1.1")
sklearn/utils/tests/test_validation.py:    @_deprecate_positional_args
sklearn/utils/tests/test_validation.py:    @_deprecate_positional_args
sklearn/utils/tests/test_validation.py:    @_deprecate_positional_args
sklearn/utils/tests/test_validation.py:    @_deprecate_positional_args(version="1.1")
sklearn/utils/tests/test_validation.py:        @_deprecate_positional_args
sklearn/utils/tests/test_validation.py:        @_deprecate_positional_args

@ogrisel
Copy link
Member

ogrisel commented May 11, 2021

I pushed a commit to bump the default version value to "1.1 (renaming of 0.26)" in the private _deprecate_positional_args helper to avoid confusion. I also checked and the only need is the for the PDP function cited in the parent issue.

@thomasjpfan the mypy linter now complains with:

sklearn/neighbors/tests/test_neighbors.py:95: error: List item 0 has incompatible type "Type[KNeighborsClassifier]"; expected "Type[NeighborsBase]"
sklearn/neighbors/tests/test_neighbors.py:96: error: List item 1 has incompatible type "Type[KNeighborsRegressor]"; expected "Type[NeighborsBase]"
sklearn/neighbors/tests/test_neighbors.py:1749: error: List item 0 has incompatible type "Type[KNeighborsClassifier]"; expected "Type[NeighborsBase]"
sklearn/neighbors/tests/test_neighbors.py:1750: error: List item 1 has incompatible type "Type[KNeighborsRegressor]"; expected "Type[NeighborsBase]"

I could probably just silence it but do you understand what is causing this? I checked and KNeighborsClassifier inherits from NeighborsBase.

@thomasjpfan
Copy link
Member

My sense is that decorators + mypy can give strange results. In this case, adding pytest to the azure CI linting environment resolved the issue. (pytest 6.x added better typing support)

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for merging this PR then. Thanks @thomasjpfan for the mypy investigation / fix.

@ogrisel
Copy link
Member

ogrisel commented May 14, 2021

This will make our tracebacks and profiler report simpler and easier to understand.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

None yet

4 participants