Merge branch 'master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / python-science.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
4 ;;; Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2016, 2017, 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
8 ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
9 ;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
10 ;;; Copyright © 2019 Giacomo Leidi <goodoldpaul@autistici.org>
11 ;;;
12 ;;; This file is part of GNU Guix.
13 ;;;
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
18 ;;;
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27 (define-module (gnu packages python-science)
28 #:use-module ((guix licenses) #:prefix license:)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages base)
31 #:use-module (gnu packages check)
32 #:use-module (gnu packages gcc)
33 #:use-module (gnu packages maths)
34 #:use-module (gnu packages perl)
35 #:use-module (gnu packages python)
36 #:use-module (gnu packages python-web)
37 #:use-module (gnu packages python-xyz)
38 #:use-module (gnu packages sphinx)
39 #:use-module (gnu packages time)
40 #:use-module (gnu packages xml)
41 #:use-module (guix packages)
42 #:use-module (guix download)
43 #:use-module (guix utils)
44 #:use-module (guix build-system python))
45
46 (define-public python-scipy
47 (package
48 (name "python-scipy")
49 (version "1.3.2")
50 (source
51 (origin
52 (method url-fetch)
53 (uri (pypi-uri "scipy" version))
54 (sha256
55 (base32 "192d8dsybvhv19igkrsafbdafx198nz7pibkjgrqjhlr66s3jfd0"))))
56 (build-system python-build-system)
57 (propagated-inputs
58 `(("python-numpy" ,python-numpy)
59 ("python-matplotlib" ,python-matplotlib)
60 ("python-pyparsing" ,python-pyparsing)))
61 (inputs
62 `(("lapack" ,lapack)
63 ("openblas" ,openblas)))
64 (native-inputs
65 `(("python-cython" ,python-cython)
66 ("python-pytest" ,python-pytest)
67 ("python-sphinx" ,python-sphinx)
68 ("python-numpydoc" ,python-numpydoc)
69 ("gfortran" ,gfortran)
70 ("perl" ,perl)
71 ("which" ,which)))
72 (outputs '("out" "doc"))
73 (arguments
74 `(#:phases
75 (modify-phases %standard-phases
76 (add-after 'unpack 'disable-broken-tests
77 (lambda _
78 (substitute* "scipy/sparse/linalg/dsolve/tests/test_linsolve.py"
79 (("^( +)def test_threads_parallel\\(self\\):" m indent)
80 (string-append indent
81 "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
82 m)))
83 (substitute* "scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py"
84 (("^def test_parallel_threads\\(\\):" m)
85 (string-append "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
86 m)))
87 #t))
88 (add-before 'build 'configure-openblas
89 (lambda* (#:key inputs #:allow-other-keys)
90 (call-with-output-file "site.cfg"
91 (lambda (port)
92 (format port
93 "[blas]
94 libraries = openblas
95 library_dirs = ~a/lib
96 include_dirs = ~a/include
97
98 # backslash-n to make emacs happy
99 \n[atlas]
100 library_dirs = ~a/lib
101 atlas_libs = openblas
102 "
103 (assoc-ref inputs "openblas")
104 (assoc-ref inputs "openblas")
105 (assoc-ref inputs "openblas"))))
106 #t))
107 (add-after 'install 'install-doc
108 (lambda* (#:key inputs outputs #:allow-other-keys)
109 (let* ((data (string-append (assoc-ref outputs "doc") "/share"))
110 (doc (string-append data "/doc/" ,name "-" ,version))
111 (html (string-append doc "/html"))
112 (pyver ,(string-append "PYVER=" (version-major+minor
113 (package-version python))))
114 ;; By default it tries to run sphinx-build through the Python
115 ;; interpreter which won't work with our shell wrapper.
116 (sphinxbuild "SPHINXBUILD=LANG=C sphinx-build"))
117 ;; Make installed package available for building the
118 ;; documentation
119 (add-installed-pythonpath inputs outputs)
120 (with-directory-excursion "doc"
121 ;; Fix generation of images for mathematical expressions.
122 (substitute* (find-files "source" "conf\\.py")
123 (("pngmath_use_preview = True")
124 "pngmath_use_preview = False"))
125 (mkdir-p html)
126 (invoke "make" "html" pyver sphinxbuild)
127 (with-directory-excursion "build/html"
128 (for-each (lambda (file)
129 (let* ((dir (dirname file))
130 (tgt-dir (string-append html "/" dir)))
131 (install-file file html)))
132 (find-files "." ".*")))))
133 #t))
134 ;; Tests can only be run after the library has been installed and not
135 ;; within the source directory.
136 (delete 'check)
137 (add-after 'install 'check
138 (lambda* (#:key inputs outputs #:allow-other-keys)
139 (add-installed-pythonpath inputs outputs)
140 (with-directory-excursion "/tmp"
141 (invoke "python" "-c"
142 "import scipy; scipy.test(verbose=2)")))))))
143 (home-page "https://www.scipy.org/")
144 (synopsis "The Scipy library provides efficient numerical routines")
145 (description "The SciPy library is one of the core packages that make up
146 the SciPy stack. It provides many user-friendly and efficient numerical
147 routines such as routines for numerical integration and optimization.")
148 (properties `((python2-variant . ,(delay python2-scipy))))
149 (license license:bsd-3)))
150
151 ;; Version 1.2.2 is the last version to support Python 2
152 (define-public python2-scipy
153 (package
154 (inherit (package-with-python2
155 (strip-python2-variant python-scipy)))
156 (version "1.2.2")
157 (source
158 (origin
159 (method url-fetch)
160 (uri (pypi-uri "scipy" version))
161 (sha256
162 (base32
163 "1cgvgin8fvckv96hjh3ikmwkra5rif51bdb75ifzf7xbil5iwcx4"))))))
164
165 (define-public python-scikit-image
166 (package
167 (name "python-scikit-image")
168 (version "0.14.2")
169 (source
170 (origin
171 (method url-fetch)
172 (uri (pypi-uri "scikit-image" version))
173 (sha256
174 (base32 "07qchljkyxvg5nrm12fvszi7pmjk4m01qp0w0z8syxzxxs20pz8s"))))
175 (build-system python-build-system)
176 (arguments
177 ;; TODO: Some tests require running X11 server. Disable them?
178 '(#:tests? #f))
179 ;; See DEPENDS.txt for the list of build and run time requiremnts
180 (propagated-inputs
181 `(("python-cloudpickle" ,python-cloudpickle)
182 ("python-dask" ,python-dask)
183 ("python-matplotlib" ,python-matplotlib)
184 ("python-networkx" ,python-networkx)
185 ("python-numpy" ,python-numpy)
186 ("python-pillow" ,python-pillow)
187 ("python-pywavelets" ,python-pywavelets)
188 ("python-scipy" ,python-scipy)
189 ("python-six" ,python-six)))
190 (native-inputs
191 `(("python-cython" ,python-cython)))
192 (home-page "https://scikit-image.org/")
193 (synopsis "Image processing in Python")
194 (description
195 "Scikit-image is a collection of algorithms for image processing.")
196 (license license:bsd-3)))
197
198 (define-public python-pandas
199 (package
200 (name "python-pandas")
201 (version "0.25.2")
202 (source
203 (origin
204 (method url-fetch)
205 (uri (pypi-uri "pandas" version))
206 (sha256
207 (base32 "1gp2pvzdiakvgjmykdzdlzrsfbg4vjm49jjdl9s0ha0a3yfs34fa"))))
208 (build-system python-build-system)
209 (arguments
210 `(#:modules ((guix build utils)
211 (guix build python-build-system)
212 (ice-9 ftw)
213 (srfi srfi-26))
214 #:phases (modify-phases %standard-phases
215 (add-after 'unpack 'patch-which
216 (lambda* (#:key inputs #:allow-other-keys)
217 (let ((which (assoc-ref inputs "which")))
218 (substitute* "pandas/io/clipboard/__init__.py"
219 (("^CHECK_CMD = .*")
220 (string-append "CHECK_CMD = \"" which "\"\n"))))
221 #t))
222 (replace 'check
223 (lambda _
224 (let ((build-directory
225 (string-append
226 (getcwd) "/build/"
227 (car (scandir "build"
228 (cut string-prefix? "lib." <>))))))
229 ;; Disable the "strict data files" option which causes
230 ;; the build to error out if required data files are
231 ;; not available (as is the case with PyPI archives).
232 (substitute* "setup.cfg"
233 (("addopts = --strict-data-files") "addopts = "))
234 (with-directory-excursion build-directory
235 ;; Delete tests that require "moto" which is not yet
236 ;; in Guix.
237 (for-each delete-file
238 '("pandas/tests/io/conftest.py"
239 "pandas/tests/io/json/test_compression.py"
240 "pandas/tests/io/parser/test_network.py"
241 "pandas/tests/io/test_parquet.py"))
242 (invoke "pytest" "-vv" "pandas" "--skip-slow"
243 "--skip-network" "-k"
244 ;; XXX: Due to the deleted tests above.
245 "not test_read_s3_jsonl"))))))))
246 (propagated-inputs
247 `(("python-numpy" ,python-numpy)
248 ("python-openpyxl" ,python-openpyxl)
249 ("python-pytz" ,python-pytz)
250 ("python-dateutil" ,python-dateutil)
251 ("python-xlrd" ,python-xlrd)))
252 (inputs
253 `(("which" ,which)))
254 (native-inputs
255 `(("python-cython" ,python-cython)
256 ("python-beautifulsoup4" ,python-beautifulsoup4)
257 ("python-lxml" ,python-lxml)
258 ("python-html5lib" ,python-html5lib)
259 ("python-nose" ,python-nose)
260 ("python-pytest" ,python-pytest)
261 ("python-pytest-mock" ,python-pytest-mock)))
262 (home-page "https://pandas.pydata.org")
263 (synopsis "Data structures for data analysis, time series, and statistics")
264 (description
265 "Pandas is a Python package providing fast, flexible, and expressive data
266 structures designed to make working with structured (tabular,
267 multidimensional, potentially heterogeneous) and time series data both easy
268 and intuitive. It aims to be the fundamental high-level building block for
269 doing practical, real world data analysis in Python.")
270 (properties `((python2-variant . ,(delay python2-pandas))))
271 (license license:bsd-3)))
272
273 ;; Pandas 0.24.x are the last versions that support Python 2.
274 (define-public python2-pandas
275 (let ((pandas (package-with-python2
276 (strip-python2-variant python-pandas))))
277 (package
278 (inherit pandas)
279 (version "0.24.2")
280 (source (origin
281 (method url-fetch)
282 (uri (pypi-uri "pandas" version))
283 (sha256
284 (base32
285 "18imlm8xbhcbwy4wa957a1fkamrcb0z988z006jpfda3ki09z4ag"))
286 (modules '((guix build utils)))
287 (snippet
288 '(begin
289 ;; Adjust for renamed error message in Python 2.7.17. Taken
290 ;; from <https://github.com/pandas-dev/pandas/pull/29294>.
291 (substitute* "pandas/io/parsers.py"
292 (("if 'NULL byte' in msg:")
293 "if 'NULL byte' in msg or 'line contains NUL' in msg:"))
294 #t)))))))