Skip to content

Commit 550121b

Browse files
authored
Provide workaround for cupy.percentile bug(#3315)
Ensure that the 100th quantile value returned by cupy.percentile is the maximum of the input array rather than (possibly) NaN due to cupy/cupy#4451. This eliminates an intermittent failure observed in tests of KBinsDiscretizer, which makes use of cupy.percentile. Note that this includes an alteration of the included sklearn code and should be reverted once the upstream cupy issue is resolved. Resolve failure due to ValueError described in #2933. Authors: - William Hicks <[email protected]> Approvers: - Dante Gama Dessavre - Victor Lafargue URL: #3315
1 parent 2316937 commit 550121b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

python/cuml/_thirdparty/sklearn/preprocessing/_discretization.py

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def fit(self, X, y=None):
199199
elif self.strategy == 'quantile':
200200
quantiles = np.linspace(0, 100, n_bins[jj] + 1)
201201
bin_edges[jj] = np.asarray(np.percentile(column, quantiles))
202+
# Workaround for https://github.com/cupy/cupy/issues/4451
203+
# This should be removed as soon as a fix is available in cupy
204+
# in order to limit alterations in the included sklearn code
205+
bin_edges[jj][-1] = col_max
202206

203207
elif self.strategy == 'kmeans':
204208
# Deterministic initialization with uniform spacing

python/cuml/test/test_preprocessing.py

-1
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ def test_robust_scale_sparse(sparse_clf_dataset, # noqa: F811
556556
@pytest.mark.parametrize("n_bins", [5, 20])
557557
@pytest.mark.parametrize("encode", ['ordinal', 'onehot-dense', 'onehot'])
558558
@pytest.mark.parametrize("strategy", ['uniform', 'quantile', 'kmeans'])
559-
@pytest.mark.xfail(strict=False)
560559
def test_kbinsdiscretizer(blobs_dataset, n_bins, # noqa: F811
561560
encode, strategy):
562561
X_np, X = blobs_dataset

0 commit comments

Comments
 (0)