From 667e1591c79ae2bb6e354dd2238d73934e05816a Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Tue, 4 Apr 2023 10:10:21 -0700 Subject: [PATCH 1/3] adding validation decorator to robust_scale --- sklearn/preprocessing/_data.py | 13 ++++++++++++- sklearn/tests/test_public_functions.py | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index bbb6e6fa80a12..568f758aeeadf 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -123,7 +123,7 @@ def _handle_zeros_in_scale(scale, copy=True, constant_mask=None): @validate_params( { "X": ["array-like", "sparse matrix"], - "axis": [Options(Integral, {0, 1})], + "axis": [Interval(Integral, 0, 1, closed="both")], "with_mean": ["boolean"], "with_std": ["boolean"], "copy": ["boolean"], @@ -1651,6 +1651,17 @@ def _more_tags(self): return {"allow_nan": True} +@validate_params( + { + "X": ["array-like", "sparse matrix"], + "axis": [Options(Integral, {0, 1})], + "with_centering": ["boolean"], + "with_scaling": ["boolean"], + "quantile_range": [tuple], + "copy": ["boolean"], + "unit_variance": ["boolean"], + } +) def robust_scale( X, *, diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index a6c829b23620f..f2294d567ae35 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -230,6 +230,7 @@ def _check_function_param_validation( "sklearn.preprocessing.label_binarize", "sklearn.preprocessing.maxabs_scale", "sklearn.preprocessing.normalize", + "sklearn.preprocessing.robust_scale", "sklearn.preprocessing.scale", "sklearn.random_projection.johnson_lindenstrauss_min_dim", "sklearn.svm.l1_min_c", From ef8b15294518aeb785561789c5c9f1cebe4b76fe Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Tue, 4 Apr 2023 11:26:43 -0700 Subject: [PATCH 2/3] reverting unintentional edits --- sklearn/preprocessing/_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index 568f758aeeadf..f3faa37b8ed3a 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -123,7 +123,7 @@ def _handle_zeros_in_scale(scale, copy=True, constant_mask=None): @validate_params( { "X": ["array-like", "sparse matrix"], - "axis": [Interval(Integral, 0, 1, closed="both")], + "axis": [Options(Integral, {0, 1})], "with_mean": ["boolean"], "with_std": ["boolean"], "copy": ["boolean"], From bf1f4b61a7bd8c586a63dff12a6fc0fba19c3e88 Mon Sep 17 00:00:00 2001 From: Juan Gomez Date: Mon, 10 Apr 2023 23:31:35 -0700 Subject: [PATCH 3/3] removing redudant validation params from robust_scale and moving validation tests to class wrapper list --- sklearn/preprocessing/_data.py | 10 +--------- sklearn/tests/test_public_functions.py | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/sklearn/preprocessing/_data.py b/sklearn/preprocessing/_data.py index f3faa37b8ed3a..eb3d89b48dc5d 100644 --- a/sklearn/preprocessing/_data.py +++ b/sklearn/preprocessing/_data.py @@ -1652,15 +1652,7 @@ def _more_tags(self): @validate_params( - { - "X": ["array-like", "sparse matrix"], - "axis": [Options(Integral, {0, 1})], - "with_centering": ["boolean"], - "with_scaling": ["boolean"], - "quantile_range": [tuple], - "copy": ["boolean"], - "unit_variance": ["boolean"], - } + {"X": ["array-like", "sparse matrix"], "axis": [Options(Integral, {0, 1})]} ) def robust_scale( X, diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index f2294d567ae35..c7f6c4c2dea53 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -230,7 +230,6 @@ def _check_function_param_validation( "sklearn.preprocessing.label_binarize", "sklearn.preprocessing.maxabs_scale", "sklearn.preprocessing.normalize", - "sklearn.preprocessing.robust_scale", "sklearn.preprocessing.scale", "sklearn.random_projection.johnson_lindenstrauss_min_dim", "sklearn.svm.l1_min_c", @@ -264,6 +263,7 @@ def test_function_param_validation(func_module): ("sklearn.decomposition.fastica", "sklearn.decomposition.FastICA"), ("sklearn.decomposition.non_negative_factorization", "sklearn.decomposition.NMF"), ("sklearn.preprocessing.minmax_scale", "sklearn.preprocessing.MinMaxScaler"), + ("sklearn.preprocessing.robust_scale", "sklearn.preprocessing.RobustScaler"), ]