8000 MRG don't warn on changing dtypes in scalers (#13306) · koenvandevelde/scikit-learn@7a23fa5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a23fa5

Browse files
amuellerkoenvandevelde
authored andcommitted
MRG don't warn on changing dtypes in scalers (scikit-learn#13306)
* don't warn on changing dtypes in scalers * remove tests for dtype warnings * len(False) > len(True) pep8
1 parent d258bf2 commit 7a23fa5

File tree

3 files changed

+10
-26
lines changed

3 files changed

+10
-26
lines changed

sklearn/compose/tests/test_column_transformer.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from sklearn.base import BaseEstimator
1818
from sklearn.compose import ColumnTransformer, make_column_transformer
19-
from sklearn.exceptions import NotFittedError, DataConversionWarning
19+
from sklearn.exceptions import NotFittedError
2020
from sklearn.preprocessing import StandardScaler, Normalizer, OneHotEncoder
2121
from sklearn.feature_extraction import DictVectorizer
2222

@@ -336,11 +336,8 @@ def test_column_transformer_list():
336336
('categorical', OneHotEncoder(), [2]),
337337
])
338338

339-
with pytest.warns(DataConversionWarning):
340-
# TODO: this warning is not very useful in this case, would be good
341-
# to get rid of it
342-
assert_array_equal(ct.fit_transform(X_list), expected_result)
343-
assert_array_equal(ct.fit(X_list).transform(X_list), expected_result)
339+
assert_array_equal(ct.fit_transform(X_list), expected_result)
340+
assert_array_equal(ct.fit(X_list).transform(X_list), expected_result)
344341

345342

346343
def test_column_transformer_sparse_stacking():

sklearn/preprocessing/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def scale(X, axis=0, with_mean=True, with_std=True, copy=True):
137137
138138
""" # noqa
139139
X = check_array(X, accept_sparse='csc', copy=copy, ensure_2d=False,
140-
warn_on_dtype=True, estimator='the scale function',
140+
warn_on_dtype=False, estimator='the scale function',
141141
dtype=FLOAT_DTYPES, force_all_finite='allow-nan')
142142
if sparse.issparse(X):
143143
if with_mean:
@@ -348,7 +348,7 @@ def partial_fit(self, X, y=None):
348348
raise TypeError("MinMaxScaler does no support sparse input. "
349349
"You may consider to use MaxAbsScaler instead.")
350350

351-
X = check_array(X, copy=self.copy, warn_on_dtype=True,
351+
X = check_array(X, copy=self.copy, warn_on_dtype=False,
352352
estimator=self, dtype=FLOAT_DTYPES,
353353
force_all_finite="allow-nan")
354354

@@ -468,7 +468,7 @@ def minmax_scale(X, feature_range=(0, 1), axis=0, copy=True):
468468
""" # noqa
469469
# Unlike the scaler object, this function allows 1d input.
470470
# If copy is required, it will be done inside the scaler object.
471-
X = check_array(X, copy=False, ensure_2d=False, warn_on_dtype=True,
471+
X = check_array(X, copy=False, ensure_2d=False, warn_on_dtype=False,
472472
dtype=FLOAT_DTYPES, force_all_finite='allow-nan')
473473
original_ndim = X.ndim
474474

@@ -659,8 +659,8 @@ def partial_fit(self, X, y=None):
659659
Ignored
660660
"""
661661
X = check_array(X, accept_sparse=('csr', 'csc'), copy=self.copy,
662-
warn_on_dtype=True, estimator=self, dtype=FLOAT_DTYPES,
663-
force_all_finite='allow-nan')
662+
warn_on_dtype=False, estimator=self,
663+
dtype=FLOAT_DTYPES, force_all_finite='allow-nan')
664664

665665
# Even in the case of `with_mean=False`, we update the mean anyway
666666
# This is needed for the incremental computation of the var
@@ -753,7 +753,7 @@ def transform(self, X, copy=None):
753753
check_is_fitted(self, 'scale_')
754754

755755
copy = copy if copy is not None else self.copy
756-
X = check_array(X, accept_sparse='csr', copy=copy, warn_on_dtype=True,
756+
X = check_array(X, accept_sparse='csr', copy=copy, warn_on_dtype=False,
757757
estimator=self, dtype=FLOAT_DTYPES,
758758
force_all_finite='allow-nan')
759759

sklearn/preprocessing/tests/test_data.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from sklearn.preprocessing.data import PowerTransformer
5555
from sklearn.preprocessing.data import power_transform
5656
from sklearn.preprocessing.data import BOUNDS_THRESHOLD
57-
from sklearn.exceptions import DataConversionWarning, NotFittedError
57+
from sklearn.exceptions import NotFittedError
5858

5959
from sklearn.base import clone
6060
from sklearn.pipeline import Pipeline
@@ -1695,19 +1695,6 @@ def test_maxabs_scaler_transform_one_row_csr():
16951695
assert_array_almost_equal(X.toarray(), X_scaled_back.toarray())
16961696

16971697

1698-
def test_warning_scaling_integers():
1699-
# Check warning when scaling integer data
1700-
X = np.array([[1, 2, 0],
1701-
[0, 0, 0]], dtype=np.uint8)
1702-
1703-
w = "Data with input dtype uint8 was converted to float64"
1704-
1705-
clean_warning_registry()
1706-
assert_warns_message(DataConversionWarning, w, scale, X)
1707-
assert_warns_message(DataConversionWarning, w, StandardScaler().fit, X)
1708-
assert_warns_message(DataConversionWarning, w, MinMaxScaler().fit, X)
1709-
1710-
17111698
def test_maxabs_scaler_1d():
17121699
# Test scaling of dataset along single axis
17131700
for X in [X_1row, X_1col, X_list_1row, X_list_1row]:

0 commit comments

Comments
 (0)
0