Skip to content
12 changes: 6 additions & 6 deletions python/cuml/cuml/internals/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,12 @@ def from_input(

if is_sparse(X):
# We don't support coercing sparse arrays to dense via this method.
# Raising a NotImplementedError here lets us nicely error
# for estimators that don't support sparse arrays without requiring
# an additional external check. Otherwise they'd get an opaque error
# for code below.
raise NotImplementedError(
"Sparse inputs are not currently supported for this method"
# Raising a TypeError here lets us nicely error for estimators that
# don't support sparse arrays without requiring an additional
# external check. Using TypeError with "sparse" in the message
# satisfies sklearn's check_estimator_sparse_tag check.
raise TypeError(
"A sparse matrix was passed, but dense data is required. "
)
if convert_to_mem_type is not False:
convert_to_mem_type = MemoryType.from_str(convert_to_mem_type)
Expand Down
6 changes: 3 additions & 3 deletions python/cuml/tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2024-2025, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
#

Expand All @@ -24,7 +24,7 @@
NearestNeighbors,
)

# Currently only certain estimators raise a NotImplementedError
# Estimators that raise TypeError when given sparse input (they don't support sparse)
estimators = {
"KMeans": lambda: KMeans(n_clusters=2, random_state=0),
"DBSCAN": lambda: DBSCAN(eps=1.0),
Expand All @@ -44,7 +44,7 @@ def test_sparse_not_implemented_exception(estimator_name):
y_reg = np.array([0.0, 1.0])
estimator = estimators[estimator_name]()
# Fit or fit_transform depending on the estimator type
with pytest.raises(NotImplementedError):
with pytest.raises(TypeError, match="sparse"):
if isinstance(
estimator, (KMeans, DBSCAN, TruncatedSVD, NearestNeighbors)
):
Expand Down
Loading
Loading