1{ stdenv
2, lib
3, buildPythonPackage
4, fetchPypi
5, fetchpatch
6, gfortran
7, glibcLocales
8, numpy
9, scipy
10, pytestCheckHook
11, pytest-xdist
12, pillow
13, cython
14, joblib
15, llvmPackages
16, threadpoolctl
17, pythonOlder
18}:
19
20buildPythonPackage rec {
21 pname = "scikit-learn";
22 version = "0.24.1";
23 disabled = pythonOlder "3.6";
24
25 src = fetchPypi {
26 inherit pname version;
27 sha256 = "oDNKGALmTWVgIsO/q1anP71r9LEpg0PzaIryFRgQu98=";
28 };
29
30 patches = [
31 # This patch fixes compatibility with numpy 1.20. It was merged before 0.24.1 was released,
32 # but for some reason was not included in the 0.24.1 release tarball.
33 (fetchpatch {
34 url = "https://github.com/scikit-learn/scikit-learn/commit/e7ef22c3ba2334cb3b476e95d7c083cf6b48ce56.patch";
35 sha256 = "174554k1pbf92bj7wgq0xjj16bkib32ailyhwavdxaknh4bd9nmv";
36 })
37 ];
38
39 buildInputs = [
40 pillow
41 glibcLocales
42 ] ++ lib.optionals stdenv.cc.isClang [
43 llvmPackages.openmp
44 ];
45
46 nativeBuildInputs = [
47 cython
48 gfortran
49 ];
50
51 propagatedBuildInputs = [
52 numpy
53 scipy
54 numpy.blas
55 joblib
56 threadpoolctl
57 ];
58
59 checkInputs = [ pytestCheckHook pytest-xdist ];
60
61 LC_ALL="en_US.UTF-8";
62
63 preBuild = ''
64 export SKLEARN_BUILD_PARALLEL=$NIX_BUILD_CORES
65 '';
66
67 doCheck = !stdenv.isAarch64;
68
69 disabledTests = [
70 # Skip test_feature_importance_regression - does web fetch
71 "test_feature_importance_regression"
72
73 # failing on macos
74 "check_regressors_train"
75 "check_classifiers_train"
76 "xfail_ignored_in_check_estimator"
77 ];
78
79 pytestFlagsArray = [
80 # verbose build outputs needed to debug hard-to-reproduce hydra failures
81 "-v"
82 "--pyargs" "sklearn"
83
84 # NuSVC memmap tests causes segmentation faults in certain environments
85 # (e.g. Hydra Darwin machines) related to a long-standing joblib issue
86 # (https://github.com/joblib/joblib/issues/563). See also:
87 # https://github.com/scikit-learn/scikit-learn/issues/17582
88 # Since we are overriding '-k' we need to include the 'disabledTests' from above manually.
89 "-k" "'not (NuSVC and memmap) ${toString (lib.forEach disabledTests (t: "and not ${t}"))}'"
90
91 "-n" "$NIX_BUILD_CORES"
92 ];
93
94 preCheck = ''
95 cd $TMPDIR
96 export HOME=$TMPDIR
97 export OMP_NUM_THREADS=1
98 '';
99
100 pythonImportsCheck = [ "sklearn" ];
101
102 meta = with lib; {
103 description = "A set of python modules for machine learning and data mining";
104 changelog = let
105 major = versions.major version;
106 minor = versions.minor version;
107 dashVer = replaceChars ["."] ["-"] version;
108 in
109 "https://scikit-learn.org/stable/whats_new/v${major}.${minor}.html#version-${dashVer}";
110 homepage = "https://scikit-learn.org";
111 license = licenses.bsd3;
112 maintainers = with maintainers; [ davhau ];
113 };
114}