1{
2 stdenv,
3 lib,
4 buildPythonPackage,
5 fetchPypi,
6
7 # build-system
8 cython,
9 gfortran,
10 meson-python,
11 numpy,
12 scipy,
13
14 # native dependencies
15 glibcLocales,
16 llvmPackages,
17 pytestCheckHook,
18 pytest-xdist,
19 pillow,
20 joblib,
21 threadpoolctl,
22 pythonOlder,
23}:
24
25buildPythonPackage rec {
26 pname = "scikit-learn";
27 version = "1.5.0";
28 pyproject = true;
29
30 disabled = pythonOlder "3.9";
31
32 src = fetchPypi {
33 pname = "scikit_learn";
34 inherit version;
35 hash = "sha256-eJ49sBx1DtbUlvott9UGN4V7RR5XvK6GO/9wfBJHvvc=";
36 };
37
38 postPatch = ''
39 substituteInPlace pyproject.toml \
40 --replace-fail "numpy>=2.0.0rc2" "numpy"
41
42 substituteInPlace meson.build --replace-fail \
43 "run_command('sklearn/_build_utils/version.py', check: true).stdout().strip()," \
44 "'${version}',"
45 '';
46
47 buildInputs = [
48 numpy.blas
49 pillow
50 glibcLocales
51 ] ++ lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ];
52
53 nativeBuildInputs = [
54 gfortran
55 ];
56
57 build-system = [
58 cython
59 meson-python
60 numpy
61 scipy
62 ];
63
64 dependencies = [
65 joblib
66 numpy
67 scipy
68 threadpoolctl
69 ];
70
71 nativeCheckInputs = [
72 pytestCheckHook
73 pytest-xdist
74 ];
75
76 env.LC_ALL = "en_US.UTF-8";
77
78 preBuild = ''
79 export SKLEARN_BUILD_PARALLEL=$NIX_BUILD_CORES
80 '';
81
82 # PermissionError: [Errno 1] Operation not permitted: '/nix/nix-installer'
83 doCheck = !stdenv.isDarwin;
84
85 disabledTests = [
86 # Skip test_feature_importance_regression - does web fetch
87 "test_feature_importance_regression"
88 ];
89
90 pytestFlagsArray = [
91 # verbose build outputs needed to debug hard-to-reproduce hydra failures
92 "-v"
93 "--pyargs"
94 "sklearn"
95
96 # NuSVC memmap tests causes segmentation faults in certain environments
97 # (e.g. Hydra Darwin machines) related to a long-standing joblib issue
98 # (https://github.com/joblib/joblib/issues/563). See also:
99 # https://github.com/scikit-learn/scikit-learn/issues/17582
100 # Since we are overriding '-k' we need to include the 'disabledTests' from above manually.
101 "-k"
102 "'not (NuSVC and memmap) ${toString (lib.forEach disabledTests (t: "and not ${t}"))}'"
103 ];
104
105 preCheck = ''
106 cd $TMPDIR
107 export HOME=$TMPDIR
108 export OMP_NUM_THREADS=1
109 '';
110
111 pythonImportsCheck = [ "sklearn" ];
112
113 meta = with lib; {
114 description = "Set of python modules for machine learning and data mining";
115 changelog =
116 let
117 major = versions.major version;
118 minor = versions.minor version;
119 dashVer = replaceStrings [ "." ] [ "-" ] version;
120 in
121 "https://scikit-learn.org/stable/whats_new/v${major}.${minor}.html#version-${dashVer}";
122 homepage = "https://scikit-learn.org";
123 license = licenses.bsd3;
124 maintainers = with maintainers; [ davhau ];
125 };
126}