@@ -252,8 +252,6 @@ def _build_y(self, X, y, sample_weight):
252252 """Build the y_ IsotonicRegression."""
253253 check_consistent_length (X , y , sample_weight )
254254 X , y = [check_array (x , ensure_2d = False ) for x in [X , y ]]
255- if sample_weight is not None :
256- sample_weight = check_array (sample_weight , ensure_2d = False )
257255
258256 y = as_float_array (y )
259257 self ._check_fit_data (X , y , sample_weight )
@@ -265,9 +263,16 @@ def _build_y(self, X, y, sample_weight):
265263 self .increasing_ = self .increasing
266264
267265 order = np .lexsort ((y , X ))
268- order_inv = np .argsort (order )
269- if sample_weight is None :
266+
267+ # If sample_weights is passed, removed zero-weight values and clean order
268+ if sample_weight is not None :
269+ sample_weight = check_array (sample_weight , ensure_2d = False )
270+ order = order [np .where (sample_weight > 0 )]
271+ sample_weight = sample_weight [order ]
272+ else :
270273 sample_weight = np .ones (len (y ))
274+
275+ order_inv = np .argsort (order )
271276 X , y , sample_weight = [astype (array [order ], np .float64 , copy = False )
272277 for array in [X , y , sample_weight ]]
273278 unique_X , unique_y , unique_sample_weight = _make_unique (X , y , sample_weight )
0 commit comments