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 __structuredAttrs = true;
27
28 pname = "scikit-learn";
29 version = "1.7.1";
30 pyproject = true;
31
32 disabled = pythonOlder "3.9";
33
34 src = fetchPypi {
35 pname = "scikit_learn";
36 inherit version;
37 hash = "sha256-JLPx6XakZlqnTuD8qsK4/Mxq53yOB6sl2jum0ykrmAI=";
38 };
39
40 postPatch = ''
41 substituteInPlace meson.build --replace-fail \
42 "run_command('sklearn/_build_utils/version.py', check: true).stdout().strip()," \
43 "'${version}',"
44 substituteInPlace pyproject.toml \
45 --replace-fail "numpy>=2,<2.3.0" numpy \
46 --replace-fail "scipy>=1.8.0,<1.16.0" scipy
47 '';
48
49 buildInputs = [
50 numpy.blas
51 pillow
52 glibcLocales
53 ]
54 ++ lib.optionals stdenv.cc.isClang [ llvmPackages.openmp ];
55
56 nativeBuildInputs = [
57 gfortran
58 ];
59
60 build-system = [
61 cython
62 meson-python
63 numpy
64 scipy
65 ];
66
67 dependencies = [
68 joblib
69 numpy
70 scipy
71 threadpoolctl
72 ];
73
74 pythonRelaxDeps = [
75 "numpy"
76 "scipy"
77 ];
78
79 nativeCheckInputs = [
80 pytestCheckHook
81 pytest-xdist
82 ];
83
84 env.LC_ALL = "en_US.UTF-8";
85
86 # PermissionError: [Errno 1] Operation not permitted: '/nix/nix-installer'
87 doCheck = !stdenv.hostPlatform.isDarwin;
88
89 disabledTests = [
90 # Skip test_feature_importance_regression - does web fetch
91 "test_feature_importance_regression"
92
93 # Fail due to new deprecation warnings in scipy
94 # FIXME: reenable when fixed upstream
95 "test_logistic_regression_path_convergence_fail"
96 "test_linalg_warning_with_newton_solver"
97 "test_newton_cholesky_fallback_to_lbfgs"
98
99 # NuSVC memmap tests causes segmentation faults in certain environments
100 # (e.g. Hydra Darwin machines) related to a long-standing joblib issue
101 # (https://github.com/joblib/joblib/issues/563). See also:
102 # https://github.com/scikit-learn/scikit-learn/issues/17582
103 "NuSVC and memmap"
104 ]
105 ++ lib.optionals stdenv.hostPlatform.isAarch64 [
106 # doesn't seem to produce correct results?
107 # possibly relevant: https://github.com/scikit-learn/scikit-learn/issues/25838#issuecomment-2308650816
108 "test_sparse_input"
109 ];
110
111 pytestFlags = [
112 # verbose build outputs needed to debug hard-to-reproduce hydra failures
113 "-v"
114 "--pyargs"
115 "sklearn"
116 ];
117
118 preCheck = ''
119 cd $TMPDIR
120 export HOME=$TMPDIR
121 export OMP_NUM_THREADS=1
122 '';
123
124 pythonImportsCheck = [ "sklearn" ];
125
126 meta = {
127 description = "Set of python modules for machine learning and data mining";
128 changelog =
129 let
130 major = lib.versions.major version;
131 minor = lib.versions.minor version;
132 dashVer = lib.replaceStrings [ "." ] [ "-" ] version;
133 in
134 "https://scikit-learn.org/stable/whats_new/v${major}.${minor}.html#version-${dashVer}";
135 homepage = "https://scikit-learn.org";
136 license = lib.licenses.bsd3;
137 maintainers = with lib.maintainers; [ davhau ];
138 };
139}