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
02d212b4
Unverified
Commit
02d212b4
authored
Jan 12, 2023
by
James Lamb
Committed by
GitHub
Jan 12, 2023
Browse files
[ci] [python-package] enforce flake8 checks (fixes #5566) (#5659)
parent
23403a7c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
10 deletions
+23
-10
.ci/test.sh
.ci/test.sh
+5
-2
docs/conf.py
docs/conf.py
+1
-1
python-package/lightgbm/compat.py
python-package/lightgbm/compat.py
+2
-2
python-package/setup.py
python-package/setup.py
+1
-1
tests/python_package_test/test_callback.py
tests/python_package_test/test_callback.py
+1
-1
tests/python_package_test/test_dask.py
tests/python_package_test/test_dask.py
+2
-2
tests/python_package_test/test_engine.py
tests/python_package_test/test_engine.py
+1
-1
tests/python_package_test/test_sklearn.py
tests/python_package_test/test_sklearn.py
+10
-0
No files found.
.ci/test.sh
View file @
02d212b4
...
@@ -76,13 +76,16 @@ if [[ $TASK == "lint" ]]; then
...
@@ -76,13 +76,16 @@ if [[ $TASK == "lint" ]]; then
conda
install
-q
-y
-n
$CONDA_ENV
\
conda
install
-q
-y
-n
$CONDA_ENV
\
cmakelint
\
cmakelint
\
cpplint
\
cpplint
\
flake8
\
isort
\
isort
\
mypy
\
mypy
\
pycodestyle
\
pydocstyle
\
pydocstyle
\
"r-lintr>=3.0"
"r-lintr>=3.0"
echo
"Linting Python code"
echo
"Linting Python code"
pycodestyle
--ignore
=
E501,W503
--exclude
=
./.nuget,./external_libs
.
||
exit
-1
flake8
\
--ignore
=
E501,W503
\
--exclude
=
./.nuget,./external_libs,./python-package/build
\
.
||
exit
-1
pydocstyle
--convention
=
numpy
--add-ignore
=
D105
--match-dir
=
"^(?!^external_libs|test|example).*"
--match
=
"(?!^test_|setup).*
\.
py"
.
||
exit
-1
pydocstyle
--convention
=
numpy
--add-ignore
=
D105
--match-dir
=
"^(?!^external_libs|test|example).*"
--match
=
"(?!^test_|setup).*
\.
py"
.
||
exit
-1
isort
.
--check-only
||
exit
-1
isort
.
--check-only
||
exit
-1
mypy
--ignore-missing-imports
python-package/
||
true
mypy
--ignore-missing-imports
python-package/
||
true
...
...
docs/conf.py
View file @
02d212b4
...
@@ -105,7 +105,7 @@ autodoc_mock_imports = [
...
@@ -105,7 +105,7 @@ autodoc_mock_imports = [
'scipy.sparse'
,
'scipy.sparse'
,
]
]
try
:
try
:
import
sklearn
import
sklearn
# noqa: F401
except
ImportError
:
except
ImportError
:
autodoc_mock_imports
.
append
(
'sklearn'
)
autodoc_mock_imports
.
append
(
'sklearn'
)
# hide type hints in API docs
# hide type hints in API docs
...
...
python-package/lightgbm/compat.py
View file @
02d212b4
...
@@ -36,14 +36,14 @@ except ImportError:
...
@@ -36,14 +36,14 @@ except ImportError:
"""matplotlib"""
"""matplotlib"""
try
:
try
:
import
matplotlib
import
matplotlib
# noqa: F401
MATPLOTLIB_INSTALLED
=
True
MATPLOTLIB_INSTALLED
=
True
except
ImportError
:
except
ImportError
:
MATPLOTLIB_INSTALLED
=
False
MATPLOTLIB_INSTALLED
=
False
"""graphviz"""
"""graphviz"""
try
:
try
:
import
graphviz
import
graphviz
# noqa: F401
GRAPHVIZ_INSTALLED
=
True
GRAPHVIZ_INSTALLED
=
True
except
ImportError
:
except
ImportError
:
GRAPHVIZ_INSTALLED
=
False
GRAPHVIZ_INSTALLED
=
False
...
...
python-package/setup.py
View file @
02d212b4
...
@@ -96,7 +96,7 @@ def silent_call(cmd: List[str], raise_error: bool = False, error_msg: str = '')
...
@@ -96,7 +96,7 @@ def silent_call(cmd: List[str], raise_error: bool = False, error_msg: str = '')
with
open
(
LOG_PATH
,
"ab"
)
as
log
:
with
open
(
LOG_PATH
,
"ab"
)
as
log
:
subprocess
.
check_call
(
cmd
,
stderr
=
log
,
stdout
=
log
)
subprocess
.
check_call
(
cmd
,
stderr
=
log
,
stdout
=
log
)
return
0
return
0
except
Exception
as
err
:
except
Exception
:
if
raise_error
:
if
raise_error
:
raise
Exception
(
"
\n
"
.
join
((
error_msg
,
LOG_NOTICE
)))
raise
Exception
(
"
\n
"
.
join
((
error_msg
,
LOG_NOTICE
)))
return
1
return
1
...
...
tests/python_package_test/test_callback.py
View file @
02d212b4
...
@@ -3,7 +3,7 @@ import pytest
...
@@ -3,7 +3,7 @@ import pytest
import
lightgbm
as
lgb
import
lightgbm
as
lgb
from
.utils
import
SERIALIZERS
,
pickle_and_unpickle_object
,
pickle_obj
,
unpickle_obj
from
.utils
import
SERIALIZERS
,
pickle_and_unpickle_object
def
reset_feature_fraction
(
boosting_round
):
def
reset_feature_fraction
(
boosting_round
):
...
...
tests/python_package_test/test_dask.py
View file @
02d212b4
...
@@ -1723,7 +1723,7 @@ def test_dask_methods_and_sklearn_equivalents_have_similar_signatures(methods):
...
@@ -1723,7 +1723,7 @@ def test_dask_methods_and_sklearn_equivalents_have_similar_signatures(methods):
@
pytest
.
mark
.
parametrize
(
'task'
,
tasks
)
@
pytest
.
mark
.
parametrize
(
'task'
,
tasks
)
def
test_training_succeeds_when_data_is_dataframe_and_label_is_column_array
(
task
,
cluster
):
def
test_training_succeeds_when_data_is_dataframe_and_label_is_column_array
(
task
,
cluster
):
with
Client
(
cluster
)
as
client
:
with
Client
(
cluster
):
_
,
_
,
_
,
_
,
dX
,
dy
,
dw
,
dg
=
_create_data
(
_
,
_
,
_
,
_
,
dX
,
dy
,
dw
,
dg
=
_create_data
(
objective
=
task
,
objective
=
task
,
output
=
'dataframe'
,
output
=
'dataframe'
,
...
@@ -1802,7 +1802,7 @@ def _tested_estimators():
...
@@ -1802,7 +1802,7 @@ def _tested_estimators():
@
pytest
.
mark
.
parametrize
(
"estimator"
,
_tested_estimators
())
@
pytest
.
mark
.
parametrize
(
"estimator"
,
_tested_estimators
())
@
pytest
.
mark
.
parametrize
(
"check"
,
sklearn_checks_to_run
())
@
pytest
.
mark
.
parametrize
(
"check"
,
sklearn_checks_to_run
())
def
test_sklearn_integration
(
estimator
,
check
,
cluster
):
def
test_sklearn_integration
(
estimator
,
check
,
cluster
):
with
Client
(
cluster
)
as
client
:
with
Client
(
cluster
):
estimator
.
set_params
(
local_listen_port
=
18000
,
time_out
=
5
)
estimator
.
set_params
(
local_listen_port
=
18000
,
time_out
=
5
)
name
=
type
(
estimator
).
__name__
name
=
type
(
estimator
).
__name__
check
(
name
,
estimator
)
check
(
name
,
estimator
)
...
...
tests/python_package_test/test_engine.py
View file @
02d212b4
...
@@ -2903,7 +2903,7 @@ def test_forced_split_feature_indices(tmp_path):
...
@@ -2903,7 +2903,7 @@ def test_forced_split_feature_indices(tmp_path):
"forcedsplits_filename"
:
tmp_split_file
"forcedsplits_filename"
:
tmp_split_file
}
}
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Forced splits file includes feature index"
):
with
pytest
.
raises
(
lgb
.
basic
.
LightGBMError
,
match
=
"Forced splits file includes feature index"
):
bst
=
lgb
.
train
(
params
,
lgb_train
)
lgb
.
train
(
params
,
lgb_train
)
def
test_forced_bins
():
def
test_forced_bins
():
...
...
tests/python_package_test/test_sklearn.py
View file @
02d212b4
...
@@ -445,9 +445,19 @@ def test_clone_and_property():
...
@@ -445,9 +445,19 @@ def test_clone_and_property():
gbm
.
fit
(
X
,
y
)
gbm
.
fit
(
X
,
y
)
gbm_clone
=
clone
(
gbm
)
gbm_clone
=
clone
(
gbm
)
# original estimator is unaffected
assert
gbm
.
n_estimators
==
10
assert
gbm
.
verbose
==
-
1
assert
isinstance
(
gbm
.
booster_
,
lgb
.
Booster
)
assert
isinstance
(
gbm
.
booster_
,
lgb
.
Booster
)
assert
isinstance
(
gbm
.
feature_importances_
,
np
.
ndarray
)
assert
isinstance
(
gbm
.
feature_importances_
,
np
.
ndarray
)
# new estimator is unfitted, but has the same parameters
assert
gbm_clone
.
__sklearn_is_fitted__
()
is
False
assert
gbm_clone
.
n_estimators
==
10
assert
gbm_clone
.
verbose
==
-
1
assert
gbm_clone
.
get_params
()
==
gbm
.
get_params
()
X
,
y
=
load_digits
(
n_class
=
2
,
return_X_y
=
True
)
X
,
y
=
load_digits
(
n_class
=
2
,
return_X_y
=
True
)
clf
=
lgb
.
LGBMClassifier
(
n_estimators
=
10
,
verbose
=-
1
)
clf
=
lgb
.
LGBMClassifier
(
n_estimators
=
10
,
verbose
=-
1
)
clf
.
fit
(
X
,
y
)
clf
.
fit
(
X
,
y
)
...
...
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