Skip to content

Commit 9e3ebd4

Browse files
yarikopticamueller
authored andcommitted
Fix for 0.17.X CPed from master (#6401)
* fix floating point indexing in generic univariate * weird work-around for spearman test * add test for auto increasing
1 parent 51a765a commit 9e3ebd4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

sklearn/feature_selection/univariate_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _get_support_mask(self):
403403
mask = scores > treshold
404404
ties = np.where(scores == treshold)[0]
405405
if len(ties):
406-
max_feats = len(scores) * self.percentile // 100
406+
max_feats = int(len(scores) * self.percentile / 100)
407407
kept_ties = ties[:max_feats - mask.sum()]
408408
mask[kept_ties] = True
409409
return mask

sklearn/tests/test_isotonic.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
import numpy as np
23
import pickle
34

@@ -166,7 +167,12 @@ def test_isotonic_regression_auto_decreasing():
166167

167168
# Create model and fit_transform
168169
ir = IsotonicRegression(increasing='auto')
169-
y_ = assert_no_warnings(ir.fit_transform, x, y)
170+
with warnings.catch_warnings(record=True) as w:
171+
warnings.simplefilter("always")
172+
y_ = ir.fit_transform(x, y)
173+
# work-around for pearson divide warnings in scipy <= 0.17.0
174+
assert_true(all(["invalid value encountered in "
175+
in str(warn.message) for warn in w]))
170176

171177
# Check that relationship decreases
172178
is_increasing = y_[0] < y_[-1]
@@ -180,7 +186,12 @@ def test_isotonic_regression_auto_increasing():
180186

181187
# Create model and fit_transform
182188
ir = IsotonicRegression(increasing='auto')
183-
y_ = assert_no_warnings(ir.fit_transform, x, y)
189+
with warnings.catch_warnings(record=True) as w:
190+
warnings.simplefilter("always")
191+
y_ = ir.fit_transform(x, y)
192+
# work-around for pearson divide warnings in scipy <= 0.17.0
193+
assert_true(all(["invalid value encountered in "
194+
in str(warn.message) for warn in w]))
184195

185196
# Check that relationship increases
186197
is_increasing = y_[0] < y_[-1]

0 commit comments

Comments
 (0)