gnu: r-fields: Update to 11.4.
[jackhill/guix/guix.git] / gnu / packages / python-science.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2020 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 ;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
12 ;;; Copyright © 2020 Vinicius Monego <monego@posteo.net>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages python-science)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (gnu packages)
32 #:use-module (gnu packages base)
33 #:use-module (gnu packages check)
34 #:use-module (gnu packages gcc)
35 #:use-module (gnu packages maths)
36 #:use-module (gnu packages perl)
37 #:use-module (gnu packages python)
38 #:use-module (gnu packages python-web)
39 #:use-module (gnu packages python-xyz)
40 #:use-module (gnu packages sphinx)
41 #:use-module (gnu packages time)
42 #:use-module (gnu packages xdisorg)
43 #:use-module (gnu packages xml)
44 #:use-module (gnu packages xorg)
45 #:use-module (guix packages)
46 #:use-module (guix download)
47 #:use-module (guix utils)
48 #:use-module (guix build-system python))
49
50 (define-public python-scipy
51 (package
52 (name "python-scipy")
53 (version "1.3.2")
54 (source
55 (origin
56 (method url-fetch)
57 (uri (pypi-uri "scipy" version))
58 (sha256
59 (base32 "192d8dsybvhv19igkrsafbdafx198nz7pibkjgrqjhlr66s3jfd0"))))
60 (build-system python-build-system)
61 (propagated-inputs
62 `(("python-numpy" ,python-numpy)
63 ("python-matplotlib" ,python-matplotlib)
64 ("python-pyparsing" ,python-pyparsing)))
65 (inputs
66 `(("lapack" ,lapack)
67 ("openblas" ,openblas)))
68 (native-inputs
69 `(("python-cython" ,python-cython)
70 ("python-pytest" ,python-pytest)
71 ("python-sphinx" ,python-sphinx)
72 ("python-numpydoc" ,python-numpydoc)
73 ("gfortran" ,gfortran)
74 ("perl" ,perl)
75 ("which" ,which)))
76 (outputs '("out" "doc"))
77 (arguments
78 `(#:phases
79 (modify-phases %standard-phases
80 (add-after 'unpack 'disable-broken-tests
81 (lambda _
82 (substitute* "scipy/sparse/linalg/dsolve/tests/test_linsolve.py"
83 (("^( +)def test_threads_parallel\\(self\\):" m indent)
84 (string-append indent
85 "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
86 m)))
87 (substitute* "scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py"
88 (("^def test_parallel_threads\\(\\):" m)
89 (string-append "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
90 m)))
91 #t))
92 (add-before 'build 'configure-openblas
93 (lambda* (#:key inputs #:allow-other-keys)
94 (call-with-output-file "site.cfg"
95 (lambda (port)
96 (format port
97 "[blas]
98 libraries = openblas
99 library_dirs = ~a/lib
100 include_dirs = ~a/include
101
102 # backslash-n to make emacs happy
103 \n[atlas]
104 library_dirs = ~a/lib
105 atlas_libs = openblas
106 "
107 (assoc-ref inputs "openblas")
108 (assoc-ref inputs "openblas")
109 (assoc-ref inputs "openblas"))))
110 #t))
111 (add-after 'install 'install-doc
112 (lambda* (#:key inputs outputs #:allow-other-keys)
113 (let* ((data (string-append (assoc-ref outputs "doc") "/share"))
114 (doc (string-append data "/doc/" ,name "-" ,version))
115 (html (string-append doc "/html"))
116 (pyver ,(string-append "PYVER=" (version-major+minor
117 (package-version python))))
118 ;; By default it tries to run sphinx-build through the Python
119 ;; interpreter which won't work with our shell wrapper.
120 (sphinxbuild "SPHINXBUILD=LANG=C sphinx-build"))
121 ;; Make installed package available for building the
122 ;; documentation
123 (add-installed-pythonpath inputs outputs)
124 (with-directory-excursion "doc"
125 ;; Fix generation of images for mathematical expressions.
126 (substitute* (find-files "source" "conf\\.py")
127 (("pngmath_use_preview = True")
128 "pngmath_use_preview = False"))
129 (mkdir-p html)
130 (invoke "make" "html" pyver sphinxbuild)
131 (with-directory-excursion "build/html"
132 (for-each (lambda (file)
133 (let* ((dir (dirname file))
134 (tgt-dir (string-append html "/" dir)))
135 (install-file file html)))
136 (find-files "." ".*")))))
137 #t))
138 ;; Tests can only be run after the library has been installed and not
139 ;; within the source directory.
140 (delete 'check)
141 (add-after 'install 'check
142 (lambda* (#:key inputs outputs #:allow-other-keys)
143 (add-installed-pythonpath inputs outputs)
144 (with-directory-excursion "/tmp"
145 (invoke "python" "-c"
146 "import scipy; scipy.test(verbose=2)")))))))
147 (home-page "https://www.scipy.org/")
148 (synopsis "The Scipy library provides efficient numerical routines")
149 (description "The SciPy library is one of the core packages that make up
150 the SciPy stack. It provides many user-friendly and efficient numerical
151 routines such as routines for numerical integration and optimization.")
152 (properties `((python2-variant . ,(delay python2-scipy))))
153 (license license:bsd-3)))
154
155 ;; Version 1.2.2 is the last version to support Python 2
156 (define-public python2-scipy
157 (package
158 (inherit (package-with-python2
159 (strip-python2-variant python-scipy)))
160 (version "1.2.2")
161 (source
162 (origin
163 (method url-fetch)
164 (uri (pypi-uri "scipy" version))
165 (sha256
166 (base32
167 "1cgvgin8fvckv96hjh3ikmwkra5rif51bdb75ifzf7xbil5iwcx4"))))))
168
169 (define-public python2-weave
170 (package
171 (name "python2-weave")
172 (version "0.16.0")
173 (source
174 (origin
175 (method url-fetch)
176 (uri (pypi-uri "weave" version))
177 (sha256
178 (base32 "0jnm3584mfichgwgrd1gk5i42ll9c08nkw9716n947n4338f6ghs"))))
179 (build-system python-build-system)
180 (arguments
181 `(#:python ,python-2
182 #:phases
183 (modify-phases %standard-phases
184 (replace 'check
185 (lambda _
186 (invoke "nosetests" "-v"
187 "--exclude"
188 "test_(user|incorrect_ownership|char_fail|obj_fail)"))))))
189 (propagated-inputs
190 `(("python-numpy" ,python2-numpy)))
191 (native-inputs
192 `(("python-nose" ,python2-nose)))
193 (home-page "https://www.scipy.org/")
194 (synopsis "Tools for including C/C++ code within Python code")
195 (description "Weave is the stand-alone version of the obsolete Scipy
196 submodule @code{scipy.weave}. It is Python 2.x only, and is provided for
197 users that need new versions of Scipy but have existing code that still
198 depends on @code{scipy.weave}. For new code, users are recommended to use
199 Cython.")
200 (license license:bsd-3)))
201
202 (define-public python-scikit-fuzzy
203 (package
204 (name "python-scikit-fuzzy")
205 (version "0.4.2")
206 (source
207 (origin
208 (method url-fetch)
209 (uri (pypi-uri "scikit-fuzzy" version))
210 (sha256
211 (base32 "0bp1n771fj44kdp7a00bcvfwirvv2rc803b7g6yf3va7v0j29c8s"))))
212 (build-system python-build-system)
213 (arguments
214 `(#:phases
215 (modify-phases %standard-phases
216 (replace 'check
217 (lambda _
218 (invoke "nosetests" "-s" "-v" "skfuzzy")
219 #t)))))
220 (native-inputs
221 `(("python-nose" ,python-nose)))
222 (propagated-inputs
223 `(("python-networkx" ,python-networkx)
224 ("python-numpy" ,python-numpy)
225 ("python-scipy" ,python-scipy)))
226 (home-page "https://github.com/scikit-fuzzy/scikit-fuzzy")
227 (synopsis "Fuzzy logic toolkit for SciPy")
228 (description
229 "This package implements many useful tools for projects involving fuzzy
230 logic, also known as grey logic.")
231 (license license:bsd-3)))
232
233 (define-public python-scikit-image
234 (package
235 (name "python-scikit-image")
236 (version "0.17.2")
237 (source
238 (origin
239 (method url-fetch)
240 (uri (pypi-uri "scikit-image" version))
241 (sha256
242 (base32 "1cyqqbcbrg3prc36wis0sm3q5rjhd7h9bp33jwfyixzhi02lr5dx"))))
243 (build-system python-build-system)
244 (arguments
245 ;; TODO: Some tests require running X11 server. Disable them?
246 '(#:tests? #f))
247 ;; See DEPENDS.txt for the list of build and run time requiremnts
248 (propagated-inputs
249 `(("python-cloudpickle" ,python-cloudpickle)
250 ("python-dask" ,python-dask)
251 ("python-imageio" ,python-imageio)
252 ("python-matplotlib" ,python-matplotlib)
253 ("python-networkx" ,python-networkx)
254 ("python-numpy" ,python-numpy)
255 ("python-pillow" ,python-pillow)
256 ("python-pywavelets" ,python-pywavelets)
257 ("python-scipy" ,python-scipy)
258 ("python-six" ,python-six)
259 ("python-tifffile" ,python-tifffile)))
260 (native-inputs
261 `(("python-cython" ,python-cython)))
262 (home-page "https://scikit-image.org/")
263 (synopsis "Image processing in Python")
264 (description
265 "Scikit-image is a collection of algorithms for image processing.")
266 (license license:bsd-3)))
267
268 (define-public python-sgp4
269 (package
270 (name "python-sgp4")
271 (version "2.12")
272 (source
273 (origin
274 (method url-fetch)
275 (uri (pypi-uri "sgp4" version))
276 (sha256
277 (base32 "0dncp9i5b6afkg7f8mj9j0qzsp008b8v73yc0qkmizhpns7mvwvx"))))
278 (build-system python-build-system)
279 (propagated-inputs
280 `(("python-numpy" ,python-numpy)))
281 (home-page "https://github.com/brandon-rhodes/python-sgp4")
282 (synopsis "Track earth satellite TLE orbits using SGP4")
283 (description
284 "This package provides a Python implementation of the most recent version
285 of the SGP4 satellite tracking algorithm.")
286 (license license:expat)))
287
288 (define-public python-pandas
289 (package
290 (name "python-pandas")
291 (version "1.0.5")
292 (source
293 (origin
294 (method url-fetch)
295 (uri (pypi-uri "pandas" version))
296 (sha256
297 (base32 "1a2gv3g6jr6vb5ca43fkwjl5xf86wpfz8y3zcy787adjl0hdkib9"))))
298 (build-system python-build-system)
299 (arguments
300 `(#:modules ((guix build utils)
301 (guix build python-build-system)
302 (ice-9 ftw)
303 (srfi srfi-26))
304 #:phases (modify-phases %standard-phases
305 (add-after 'unpack 'patch-which
306 (lambda* (#:key inputs #:allow-other-keys)
307 (let ((which (assoc-ref inputs "which")))
308 (substitute* "pandas/io/clipboard/__init__.py"
309 (("^WHICH_CMD = .*")
310 (string-append "WHICH_CMD = \"" which "\"\n"))))
311 #t))
312 (add-before 'check 'prepare-x
313 (lambda _
314 (system "Xvfb &")
315 (setenv "DISPLAY" ":0")
316 ;; xsel needs to write a log file.
317 (setenv "HOME" "/tmp")
318 #t))
319 (replace 'check
320 (lambda _
321 (let ((build-directory
322 (string-append
323 (getcwd) "/build/"
324 (car (scandir "build"
325 (cut string-prefix? "lib." <>))))))
326 ;; Disable the "strict data files" option which causes
327 ;; the build to error out if required data files are
328 ;; not available (as is the case with PyPI archives).
329 (substitute* "setup.cfg"
330 (("addopts = --strict-data-files") "addopts = "))
331 (with-directory-excursion build-directory
332 (invoke "pytest" "-vv" "pandas" "--skip-slow"
333 "--skip-network"))))))))
334 (propagated-inputs
335 `(("python-jinja2" ,python-jinja2)
336 ("python-numpy" ,python-numpy)
337 ("python-openpyxl" ,python-openpyxl)
338 ("python-pytz" ,python-pytz)
339 ("python-dateutil" ,python-dateutil)
340 ("python-xlrd" ,python-xlrd)))
341 (inputs
342 `(("which" ,which)
343 ("xclip" ,xclip)
344 ("xsel" ,xsel)))
345 (native-inputs
346 `(("python-cython" ,python-cython)
347 ("python-beautifulsoup4" ,python-beautifulsoup4)
348 ("python-lxml" ,python-lxml)
349 ("python-html5lib" ,python-html5lib)
350 ("python-nose" ,python-nose)
351 ("python-pytest" ,python-pytest)
352 ("python-pytest-mock" ,python-pytest-mock)
353 ;; Needed to test clipboard support.
354 ("xorg-server" ,xorg-server-for-tests)))
355 (home-page "https://pandas.pydata.org")
356 (synopsis "Data structures for data analysis, time series, and statistics")
357 (description
358 "Pandas is a Python package providing fast, flexible, and expressive data
359 structures designed to make working with structured (tabular,
360 multidimensional, potentially heterogeneous) and time series data both easy
361 and intuitive. It aims to be the fundamental high-level building block for
362 doing practical, real world data analysis in Python.")
363 (properties `((python2-variant . ,(delay python2-pandas))))
364 (license license:bsd-3)))
365
366 (define-public python-pandas-0.25
367 (package
368 (inherit python-pandas)
369 (version "0.25.3")
370 (source (origin
371 (method url-fetch)
372 (uri (pypi-uri "pandas" version))
373 (sha256
374 (base32
375 "191048m6kdc6yfvqs9w412lq60cfvigrsb57y0x116lwibgp9njj"))))
376 (arguments
377 (substitute-keyword-arguments (package-arguments python-pandas)
378 ((#:phases phases)
379 `(modify-phases ,phases
380 (replace 'patch-which
381 (lambda* (#:key inputs #:allow-other-keys)
382 (let ((which (assoc-ref inputs "which")))
383 (substitute* "pandas/io/clipboard/__init__.py"
384 (("^CHECK_CMD = .*")
385 (string-append "CHECK_CMD = \"" which "\"\n"))))
386 #t))
387 (delete 'prepare-x)))))))
388
389 ;; Pandas 0.24.x are the last versions that support Python 2.
390 (define-public python2-pandas
391 (let ((pandas (package-with-python2
392 (strip-python2-variant python-pandas-0.25))))
393 (package
394 (inherit pandas)
395 (version "0.24.2")
396 (source (origin
397 (method url-fetch)
398 (uri (pypi-uri "pandas" version))
399 (sha256
400 (base32
401 "18imlm8xbhcbwy4wa957a1fkamrcb0z988z006jpfda3ki09z4ag"))
402 (modules '((guix build utils)))
403 (snippet
404 '(begin
405 ;; Adjust for renamed error message in Python 2.7.17. Taken
406 ;; from <https://github.com/pandas-dev/pandas/pull/29294>.
407 (substitute* "pandas/io/parsers.py"
408 (("if 'NULL byte' in msg:")
409 "if 'NULL byte' in msg or 'line contains NUL' in msg:"))
410 #t)))))))
411
412 (define-public python-bottleneck
413 (package
414 (name "python-bottleneck")
415 (version "1.3.2")
416 (source
417 (origin
418 (method url-fetch)
419 (uri (pypi-uri "Bottleneck" version))
420 (sha256
421 (base32 "0wz5320jx3n4q2nsvwvc7cpi66b46qbals9v53m955rmcq5ry5r0"))))
422 (build-system python-build-system)
423 (arguments
424 `(#:phases
425 (modify-phases %standard-phases
426 (replace 'check
427 (lambda _
428 (invoke "python" "setup.py" "pytest"))))))
429 (native-inputs
430 `(("python-hypothesis" ,python-hypothesis)
431 ("python-pytest" ,python-pytest)
432 ("python-pytest-runner" ,python-pytest-runner)))
433 (propagated-inputs
434 `(("python-numpy" ,python-numpy)))
435 (home-page "https://github.com/pydata/bottleneck")
436 (synopsis "Fast NumPy array functions written in C")
437 (description
438 "Bottleneck is a collection of fast, NaN-aware NumPy array functions
439 written in C.")
440 (license license:bsd-2)))
441
442 (define-public python-xarray
443 (package
444 (name "python-xarray")
445 (version "0.15.1")
446 (source (origin
447 (method url-fetch)
448 (uri (pypi-uri "xarray" version))
449 (sha256
450 (base32
451 "1yx8j66b7rn10m2l6gmn8yr9cn38pi5cj0x0wwpy4hdnhy6i7qv4"))))
452 (build-system python-build-system)
453 (native-inputs
454 `(("python-setuptools-scm" ,python-setuptools-scm)
455 ("python-pytest" ,python-pytest)))
456 (propagated-inputs
457 `(("python-numpy" ,python-numpy)
458 ("python-pandas" ,python-pandas)))
459 (arguments
460 `(#:phases
461 (modify-phases %standard-phases
462 (replace 'check
463 (lambda _
464 (invoke "pytest"))))))
465 (home-page "https://github.com/pydata/xarray")
466 (synopsis "N-D labeled arrays and datasets")
467 (description "Xarray (formerly xray) makes working with labelled
468 multi-dimensional arrays simple, efficient, and fun!
469
470 Xarray introduces labels in the form of dimensions, coordinates and attributes
471 on top of raw NumPy-like arrays, which allows for a more intuitive, more
472 concise, and less error-prone developer experience. The package includes a
473 large and growing library of domain-agnostic functions for advanced analytics
474 and visualization with these data structures.")
475 (license license:asl2.0)))
476
477 (define-public python-msgpack-numpy
478 (package
479 (name "python-msgpack-numpy")
480 (version "0.4.6.post0")
481 (source
482 (origin
483 (method url-fetch)
484 (uri (pypi-uri "msgpack-numpy" version))
485 (sha256
486 (base32
487 "0syzy645mwcy7lfjwz6pc8f9p2vv1qk4limc8iina3l5nnf0rjyz"))))
488 (build-system python-build-system)
489 (propagated-inputs
490 `(("python-msgpack" ,python-msgpack)
491 ("python-numpy" ,python-numpy)))
492 (home-page "https://github.com/lebedov/msgpack-numpy")
493 (synopsis
494 "Numpy data serialization using msgpack")
495 (description
496 "This package provides encoding and decoding routines that enable the
497 serialization and deserialization of numerical and array data types provided
498 by numpy using the highly efficient @code{msgpack} format. Serialization of
499 Python's native complex data types is also supported.")
500 (license license:bsd-3)))