diff mbox series

[bug#48388,3/3] gnu: Add python-xgboost.

Message ID 20210512235844.516970-3-monego@posteo.net
State Accepted
Headers show
Series Add xgboost. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Vinicius Monego May 12, 2021, 11:58 p.m. UTC
* gnu/packages/machine-learning.scm (python-xgboost): New variable.
---
 gnu/packages/machine-learning.scm | 60 +++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
diff mbox series

Patch

diff --git a/gnu/packages/machine-learning.scm b/gnu/packages/machine-learning.scm
index fd10de427f..f7bb01f274 100644
--- a/gnu/packages/machine-learning.scm
+++ b/gnu/packages/machine-learning.scm
@@ -1992,6 +1992,66 @@  tree boosting (also known as GBDT, GBM) that solve many data science problems
 in a fast and accurate way.")
     (license license:asl2.0)))
 
+(define-public python-xgboost
+  (package
+    (inherit xgboost)
+    (name "python-xgboost")
+    (build-system python-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'preparations
+           (lambda* (#:key inputs #:allow-other-keys)
+             ;; Move python-package content to parent directory to silence
+             ;; some warnings about files not being found if we chdir.
+             (rename-file "python-package/xgboost" "xgboost")
+             (rename-file "python-package/README.rst" "README.rst")
+             (rename-file "python-package/setup.cfg" "setup.cfg")
+             (rename-file "python-package/setup.py" "setup.py")
+
+             (with-directory-excursion "xgboost"
+               ;; Version is read from a VERSION file, but that file is not
+               ;; part of the installation.
+               (substitute* "__init__.py"
+                 (("__version__ = ''")
+                  (string-append "__version__ = " "'"
+                                 ,(package-version xgboost) "'")))
+               ;; The Python wrapper expects libxgboost to be found in the
+               ;; same source from where the wrapper builds.  This workaround
+               ;; allows libxgboost to be used from the xgboost package.
+               (substitute* "libpath.py"
+                 (("XGBOOST_PATH = ''")
+                  (string-append "XGBOOST_PATH = "
+                                 "'" (assoc-ref inputs "xgboost") "'"))))
+             #t))
+         (replace 'check
+           ;; Python-specific tests are located in tests/python.
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (add-installed-pythonpath inputs outputs)
+             (invoke "pytest" "tests/python"
+                     ;; FIXME: CLI tests fail with PermissionError.
+                     "--ignore" "tests/python/test_cli.py" "-k"
+                     (string-append
+                      "not test_cli_regression_demo"
+                      ;; The tests below open a network connection.
+                      " and not test_model_compatibility"
+                      " and not test_get_group"
+                      " and not test_cv_no_shuffle"
+                      " and not test_cv"
+                      " and not test_training"
+                      ;; "'['./runexp.sh']' returned non-zero exit status 1."
+                      " and not test_cli_binary_classification")))))))
+    (native-inputs
+     `(("python-pandas" ,python-pandas)
+       ("python-pytest" ,python-pytest)
+       ("python-scikit-learn" ,python-scikit-learn)))
+    (inputs
+     `(("xgboost" ,xgboost)))
+    (propagated-inputs
+     `(("python-numpy" ,python-numpy)
+       ("python-scipy" ,python-scipy)))
+    (synopsis "Python interface for the XGBoost library")))
+
 (define-public python-iml
   (package
     (name "python-iml")