Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions python/cuml/cuml/common/exceptions.py

This file was deleted.

39 changes: 6 additions & 33 deletions python/cuml/cuml/internals/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def _get_n_features(X):

ndim = len(shape)

if ndim != 2:
import cuml.accel

if ndim < 2:
if isinstance(X, (cudf.Series, pd.Series)):
msg = (
f"Expected a 2-dimensional container but got {type(X).__name__} "
Expand All @@ -100,37 +98,13 @@ def _get_n_features(X):
"using array.reshape(-1, 1) if your data has a single feature, "
"or array.reshape(1, -1) if it contains a single sample."
)
raise ValueError(msg)
elif ndim > 2:
raise ValueError(f"Expected 2D array, got {ndim}D array instead.")

if cuml.accel.enabled() or ndim > 2:
raise ValueError(msg)
else:
warnings.warn(
"Support for passing non-2-dimensional X was deprecated in 26.04 "
"and will be removed in version 26.06 of cuML. In version 26.06 this will error "
f"with the following message:\n\n{msg}",
FutureWarning,
)
# Fallback to 1 feature until the deprecation is completed
return 1
return shape[1]


def _warn_or_error(exc_cls, msg):
"""Errors if running in cuml.accel, otherwise warns that an error will be
raised in the future."""
import cuml.accel

if cuml.accel.enabled():
raise exc_cls(msg)
else:
warnings.warn(
"cuml is adding support for `feature_names_in_` for validating "
"the feature names of dataframe-like inputs. In version 26.06 of cuML this "
f"will error with the following message:\n\n{msg}",
FutureWarning,
)


