Fix pylint errors. (#7967)

This commit is contained in:
Jiaming Yuan 2022-06-02 18:04:46 +08:00 committed by GitHub
parent 13b15e07e8
commit 6b55150e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 10 deletions

View File

@ -96,7 +96,7 @@ class BuildExt(build_ext.build_ext): # pylint: disable=too-many-ancestors
logger = logging.getLogger('XGBoost build_ext') logger = logging.getLogger('XGBoost build_ext')
# pylint: disable=too-many-arguments,no-self-use # pylint: disable=too-many-arguments
def build( def build(
self, self,
src_dir: str, src_dir: str,

View File

@ -1,5 +1,5 @@
# coding: utf-8 # coding: utf-8
# pylint: disable=invalid-name, too-many-statements, no-self-use # pylint: disable=invalid-name, too-many-statements
# pylint: disable=too-many-arguments # pylint: disable=too-many-arguments
"""Callback library containing training routines. See :doc:`Callback Functions """Callback library containing training routines. See :doc:`Callback Functions
</python/callbacks>` for a quick introduction. </python/callbacks>` for a quick introduction.

View File

@ -3,6 +3,7 @@
"""Core XGBoost Library.""" """Core XGBoost Library."""
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections.abc import Mapping from collections.abc import Mapping
import copy
from typing import List, Optional, Any, Union, Dict, TypeVar from typing import List, Optional, Any, Union, Dict, TypeVar
from typing import Callable, Tuple, cast, Sequence, Type, Iterable from typing import Callable, Tuple, cast, Sequence, Type, Iterable
import ctypes import ctypes
@ -1638,7 +1639,7 @@ class Booster:
booster: `Booster` booster: `Booster`
a copied booster model a copied booster model
""" """
return self.__copy__() return copy.copy(self)
def attr(self, key: str) -> Optional[str]: def attr(self, key: str) -> Optional[str]:
"""Get attribute string from the Booster. """Get attribute string from the Booster.
@ -2370,15 +2371,15 @@ class Booster:
ret = self.get_dump(fmap, with_stats, dump_format) ret = self.get_dump(fmap, with_stats, dump_format)
if dump_format == 'json': if dump_format == 'json':
fout_obj.write('[\n') fout_obj.write('[\n')
for i, _ in enumerate(ret): for i, val in enumerate(ret):
fout_obj.write(ret[i]) fout_obj.write(val)
if i < len(ret) - 1: if i < len(ret) - 1:
fout_obj.write(",\n") fout_obj.write(",\n")
fout_obj.write('\n]') fout_obj.write('\n]')
else: else:
for i, _ in enumerate(ret): for i, val in enumerate(ret):
fout_obj.write(f"booster[{i}]:\n") fout_obj.write(f"booster[{i}]:\n")
fout_obj.write(ret[i]) fout_obj.write(val)
if need_close: if need_close:
fout_obj.close() fout_obj.close()
@ -2667,8 +2668,8 @@ class Booster:
values = [] values = []
# pylint: disable=consider-using-f-string # pylint: disable=consider-using-f-string
regexp = re.compile(r"\[{0}<([\d.Ee+-]+)\]".format(feature)) regexp = re.compile(r"\[{0}<([\d.Ee+-]+)\]".format(feature))
for i, _ in enumerate(xgdump): for i, val in enumerate(xgdump):
m = re.findall(regexp, xgdump[i]) m = re.findall(regexp, val)
values.extend([float(x) for x in m]) values.extend([float(x) for x in m])
n_unique = len(np.unique(values)) n_unique = len(np.unique(values))

View File

@ -1719,7 +1719,7 @@ class DaskScikitLearnBase(XGBModel):
"""Implementation of the Scikit-Learn API for XGBoost.""", ["estimators", "model"] """Implementation of the Scikit-Learn API for XGBoost.""", ["estimators", "model"]
) )
class DaskXGBRegressor(DaskScikitLearnBase, XGBRegressorBase): class DaskXGBRegressor(DaskScikitLearnBase, XGBRegressorBase):
# pylint: disable=missing-class-docstring """dummy doc string to workaround pylint, replaced by the decorator."""
async def _fit_async( async def _fit_async(
self, self,
X: _DaskCollection, X: _DaskCollection,