Skip to content

Commit 4884482

Browse files
committed
Reworking .transform conditionals for out_of_bounds argument
1 parent 376a9ac commit 4884482

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

sklearn/isotonic.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,21 +293,23 @@ def transform(self, T):
293293
if len(T.shape) != 1:
294294
raise ValueError("X should be a vector")
295295

296-
# Only raise exception on out-of-bounds data if requested.
296+
# Handle the out_of_bounds argument by setting bounds_error and T
297297
if self.out_of_bounds == "raise":
298298
f = interpolate.interp1d(self.X_, self.y_, kind='linear',
299299
bounds_error=True)
300-
else:
300+
elif self.out_of_bounds == "nan":
301301
f = interpolate.interp1d(self.X_, self.y_, kind='linear',
302302
bounds_error=False)
303-
304-
# Clip out-of-bounds values if requested.
305-
if self.out_of_bounds == "clip":
306-
T_final = np.clip(T, self.X_min_, self.X_max_)
303+
elif self.out_of_bounds == "clip":
304+
f = interpolate.interp1d(self.X_, self.y_, kind='linear',
305+
bounds_error=False)
306+
T = np.clip(T, self.X_min_, self.X_max_)
307307
else:
308-
T_final = T
308+
raise ValueError("The argument ``out_of_bounds`` must be in "
309+
"'nan', 'clip', 'raise'; got {0}"\
310+
.format(self.out_of_bounds))
309311

310-
return f(T_final)
312+
return f(T)
311313

312314
def fit_transform(self, X, y, sample_weight=None, weight=None):
313315
"""Fit model and transform y by linear interpolation.

0 commit comments

Comments
 (0)