Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
tianlh
LightGBM-DCU
Commits
c58320fc
Unverified
Commit
c58320fc
authored
May 25, 2025
by
Nick Miller
Committed by
GitHub
May 25, 2025
Browse files
[python-package] Add specific error messages to `test_sklearn` (#6929)
add error messages to test_sklearn.py
parent
59f8a9b6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
tests/python_package_test/test_sklearn.py
tests/python_package_test/test_sklearn.py
+6
-3
No files found.
tests/python_package_test/test_sklearn.py
View file @
c58320fc
...
@@ -1524,7 +1524,8 @@ def test_check_is_fitted():
...
@@ -1524,7 +1524,8 @@ def test_check_is_fitted():
rnk
=
lgb
.
LGBMRanker
(
n_estimators
=
5
)
rnk
=
lgb
.
LGBMRanker
(
n_estimators
=
5
)
models
=
(
est
,
clf
,
reg
,
rnk
)
models
=
(
est
,
clf
,
reg
,
rnk
)
for
model
in
models
:
for
model
in
models
:
with
pytest
.
raises
(
lgb
.
compat
.
LGBMNotFittedError
):
err_msg
=
f
"This
{
type
(
model
).
__name__
}
instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
with
pytest
.
raises
(
lgb
.
compat
.
LGBMNotFittedError
,
match
=
err_msg
):
check_is_fitted
(
model
)
check_is_fitted
(
model
)
est
.
fit
(
X
,
y
)
est
.
fit
(
X
,
y
)
clf
.
fit
(
X
,
y
)
clf
.
fit
(
X
,
y
)
...
@@ -1623,7 +1624,8 @@ def test_getting_feature_names_in_np_input(estimator_class):
...
@@ -1623,7 +1624,8 @@ def test_getting_feature_names_in_np_input(estimator_class):
model
=
estimator_class
(
**
{
**
params
,
"objective"
:
"binary"
})
model
=
estimator_class
(
**
{
**
params
,
"objective"
:
"binary"
})
else
:
else
:
model
=
estimator_class
(
**
params
)
model
=
estimator_class
(
**
params
)
with
pytest
.
raises
(
lgb
.
compat
.
LGBMNotFittedError
):
err_msg
=
f
"This
{
estimator_class
.
__name__
}
instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
with
pytest
.
raises
(
lgb
.
compat
.
LGBMNotFittedError
,
match
=
err_msg
):
check_is_fitted
(
model
)
check_is_fitted
(
model
)
if
isinstance
(
model
,
lgb
.
LGBMRanker
):
if
isinstance
(
model
,
lgb
.
LGBMRanker
):
model
.
fit
(
X
,
y
,
group
=
[
X
.
shape
[
0
]])
model
.
fit
(
X
,
y
,
group
=
[
X
.
shape
[
0
]])
...
@@ -1644,7 +1646,8 @@ def test_getting_feature_names_in_pd_input(estimator_class):
...
@@ -1644,7 +1646,8 @@ def test_getting_feature_names_in_pd_input(estimator_class):
model
=
estimator_class
(
**
{
**
params
,
"objective"
:
"binary"
})
model
=
estimator_class
(
**
{
**
params
,
"objective"
:
"binary"
})
else
:
else
:
model
=
estimator_class
(
**
params
)
model
=
estimator_class
(
**
params
)
with
pytest
.
raises
(
lgb
.
compat
.
LGBMNotFittedError
):
err_msg
=
f
"This
{
estimator_class
.
__name__
}
instance is not fitted yet. Call 'fit' with appropriate arguments before using this estimator."
with
pytest
.
raises
(
lgb
.
compat
.
LGBMNotFittedError
,
match
=
err_msg
):
check_is_fitted
(
model
)
check_is_fitted
(
model
)
if
isinstance
(
model
,
lgb
.
LGBMRanker
):
if
isinstance
(
model
,
lgb
.
LGBMRanker
):
model
.
fit
(
X
,
y
,
group
=
[
X
.
shape
[
0
]])
model
.
fit
(
X
,
y
,
group
=
[
X
.
shape
[
0
]])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment