Skip to content
Permalink
Browse files

changes for pylint

  • Loading branch information...
sdpython committed May 12, 2018
1 parent 02dea3a commit 084e6cd06c4bee89f04b48696c4a44ebde3063be
@@ -0,0 +1,11 @@

.. blogpost::
:title: XGBoost into python code
:keywords: xgboost, pyxgboost, python
:date: 2018-04-30
:categories: modules

Package `pyxgboost <https://github.com/KOLANICH/pyxgboost>`_
converts a tree from :epkg:`xgboost` into a :epkg:`Python` code.
:epkg:`Python` still needs to be used if the models
has to be deployed but it should be faster for small models.
@@ -5,6 +5,9 @@


def main():
"""
Runs the unit tests.
"""
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import main_wrapper_tests
fLOG(OutputPrint=True)
@@ -6,6 +6,9 @@
import sys
import os
import unittest
from pyquickhelper.loghelper import fLOG
from pyquickhelper.ipythonhelper import test_notebook_execution_coverage
from pyquickhelper.pycode import add_missing_development_version


try:
@@ -22,25 +25,6 @@
import src


try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..", "..", "pyquickhelper", "src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_


from pyquickhelper.loghelper import fLOG
from pyquickhelper.ipythonhelper import test_notebook_execution_coverage
from pyquickhelper.pycode import add_missing_development_version


class TestFunctionTestNotebook(unittest.TestCase):

def setUp(self):
@@ -3,8 +3,10 @@
"""
import sys
import os
import numpy
import unittest
import numpy
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase


try:
@@ -20,22 +22,7 @@
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..", "..", "pyquickhelper", "src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_


from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase
from src.mlprodict.testing import iris_data, check_model_representation
from src.mlprodict.grammar_sklearn import sklearn2graph, identify_interpreter
from src.mlprodict.cc import compile_c_function
@@ -3,8 +3,10 @@
"""
import sys
import os
import numpy
import unittest
import numpy
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase


try:
@@ -20,22 +22,7 @@
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..", "..", "pyquickhelper", "src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_


from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase
from src.mlprodict.grammar_sklearn import sklearn2graph
from src.mlprodict.grammar.exc import Float32InfError

@@ -5,6 +5,8 @@
import os
import unittest
import numpy
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase


try:
@@ -20,21 +22,6 @@
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..", "..", "pyquickhelper", "src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase
from src.mlprodict.testing import check_model_representation


@@ -5,6 +5,8 @@
import sys
import os
import unittest
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase


try:
@@ -20,21 +22,6 @@
sys.path.append(path)
import src

try:
import pyquickhelper as skip_
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..", "..", "pyquickhelper", "src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper as skip_

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase
from src.mlprodict.testing import iris_data, check_model_representation


@@ -5,8 +5,8 @@
import sys
import os
import unittest
import warnings

from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import check_pep8, ExtTestCase

try:
import src
@@ -22,47 +22,39 @@
import src


from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import check_pep8


class TestCodeStyle(unittest.TestCase):
class TestCodeStyle(ExtTestCase):
"""Test style."""

