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