def _get_feature_names(X):
"""Get feature names from X.

Expand All @@ -157,15 +131,14 @@ def _get_feature_names(X):
if len(types) == 1 and types[0] == "str":
return feature_names
elif len(types) > 1 and "str" in types:
msg = (
raise TypeError(
"Feature names are only supported if all input features have string names, "
f"but your input has {types} as feature name / column name types. "
"If you want feature names to be stored and validated, you must convert "
"them all to strings, by using X.columns = X.columns.astype(str) for "
"example. Otherwise you can remove feature / column names from your input "
"data, or convert them all to a non-string data type."
)
_warn_or_error(TypeError, msg)

return None

Expand Down Expand Up @@ -241,7 +214,7 @@ def check_features(estimator, X, reset=False) -> None:
)

msg = "\n".join(parts)
_warn_or_error(ValueError, msg)
raise ValueError(msg)

# Then check n_features_in_
if n_features != estimator.n_features_in_:
Expand Down
46 changes: 1 addition & 45 deletions python/cuml/tests/test_sklearn_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@
"check_dtype_object": "KMeans does not handle object dtype",
"check_estimators_nan_inf": "KMeans does not check for NaN and inf",
"check_transformer_data_not_an_array": "KMeans does not handle non-array data",
"check_fit1d": "KMeans does not raise ValueError for 1D input",
"check_fit2d_predict1d": "KMeans does not handle 1D prediction input gracefully",
},
KernelRidge: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -115,8 +113,6 @@
"check_regressor_data_not_an_array": "KernelRidge does not handle non-array data",
"check_supervised_y_2d": "KernelRidge does not handle 2D y",
"check_supervised_y_no_nan": "KernelRidge does not check for NaN in y",
"check_fit1d": "KernelRidge does not raise ValueError for 1D input",
"check_fit2d_predict1d": "KernelRidge does not handle 1D prediction input gracefully",
"check_requires_y_none": "KernelRidge does not handle y=None",
},
LogisticRegression: {
Expand All @@ -136,8 +132,6 @@
"check_supervised_y_2d": "LogisticRegression does not handle 2D y",
"check_class_weight_classifiers": "LogisticRegression does not handle class weights properly",
"check_fit2d_1sample": "LogisticRegression does not handle single sample",
"check_fit1d": "LogisticRegression does not raise ValueError for 1D input",
"check_fit2d_predict1d": "LogisticRegression does not handle 1D prediction input gracefully",
"check_requires_y_none": "LogisticRegression does not handle y=None",
},
LinearRegression: {
Expand All @@ -154,8 +148,6 @@
"check_regressor_data_not_an_array": "LinearRegression does not handle non-array data",
"check_supervised_y_no_nan": "LinearRegression does not check for NaN in y",
"check_fit2d_1sample": "LinearRegression does not handle single sample",
"check_fit1d": "LinearRegression does not raise ValueError for 1D input",
"check_fit2d_predict1d": "LinearRegression does not handle 1D prediction input gracefully",
"check_requires_y_none": "LinearRegression does not handle y=None",
},
Ridge: {
Expand All @@ -171,8 +163,6 @@
"check_regressor_data_not_an_array": "Ridge does not handle non-array data",
"check_supervised_y_2d": "Ridge does not handle 2D y",
"check_supervised_y_no_nan": "Ridge does not check for NaN in y",
"check_fit1d": "Ridge does not raise ValueError for 1D input",
"check_fit2d_predict1d": "Ridge does not handle 1D prediction input gracefully",
"check_requires_y_none": "Ridge does not handle y=None",
"check_non_transformer_estimators_n_iter": "Ridge `n_iter_` may be `None`",
},
Expand All @@ -189,8 +179,6 @@
"check_supervised_y_2d": "RandomForestRegressor does not handle 2D y",
"check_supervised_y_no_nan": "RandomForestRegressor does not check for NaN in y",
"check_dict_unchanged": "RandomForestRegressor modifies input dictionaries",
"check_fit1d": "RandomForestRegressor does not raise ValueError for 1D input",
"check_fit2d_predict1d": "RandomForestRegressor does not handle 1D prediction input gracefully",
"check_requires_y_none": "RandomForestRegressor does not handle y=None",
},
KNeighborsClassifier: {
Expand All @@ -203,7 +191,6 @@
"check_classifiers_train": "KNeighborsClassifier does not validate input data properly",
"check_supervised_y_no_nan": "KNeighborsClassifier does not check for NaN in y",
"check_supervised_y_2d": "KNeighborsClassifier does not handle 2D y",
"check_fit2d_predict1d": "KNeighborsClassifier does not handle 1D prediction input gracefully",
"check_requires_y_none": "KNeighborsClassifier does not handle y=None",
},
RandomForestClassifier: {
Expand All @@ -219,8 +206,6 @@
"check_supervised_y_no_nan": "RandomForestClassifier does not check for NaN in y",
"check_supervised_y_2d": "RandomForestClassifier does not handle 2D y",
"check_dict_unchanged": "RandomForestClassifier modifies input dictionaries",
"check_fit1d": "RandomForestClassifier does not raise ValueError for 1D input",
"check_fit2d_predict1d": "RandomForestClassifier does not handle 1D prediction input gracefully",
"check_requires_y_none": "RandomForestClassifier does not handle y=None",
},
KNeighborsRegressor: {
Expand All @@ -235,7 +220,6 @@
"check_regressor_data_not_an_array": "KNeighborsRegressor does not handle non-array data",
"check_supervised_y_2d": "KNeighborsRegressor does not handle 2D y",
"check_supervised_y_no_nan": "KNeighborsRegressor does not check for NaN in y",
"check_fit2d_predict1d": "KNeighborsRegressor does not handle 1D prediction input gracefully",
"check_requires_y_none": "KNeighborsRegressor does not handle y=None",
},
NearestNeighbors: {
Expand All @@ -257,8 +241,6 @@
"check_classifiers_train(readonly_memmap=True)": "LinearSVC does not handle readonly memmap",
"check_classifiers_train(readonly_memmap=True,X_dtype=float32)": "LinearSVC does not handle readonly memmap with float32",
"check_supervised_y_2d": "LinearSVC does not handle 2D y",
"check_fit1d": "LinearSVC does not raise ValueError for 1D input",
"check_fit2d_predict1d": "LinearSVC does not handle 1D prediction input gracefully",
"check_requires_y_none": "LinearSVC does not handle y=None",
},
LinearSVR: {
Expand All @@ -275,8 +257,6 @@
"check_regressor_data_not_an_array": "LinearSVR does not handle non-array data",
"check_supervised_y_2d": "LinearSVR does not handle 2D y",
"check_supervised_y_no_nan": "LinearSVR does not check for NaN in y",
"check_fit1d": "LinearSVR does not raise ValueError for 1D input",
"check_fit2d_predict1d": "LinearSVR does not handle 1D prediction input gracefully",
"check_requires_y_none": "LinearSVR does not handle y=None",
},
SVC: {
Expand All @@ -294,7 +274,6 @@
"check_requires_y_none": "SVC does not handle y=None",
"check_sample_weights_list": "SVC does not handle list sample weights",
"check_supervised_y_2d": "SVC does not warn on 1 column 2D y",
"check_fit2d_predict1d": "SVC doesn't raise the expected error",
},
SVR: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -311,7 +290,6 @@
"check_regressor_data_not_an_array": "SVR does not handle non-array data",
"check_supervised_y_2d": "SVR does not handle 2D y",
"check_supervised_y_no_nan": "SVR does not check for NaN in y",
"check_fit2d_predict1d": "SVR does not handle 1D prediction input gracefully",
"check_requires_y_none": "SVR does not handle y=None",
},
PCA: {
Expand All @@ -322,16 +300,13 @@
"check_transformer_data_not_an_array": "PCA does not handle non-array data",
"check_fit2d_1sample": "PCA does not handle single sample",
"check_fit2d_1feature": "PCA does not handle single feature",
"check_fit1d": "PCA does not raise ValueError for 1D input",
"check_fit2d_predict1d": "PCA does not handle 1D prediction input gracefully",
},
IncrementalPCA: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_dtype_object": "IncrementalPCA does not handle object dtype",
"check_estimators_empty_data_messages": "IncrementalPCA does not handle empty data",
"check_estimators_nan_inf": "IncrementalPCA does not check for NaN and inf",
"check_transformer_data_not_an_array": "IncrementalPCA does not handle non-array data",
"check_fit2d_predict1d": "IncrementalPCA does not handle 1D prediction input gracefully",
},
TruncatedSVD: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -341,8 +316,6 @@
"check_transformer_data_not_an_array": "TruncatedSVD does not handle non-array data",
"check_fit2d_1sample": "TruncatedSVD does not handle single sample",
"check_fit2d_1feature": "TruncatedSVD does not handle single feature",
"check_fit1d": "TruncatedSVD does not raise ValueError for 1D input",
"check_fit2d_predict1d": "TruncatedSVD does not handle 1D prediction input gracefully",
},
TSNE: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -355,7 +328,7 @@
"check_methods_subset_invariance": "TSNE results depend on data subset",
"check_fit2d_1sample": "TSNE does not handle single sample",
"check_fit2d_1feature": "TSNE does not handle single feature",
"check_fit2d_predict1d": "TSNE does not handle 1D prediction input gracefully",
"check_fit2d_predict1d": "TSNE only supports n_components = 2",
},
UMAP: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -364,7 +337,6 @@
"check_methods_sample_order_invariance": "UMAP results depend on sample order",
"check_transformer_general": "UMAP does not have consistent fit_transform and transform outputs",
"check_methods_subset_invariance": "UMAP results depend on data subset",
"check_fit2d_predict1d": "UMAP doesn't raise the expected error",
},
Lasso: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -379,8 +351,6 @@
"check_regressor_data_not_an_array": "Lasso does not handle non-array data",
"check_supervised_y_2d": "Lasso does not handle 2D y",
"check_supervised_y_no_nan": "Lasso does not check for NaN in y",
"check_fit1d": "Lasso does not raise ValueError for 1D input",
"check_fit2d_predict1d": "Lasso does not handle 1D prediction input gracefully",
"check_requires_y_none": "Lasso does not handle y=None",
},
ElasticNet: {
Expand All @@ -396,8 +366,6 @@
"check_regressor_data_not_an_array": "ElasticNet does not handle non-array data",
"check_supervised_y_2d": "ElasticNet does not handle 2D y",
"check_supervised_y_no_nan": "ElasticNet does not check for NaN in y",
"check_fit1d": "ElasticNet does not raise ValueError for 1D input",
"check_fit2d_predict1d": "ElasticNet does not handle 1D prediction input gracefully",
"check_requires_y_none": "ElasticNet does not handle y=None",
},
KernelDensity: {
Expand All @@ -407,7 +375,6 @@
"check_all_zero_sample_weights_error": "KernelDensity does not validate all-zero sample weights",
"check_dtype_object": "KernelDensity does not handle object dtype",
"check_estimators_nan_inf": "KernelDensity does not check for NaN and inf",
"check_fit1d": "KernelDensity does not raise ValueError for 1D input",
},
LedoitWolf: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -423,21 +390,18 @@
"check_dtype_object": "DBSCAN does not handle object dtype",
"check_estimators_empty_data_messages": "DBSCAN does not handle empty data",
"check_estimators_nan_inf": "DBSCAN does not check for NaN and inf",
"check_fit1d": "DBSCAN does not raise ValueError for 1D input",
},
HDBSCAN: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_dtype_object": "HDBSCAN does not handle object dtype",
"check_estimators_empty_data_messages": "HDBSCAN does not handle empty data",
"check_estimators_nan_inf": "HDBSCAN does not check for NaN and inf",
"check_fit2d_1sample": "HDBSCAN does not handle single sample properly",
"check_fit1d": "HDBSCAN does not raise ValueError for 1D input",
},
AgglomerativeClustering: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
"check_dtype_object": "AgglomerativeClustering does not handle object dtype",
"check_estimators_nan_inf": "AgglomerativeClustering does not check for NaN and inf",
"check_fit1d": "AgglomerativeClustering does not raise ValueError for 1D input",
},
SpectralClustering: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -463,8 +427,6 @@
"check_classifiers_regression_target": "GaussianNB does not handle regression targets",
"check_supervised_y_no_nan": "GaussianNB does not check for NaN in y",
"check_supervised_y_2d": "GaussianNB does not handle 2D y",
"check_fit1d": "GaussianNB does not raise ValueError for 1D input",
"check_fit2d_predict1d": "GaussianNB does not handle 1D prediction input gracefully",
"check_requires_y_none": "GaussianNB does not handle y=None",
"check_sample_weights_list": "GaussianNB does not handle list sample weights",
},
Expand All @@ -475,7 +437,6 @@
"check_estimators_empty_data_messages": "GaussianRandomProjection doesn't check for empty data",
"check_estimators_nan_inf": "GaussianRandomProjection does not check for NaN and inf",
"check_transformer_data_not_an_array": "GaussianRandomProjection does not handle non-array data",
"check_fit2d_predict1d": "GaussianRandomProjection does not handle 1D prediction input gracefully",
},
SparseRandomProjection: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -484,7 +445,6 @@
"check_estimators_empty_data_messages": "SparseRandomProjection doesn't check for empty data",
"check_estimators_nan_inf": "SparseRandomProjection does not check for NaN and inf",
"check_transformer_data_not_an_array": "SparseRandomProjection does not handle non-array data",
"check_fit2d_predict1d": "SparseRandomProjection does not handle 1D prediction input gracefully",
},
BernoulliNB: {
"check_estimator_tags_renamed": "No support for modern tags infrastructure",
Expand All @@ -505,7 +465,6 @@
"check_classifiers_regression_target": "BernoulliNB does not validate target is classification",
"check_supervised_y_no_nan": "BernoulliNB does not check for NaN in y",
"check_supervised_y_2d": "BernoulliNB does not handle 2D y input gracefully",
"check_fit2d_predict1d": "BernoulliNB does not handle 1D prediction input gracefully",
"check_requires_y_none": "BernoulliNB does not require y for fit",
},
ComplementNB: {
Expand All @@ -527,7 +486,6 @@
"check_classifiers_regression_target": "ComplementNB does not validate target is classification",
"check_supervised_y_no_nan": "ComplementNB does not check for NaN in y",
"check_supervised_y_2d": "ComplementNB does not handle 2D y input gracefully",
"check_fit2d_predict1d": "ComplementNB does not handle 1D prediction input gracefully",
"check_requires_y_none": "ComplementNB does not require y for fit",
},
CategoricalNB: {
Expand All @@ -549,7 +507,6 @@
"check_classifiers_regression_target": "CategoricalNB does not validate target is classification",
"check_supervised_y_no_nan": "CategoricalNB does not check for NaN in y",
"check_supervised_y_2d": "CategoricalNB does not handle 2D y input gracefully",
"check_fit2d_predict1d": "CategoricalNB does not handle 1D prediction input gracefully",
"check_requires_y_none": "CategoricalNB does not require y for fit",
},
MultinomialNB: {
Expand All @@ -571,7 +528,6 @@
"check_classifiers_regression_target": "MultinomialNB does not validate target is classification",
"check_supervised_y_no_nan": "MultinomialNB does not check for NaN in y",
"check_supervised_y_2d": "MultinomialNB does not handle 2D y input gracefully",
"check_fit2d_predict1d": "MultinomialNB does not handle 1D prediction input gracefully",
"check_requires_y_none": "MultinomialNB does not require y for fit",
},
}
Expand Down
3 changes: 0 additions & 3 deletions python/cuml/tests/test_sklearn_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,6 @@ def test_linear_svc(random_state):
assert sk_score > 0.7


@pytest.mark.filterwarnings(
"ignore:TargetEncoder currently returns 1D output:FutureWarning"
)
def test_target_encoder(random_state):
# Create simple categorical data
X = np.array(
Expand Down
Loading
Loading