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