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