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
798dc1d4
"...git@developer.sourcefind.cn:tianlh/lightgbm-dcu.git" did not exist on "23da5fc56abceac9ccb8ca2b09f945684e0f769e"
Unverified
Commit
798dc1d4
authored
Oct 29, 2021
by
Nikita Titov
Committed by
GitHub
Oct 28, 2021
Browse files
[tests] [python] add test for non-serializable callback (#4741)
parent
e10cbd23
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
tests/python_package_test/test_sklearn.py
tests/python_package_test/test_sklearn.py
+20
-0
No files found.
tests/python_package_test/test_sklearn.py
View file @
798dc1d4
...
@@ -32,6 +32,14 @@ else:
...
@@ -32,6 +32,14 @@ else:
decreasing_generator
=
itertools
.
count
(
0
,
-
1
)
decreasing_generator
=
itertools
.
count
(
0
,
-
1
)
class
UnpicklableCallback
:
def
__reduce__
(
self
):
raise
Exception
(
"This class in not picklable"
)
def
__call__
(
self
,
env
):
env
.
model
.
set_attr
(
attr_set_inside_callback
=
str
(
env
.
iteration
*
10
))
def
custom_asymmetric_obj
(
y_true
,
y_pred
):
def
custom_asymmetric_obj
(
y_true
,
y_pred
):
residual
=
(
y_true
-
y_pred
).
astype
(
np
.
float64
)
residual
=
(
y_true
-
y_pred
).
astype
(
np
.
float64
)
grad
=
np
.
where
(
residual
<
0
,
-
2
*
10.0
*
residual
,
-
2
*
residual
)
grad
=
np
.
where
(
residual
<
0
,
-
2
*
10.0
*
residual
,
-
2
*
residual
)
...
@@ -427,6 +435,18 @@ def test_joblib():
...
@@ -427,6 +435,18 @@ def test_joblib():
np
.
testing
.
assert_allclose
(
pred_origin
,
pred_pickle
)
np
.
testing
.
assert_allclose
(
pred_origin
,
pred_pickle
)
def
test_non_serializable_objects_in_callbacks
(
tmp_path
):
unpicklable_callback
=
UnpicklableCallback
()
with
pytest
.
raises
(
Exception
,
match
=
"This class in not picklable"
):
joblib
.
dump
(
unpicklable_callback
,
tmp_path
/
'tmp.joblib'
)
X
,
y
=
load_boston
(
return_X_y
=
True
)
gbm
=
lgb
.
LGBMRegressor
(
n_estimators
=
5
)
gbm
.
fit
(
X
,
y
,
callbacks
=
[
unpicklable_callback
])
assert
gbm
.
booster_
.
attr
(
'attr_set_inside_callback'
)
==
'40'
def
test_random_state_object
():
def
test_random_state_object
():
X
,
y
=
load_iris
(
return_X_y
=
True
)
X
,
y
=
load_iris
(
return_X_y
=
True
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.1
,
random_state
=
42
)
...
...
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