def test_code_style_src(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

if sys.version_info[0] == 2 or "Anaconda" in sys.executable \
or "condavir" in sys.executable:
warnings.warn(
"skipping test_code_style because of Python 2 or " + sys.executable)
return
def test_src(self):
"skip pylint"
self.assertFalse(src is None)

def test_style_src(self):
thi = os.path.abspath(os.path.dirname(__file__))
src_ = os.path.normpath(os.path.join(thi, "..", "..", "src"))
check_pep8(src_, fLOG=fLOG, ignore=('E501', 'E265', 'E721'))

def test_code_style_test(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

if sys.version_info[0] == 2 or "Anaconda" in sys.executable \
or "condavir" in sys.executable:
warnings.warn(
"skipping test_code_style because of Python 2 or " + sys.executable)
return
check_pep8(src_, fLOG=fLOG,
pylint_ignore=('C0103', 'C1801', 'R0201', 'R1705', 'W0108', 'W0613',
'R1702', 'W0212', 'W0640', 'W0223', 'W0201',
'W0622', 'C0123'),
skip=["Instance of 'tuple' has no ",
"do not compare types, use 'isinstance()'",
"Instance of 'AutoAction' has no 'children' member",
])

def test_style_test(self):
thi = os.path.abspath(os.path.dirname(__file__))
test = os.path.normpath(os.path.join(thi, "..", ))
check_pep8(test, fLOG=fLOG, neg_filter="temp_.*",
check_pep8(test, fLOG=fLOG, neg_pattern="temp_.*",
pylint_ignore=('C0103', 'C1801', 'R0201', 'R1705', 'W0108', 'W0613',
'C0111'),
skip=["src' imported but unused",
"skip_' imported but unused",
"skip__' imported but unused",
"skip___' imported but unused",
"Unused variable 'skip_'",
"imported as skip_",
"Instance of 'tuple' has no ",
"Unused import src",
])


@@ -2,25 +2,8 @@
@brief test log(time=0s)
"""

import sys
import os
import unittest


try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src


from pyquickhelper.loghelper import fLOG
from pyquickhelper.filehelper import explore_folder_iterfile
from pyquickhelper.ipythonhelper import upgrade_notebook, remove_execution_number
@@ -4,8 +4,8 @@
"""
import os
import sys
import numpy
import shutil
import numpy


_header_c_float = """
@@ -88,7 +88,8 @@ def compile_c_function(code_c, nbout, dtype=numpy.float32, add_header=True,
@param add_header add common function before compiling
@param suffix avoid avoid the same compiled module name
@param additional_paths additional paths to add to the module
@param tmpdir see `compile <http://cffi.readthedocs.io/en/latest/cdef.html?highlight=compile#ffibuilder-compile-etc-compiling-out-of-line-modules>`_
@param tmpdir see `compile <http://cffi.readthedocs.io/en/latest/cdef.html?
highlight=compile#ffibuilder-compile-etc-compiling-out-of-line-modules>`_
@param fLOG logging function
@return compiled function
@@ -196,6 +197,7 @@ def compile_c_function(code_c, nbout, dtype=numpy.float32, add_header=True,
fct = getattr(mod.lib, name)

def wrapper(features, output, cast_type, dtype):
"wrapper for a vector of features"
if len(features.shape) != 1:
raise TypeError(
"Only one dimension for the features not {0}.".format(features.shape))
@@ -219,9 +221,11 @@ def wrapper(features, output, cast_type, dtype):
return output

def wrapper_double(features, output=None):
"wrapper for double"
return wrapper(features, output, "double*", numpy.float64)

def wrapper_float(features, output=None):
"wrapper for float"
return wrapper(features, output, "float*", numpy.float32)

return wrapper_float if is_float else wrapper_double
@@ -46,7 +46,10 @@ def export(self, lang="json", hook=None, result_name=None):

@staticmethod
def cache(func):
"""Caches the result of a function."""

def func_wrapper(self, hook=None, result_name=None):
"""Wrapper to cache the result of a function."""
if self._cache is not None:
c = self._cache.copy()
c['cache'] = True
@@ -87,6 +90,6 @@ def format_value(self, value, lang="json", hook=None):
raise TypeError(
"Singature of '{0}' is wrong for type '{1}'".format(name, type(self)))
else:
raise NotImplemented(
raise NotImplementedError(
"No formatting is implemented for lang='{0}' and type='{1}'".format(
lang, type(self)))
@@ -389,8 +389,7 @@ def _export_c(self, hook=None, result_name=None):
dc = MLAction._export_c(self, hook=hook, result_name=result_name)
rows = [dc['code']]
dc2 = self.output._export_c(hook='type')
op = "{2} {0} = {0}0 ? {0}1 : {0}2;".format(
result_name, self.name, dc2['code'])
op = "{1} {0} = {0}0 ? {0}1 : {0}2;".format(result_name, dc2['code'])
rows.append(op)
rows.append("// {0}-{1} - done".format(id(self), self.name))
return {'code': "\n".join(rows), 'result_name': result_name}
Oops, something went wrong.

0 comments on commit 084e6cd

Please sign in to comment.
You can’t perform that action at this time.