Skip to content

Commit 5fbb227

Browse files
committed
ENH: issue warning when minmax scaling integer data + test
1 parent e192ce4 commit 5fbb227

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sklearn/preprocessing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def fit(self, X, y=None):
184184
used for later scaling along the features axis.
185185
"""
186186
X = check_arrays(X, sparse_format="dense", copy=self.copy)[0]
187+
warn_if_not_float(X, estimator=self)
187188
feature_range = self.feature_range
188189
if feature_range[0] >= feature_range[1]:
189190
raise ValueError("Minimum of desired feature range must be smaller"

sklearn/tests/test_preprocessing.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
import numpy as np
23
import numpy.linalg as la
34
import scipy.sparse as sp
@@ -280,6 +281,19 @@ def test_scale_function_without_centering():
280281
assert_array_almost_equal(X_csr_scaled_std, X_scaled.std(axis=0))
281282

282283

284+
def test_warning_scaling_integers():
285+
"""Check warning when scaling integer data"""
286+
X = np.array([[1, 2, 0],
287+
[0, 0, 0]], dtype=np.uint8)
288+
289+
with warnings.catch_warnings(record=True) as w:
290+
StandardScaler().fit(X)
291+
assert_equal(len(w), 1)
292+
293+
with warnings.catch_warnings(record=True) as w:
294+
MinMaxScaler().fit(X)
295+
assert_equal(len(w), 1)
296+
283297
def test_normalizer_l1():
284298
rng = np.random.RandomState(0)
285299
X_dense = rng.randn(4, 5)

0 commit comments

Comments
 (0)