gnu: facter: Update to 4.0.33.
[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-pandas
269 (package
270 (name "python-pandas")
271 (version "1.0.5")
272 (source
273 (origin
274 (method url-fetch)
275 (uri (pypi-uri "pandas" version))
276 (sha256
277 (base32 "1a2gv3g6jr6vb5ca43fkwjl5xf86wpfz8y3zcy787adjl0hdkib9"))))
278 (build-system python-build-system)
279 (arguments
280 `(#:modules ((guix build utils)
281 (guix build python-build-system)
282 (ice-9 ftw)
283 (srfi srfi-26))
284 #:phases (modify-phases %standard-phases
285 (add-after 'unpack 'patch-which
286 (lambda* (#:key inputs #:allow-other-keys)
287 (let ((which (assoc-ref inputs "which")))
288 (substitute* "pandas/io/clipboard/__init__.py"
289 (("^WHICH_CMD = .*")
290 (string-append "WHICH_CMD = \"" which "\"\n"))))
291 #t))
292 (add-before 'check 'prepare-x
293 (lambda _
294 (system "Xvfb &")
295 (setenv "DISPLAY" ":0")
296 ;; xsel needs to write a log file.
297 (setenv "HOME" "/tmp")
298 #t))
299 (replace 'check
300 (lambda _
301 (let ((build-directory
302 (string-append
303 (getcwd) "/build/"
304 (car (scandir "build"
305 (cut string-prefix? "lib." <>))))))
306 ;; Disable the "strict data files" option which causes
307 ;; the build to error out if required data files are
308 ;; not available (as is the case with PyPI archives).
309 (substitute* "setup.cfg"
310 (("addopts = --strict-data-files") "addopts = "))
311 (with-directory-excursion build-directory
312 (invoke "pytest" "-vv" "pandas" "--skip-slow"
313 "--skip-network"))))))))
314 (propagated-inputs
315 `(("python-jinja2" ,python-jinja2)
316 ("python-numpy" ,python-numpy)
317 ("python-openpyxl" ,python-openpyxl)
318 ("python-pytz" ,python-pytz)
319 ("python-dateutil" ,python-dateutil)
320 ("python-xlrd" ,python-xlrd)))
321 (inputs
322 `(("which" ,which)
323 ("xclip" ,xclip)
324 ("xsel" ,xsel)))
325 (native-inputs
326 `(("python-cython" ,python-cython)
327 ("python-beautifulsoup4" ,python-beautifulsoup4)
328 ("python-lxml" ,python-lxml)
329 ("python-html5lib" ,python-html5lib)
330 ("python-nose" ,python-nose)
331 ("python-pytest" ,python-pytest)
332 ("python-pytest-mock" ,python-pytest-mock)
333 ;; Needed to test clipboard support.
334 ("xorg-server" ,xorg-server-for-tests)))
335 (home-page "https://pandas.pydata.org")
336 (synopsis "Data structures for data analysis, time series, and statistics")
337 (description
338 "Pandas is a Python package providing fast, flexible, and expressive data
339 structures designed to make working with structured (tabular,
340 multidimensional, potentially heterogeneous) and time series data both easy
341 and intuitive. It aims to be the fundamental high-level building block for
342 doing practical, real world data analysis in Python.")
343 (properties `((python2-variant . ,(delay python2-pandas))))
344 (license license:bsd-3)))
345
346 (define-public python-pandas-0.25
347 (package
348 (inherit python-pandas)
349 (version "0.25.3")
350 (source (origin
351 (method url-fetch)
352 (uri (pypi-uri "pandas" version))
353 (sha256
354 (base32
355 "191048m6kdc6yfvqs9w412lq60cfvigrsb57y0x116lwibgp9njj"))))
356 (arguments
357 (substitute-keyword-arguments (package-arguments python-pandas)
358 ((#:phases phases)
359 `(modify-phases ,phases
360 (replace 'patch-which
361 (lambda* (#:key inputs #:allow-other-keys)
362 (let ((which (assoc-ref inputs "which")))
363 (substitute* "pandas/io/clipboard/__init__.py"
364 (("^CHECK_CMD = .*")
365 (string-append "CHECK_CMD = \"" which "\"\n"))))
366 #t))
367 (delete 'prepare-x)))))))
368
369 ;; Pandas 0.24.x are the last versions that support Python 2.
370 (define-public python2-pandas
371 (let ((pandas (package-with-python2
372 (strip-python2-variant python-pandas-0.25))))
373 (package
374 (inherit pandas)
375 (version "0.24.2")
376 (source (origin
377 (method url-fetch)
378 (uri (pypi-uri "pandas" version))
379 (sha256
380 (base32
381 "18imlm8xbhcbwy4wa957a1fkamrcb0z988z006jpfda3ki09z4ag"))
382 (modules '((guix build utils)))
383 (snippet
384 '(begin
385 ;; Adjust for renamed error message in Python 2.7.17. Taken
386 ;; from <https://github.com/pandas-dev/pandas/pull/29294>.
387 (substitute* "pandas/io/parsers.py"
388 (("if 'NULL byte' in msg:")
389 "if 'NULL byte' in msg or 'line contains NUL' in msg:"))
390 #t)))))))
391
392 (define-public python-xarray
393 (package
394 (name "python-xarray")
395 (version "0.15.1")
396 (source (origin
397 (method url-fetch)
398 (uri (pypi-uri "xarray" version))
399 (sha256
400 (base32
401 "1yx8j66b7rn10m2l6gmn8yr9cn38pi5cj0x0wwpy4hdnhy6i7qv4"))))
402 (build-system python-build-system)
403 (native-inputs
404 `(("python-setuptools-scm" ,python-setuptools-scm)
405 ("python-pytest" ,python-pytest)))
406 (propagated-inputs
407 `(("python-numpy" ,python-numpy)
408 ("python-pandas" ,python-pandas)))
409 (arguments
410 `(#:phases
411 (modify-phases %standard-phases
412 (replace 'check
413 (lambda _
414 (invoke "pytest"))))))
415 (home-page "https://github.com/pydata/xarray")
416 (synopsis "N-D labeled arrays and datasets")
417 (description "Xarray (formerly xray) makes working with labelled
418 multi-dimensional arrays simple, efficient, and fun!
419
420 Xarray introduces labels in the form of dimensions, coordinates and attributes
421 on top of raw NumPy-like arrays, which allows for a more intuitive, more
422 concise, and less error-prone developer experience. The package includes a
423 large and growing library of domain-agnostic functions for advanced analytics
424 and visualization with these data structures.")
425 (license license:asl2.0)))
426
427 (define-public python-msgpack-numpy
428 (package
429 (name "python-msgpack-numpy")
430 (version "0.4.6.post0")
431 (source
432 (origin
433 (method url-fetch)
434 (uri (pypi-uri "msgpack-numpy" version))
435 (sha256
436 (base32
437 "0syzy645mwcy7lfjwz6pc8f9p2vv1qk4limc8iina3l5nnf0rjyz"))))
438 (build-system python-build-system)
439 (propagated-inputs
440 `(("python-msgpack" ,python-msgpack)
441 ("python-numpy" ,python-numpy)))
442 (home-page "https://github.com/lebedov/msgpack-numpy")
443 (synopsis
444 "Numpy data serialization using msgpack")
445 (description
446 "This package provides encoding and decoding routines that enable the
447 serialization and deserialization of numerical and array data types provided
448 by numpy using the highly efficient @code{msgpack} format. Serialization of
449 Python's native complex data types is also supported.")
450 (license license:bsd-3)))