Repository navigation
FIX (HDBSCAN) : FutureWarning for copy parameter deprecation - #31973
Conversation
4067f81 to
f648148
Compare
|
@adrinjalali @Micky774 for the DocTest of or I can modify the DocTest code in Additionally, for the Changelog, should I create |
adrinjalali
left a comment
There was a problem hiding this comment.
or I can modify the DocTest code in HDBSCAN class documentation like hdb = HDBSCAN(min_cluster_size=20, copy=True) in order that it does not trigger the warning.
That's an okay solution.
Additionally, for the Changelog, should I create 31973.fix.rst in \doc\whats_new\upcoming_changes\sklearn.cluster?
Yes
| "allow_single_cluster": ["boolean"], | ||
| "store_centers": [None, StrOptions({"centroid", "medoid", "both"})], | ||
| "copy": ["boolean"], | ||
| "copy": ["boolean", StrOptions({"warn"})], |
| """ | ||
| if self.copy == "warn": | ||
| warn( | ||
| "The default value of `copy` will change from False to True in 1.10", |
There was a problem hiding this comment.
| "The default value of `copy` will change from False to True in 1.10", | |
| "The default value of `copy` will change from False to True in 1.10." | |
| " Explicitly set a value for `copy` to silence this warning.", |
| "The default value of `copy` will change from False to True in 1.10", | ||
| FutureWarning, | ||
| ) | ||
| self._copy = False |
There was a problem hiding this comment.
since this is only used in fit here, no need to set an attribute, could simply be a local variable.
| pytestmark = pytest.mark.filterwarnings( | ||
| "ignore:The default value of `copy` will change from False to True in 1.10" | ||
| ) |
There was a problem hiding this comment.
instead of this, the tests which raise should set the value of copy explicitly, and have a test which tests the right warning is raised at the right time.
There was a problem hiding this comment.
I agree we should create an additional test to check if the deprecation warning is being raised correctly. I'll add that test.
However, for the first part, that we set the value of copy explicitly - I think keeping the file level marker will be a better choice because this file contains only the HDBSCAN testcases and there are 25+ testcases which needs to have the copy parameter set explicitly. Also, in the future when the version 1.10 will be released, we will have to explicitly remove the copy parameter to get the default behavior back. So, I think we can keep this warning as it is (I'll update the changes in warning suggested above and a #TODO as well).
What do you think?
@adrinjalali
There was a problem hiding this comment.
here we'd set the value of copy to what the new value would be (True) and therefore after 1.10 no change is needed. This is how we've handled other deprecation cases as well.
|
|
||
|
|
||
| @pytest.mark.filterwarnings("ignore::sklearn.exceptions.ConvergenceWarning") | ||
| @pytest.mark.filterwarnings( |
There was a problem hiding this comment.
| @pytest.mark.filterwarnings( | |
| # TODO(1.10): remove filter | |
| @pytest.mark.filterwarnings( |
…# TODO for removals of warnings
…constraints of HDBSCAN
…n all test's `HDBSCAN` instances to remove warning.
…he `copy` parameter is not set.
|
@adrinjalali I made the suggested changes. Please have a look. |
adrinjalali
left a comment
There was a problem hiding this comment.
please submit a commit (can be empty) with a [doc build] message to trigger a full doc build to make sure there are no warnings there. You probably need to fix the usages of HDBSCAN in the docs first.
fafe75a to
d8abea9
Compare
|
@adrinjalali I am waiting for your review. Please check if everything is fine now. |
adrinjalali
left a comment
There was a problem hiding this comment.
LGTM. Maybe @jeremiedbb could have a look
jeremiedbb
left a comment
There was a problem hiding this comment.
I just pushed a commit to use copy=False when possible in the tests to reduce memory usage.
LGTM. Thanks @Sarthakpurii !
Reference Issues/PRs
Fixes #31907
What does this implement/fix? Explain your changes.
What’s the bug:
When using
metric = 'precomputed', scikit-learn’sHDBSCANmodified the input matrix in place.This breaks the expected contract that input data passed to
fitremain unchanged.On further evaluation,
copyparameter in all estimators are set toTrue,HDBSCANis the only estimator havingcopy = Falseas default, breaking the overall consistency.What this PR does:
copyparameter from False to"warn"."warns"in_parameter_constraintsforcopyto enable the new default.fit(), warns the user about default value change deprecation ofcopyparameter, ifcopyif not explicitly defined by the user. Additionally, it sets the copy toFalseif it is"warn"given the current default value ofcopy.copyparameter deprecation in version1.10.Why:
This ensures the consistency of
HDBSCAN'scopyparameter with scikit-learn other estimators. Also, it will fix the default working of HDBSCAN to not alter the original matrix if the given matrix is precomputed matrix in the future version (1.10).