Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MNT Improve error check_array error message when estimator is None #30485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 20, 2024
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
21 changes: 21 additions & 0 deletions 21 sklearn/utils/tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2358,3 +2358,24 @@ def test_force_all_finite_rename_warning():

with pytest.warns(FutureWarning, match=msg):
as_float_array(X, force_all_finite=True)


@pytest.mark.parametrize(
["X", "estimator", "expected_error_message"],
[
(
np.array([[[1, 2], [3, 4]], [[1, 2], [3, 4]]]),
RandomForestRegressor(),
"Found array with dim 3, while dim <= 2 is required by "
"RandomForestRegressor.",
),
(
np.array([[[1, 2], [3, 4]], [[1, 2], [3, 4]]]),
None,
"Found array with dim 3, while dim <= 2 is required.",
),
],
)
def test_check_array_allow_nd_errors(X, estimator, expected_error_message):
with pytest.raises(ValueError, match=expected_error_message):
check_array(X, estimator=estimator)
4 changes: 2 additions & 2 deletions 4 sklearn/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ def is_sparse(dtype):
)
if not allow_nd and array.ndim >= 3:
raise ValueError(
"Found array with dim %d. %s expected <= 2."
% (array.ndim, estimator_name)
f"Found array with dim {array.ndim},"
f" while dim <= 2 is required{context}."
)

if ensure_all_finite:
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.