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