gnu: facter: Update to 4.0.34.
[jackhill/guix/guix.git] / gnu / packages / python-science.scm
CommitLineData
ca7c3653 1;;; GNU Guix --- Functional package management for GNU
ed333178 2;;; Copyright © 2015, 2016, 2020 Ricardo Wurmus <rekado@elephly.net>
ca7c3653 3;;; Copyright © 2015 Federico Beffa <beffa@fbengineering.ch>
312ec128 4;;; Copyright © 2016 Ben Woodcroft <donttrustben@gmail.com>
ca7c3653
RW
5;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
39877154 7;;; Copyright © 2016, 2017, 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
ca7c3653 8;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
312ec128
RW
9;;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
10;;; Copyright © 2019 Giacomo Leidi <goodoldpaul@autistici.org>
20b545f7 11;;; Copyright © 2020 Pierre Langlois <pierre.langlois@gmx.com>
34432d5a 12;;; Copyright © 2020 Vinicius Monego <monego@posteo.net>
ca7c3653
RW
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)
ec1224a7
RW
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)
312ec128 38 #:use-module (gnu packages python-web)
ca7c3653 39 #:use-module (gnu packages python-xyz)
ec1224a7 40 #:use-module (gnu packages sphinx)
312ec128 41 #:use-module (gnu packages time)
20b545f7 42 #:use-module (gnu packages xdisorg)
55e1475c 43 #:use-module (gnu packages xml)
20b545f7 44 #:use-module (gnu packages xorg)
ca7c3653
RW
45 #:use-module (guix packages)
46 #:use-module (guix download)
47 #:use-module (guix utils)
48 #:use-module (guix build-system python))
49
ec1224a7
RW
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]
98libraries = openblas
99library_dirs = ~a/lib
100include_dirs = ~a/include
101
102# backslash-n to make emacs happy
103\n[atlas]
104library_dirs = ~a/lib
105atlas_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
150the SciPy stack. It provides many user-friendly and efficient numerical
151routines 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
ed333178
RW
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
196submodule @code{scipy.weave}. It is Python 2.x only, and is provided for
197users that need new versions of Scipy but have existing code that still
198depends on @code{scipy.weave}. For new code, users are recommended to use
199Cython.")
200 (license license:bsd-3)))
201
34432d5a
VM
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
230logic, also known as grey logic.")
231 (license license:bsd-3)))
232
ca7c3653
RW
233(define-public python-scikit-image
234 (package
235 (name "python-scikit-image")
4be49afa 236 (version "0.17.2")
ca7c3653
RW
237 (source
238 (origin
239 (method url-fetch)
240 (uri (pypi-uri "scikit-image" version))
241 (sha256
4be49afa 242 (base32 "1cyqqbcbrg3prc36wis0sm3q5rjhd7h9bp33jwfyixzhi02lr5dx"))))
ca7c3653
RW
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)
8bebb547 251 ("python-imageio" ,python-imageio)
ca7c3653
RW
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)
8bebb547
VM
258 ("python-six" ,python-six)
259 ("python-tifffile" ,python-tifffile)))
ca7c3653
RW
260 (native-inputs
261 `(("python-cython" ,python-cython)))
082c733c 262 (home-page "https://scikit-image.org/")
ca7c3653
RW
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
312ec128
RW
268(define-public python-pandas
269 (package
270 (name "python-pandas")
20b545f7 271 (version "1.0.5")
312ec128
RW
272 (source
273 (origin
274 (method url-fetch)
275 (uri (pypi-uri "pandas" version))
276 (sha256
20b545f7 277 (base32 "1a2gv3g6jr6vb5ca43fkwjl5xf86wpfz8y3zcy787adjl0hdkib9"))))
312ec128
RW
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"
20b545f7
PL
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")
312ec128
RW
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
312ec128 312 (invoke "pytest" "-vv" "pandas" "--skip-slow"
20b545f7 313 "--skip-network"))))))))
312ec128 314 (propagated-inputs
20b545f7
PL
315 `(("python-jinja2" ,python-jinja2)
316 ("python-numpy" ,python-numpy)
312ec128
RW
317 ("python-openpyxl" ,python-openpyxl)
318 ("python-pytz" ,python-pytz)
319 ("python-dateutil" ,python-dateutil)
320 ("python-xlrd" ,python-xlrd)))
321 (inputs
20b545f7
PL
322 `(("which" ,which)
323 ("xclip" ,xclip)
324 ("xsel" ,xsel)))
312ec128
RW
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)
20b545f7
PL
332 ("python-pytest-mock" ,python-pytest-mock)
333 ;; Needed to test clipboard support.
334 ("xorg-server" ,xorg-server-for-tests)))
312ec128
RW
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
339structures designed to make working with structured (tabular,
340multidimensional, potentially heterogeneous) and time series data both easy
341and intuitive. It aims to be the fundamental high-level building block for
342doing practical, real world data analysis in Python.")
343 (properties `((python2-variant . ,(delay python2-pandas))))
344 (license license:bsd-3)))
345
20b545f7
PL
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
312ec128
RW
369;; Pandas 0.24.x are the last versions that support Python 2.
370(define-public python2-pandas
371 (let ((pandas (package-with-python2
20b545f7 372 (strip-python2-variant python-pandas-0.25))))
39877154
MB
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)))))))
3417a251 391
47ad589f
VM
392(define-public python-bottleneck
393 (package
394 (name "python-bottleneck")
395 (version "1.3.2")
396 (source
397 (origin
398 (method url-fetch)
399 (uri (pypi-uri "Bottleneck" version))
400 (sha256
401 (base32 "0wz5320jx3n4q2nsvwvc7cpi66b46qbals9v53m955rmcq5ry5r0"))))
402 (build-system python-build-system)
403 (arguments
404 `(#:phases
405 (modify-phases %standard-phases
406 (replace 'check
407 (lambda _
408 (invoke "python" "setup.py" "pytest"))))))
409 (native-inputs
410 `(("python-hypothesis" ,python-hypothesis)
411 ("python-pytest" ,python-pytest)
412 ("python-pytest-runner" ,python-pytest-runner)))
413 (propagated-inputs
414 `(("python-numpy" ,python-numpy)))
415 (home-page "https://github.com/pydata/bottleneck")
416 (synopsis "Fast NumPy array functions written in C")
417 (description
418 "Bottleneck is a collection of fast, NaN-aware NumPy array functions
419written in C.")
420 (license license:bsd-2)))
421
3417a251
PL
422(define-public python-xarray
423 (package
424 (name "python-xarray")
425 (version "0.15.1")
426 (source (origin
427 (method url-fetch)
428 (uri (pypi-uri "xarray" version))
429 (sha256
430 (base32
431 "1yx8j66b7rn10m2l6gmn8yr9cn38pi5cj0x0wwpy4hdnhy6i7qv4"))))
432 (build-system python-build-system)
433 (native-inputs
434 `(("python-setuptools-scm" ,python-setuptools-scm)
435 ("python-pytest" ,python-pytest)))
436 (propagated-inputs
437 `(("python-numpy" ,python-numpy)
438 ("python-pandas" ,python-pandas)))
439 (arguments
440 `(#:phases
441 (modify-phases %standard-phases
442 (replace 'check
443 (lambda _
444 (invoke "pytest"))))))
445 (home-page "https://github.com/pydata/xarray")
446 (synopsis "N-D labeled arrays and datasets")
447 (description "Xarray (formerly xray) makes working with labelled
448multi-dimensional arrays simple, efficient, and fun!
449
450Xarray introduces labels in the form of dimensions, coordinates and attributes
451on top of raw NumPy-like arrays, which allows for a more intuitive, more
452concise, and less error-prone developer experience. The package includes a
453large and growing library of domain-agnostic functions for advanced analytics
454and visualization with these data structures.")
455 (license license:asl2.0)))
5db8ba1f
RW
456
457(define-public python-msgpack-numpy
458 (package
459 (name "python-msgpack-numpy")
460 (version "0.4.6.post0")
461 (source
462 (origin
463 (method url-fetch)
464 (uri (pypi-uri "msgpack-numpy" version))
465 (sha256
466 (base32
467 "0syzy645mwcy7lfjwz6pc8f9p2vv1qk4limc8iina3l5nnf0rjyz"))))
468 (build-system python-build-system)
469 (propagated-inputs
470 `(("python-msgpack" ,python-msgpack)
471 ("python-numpy" ,python-numpy)))
472 (home-page "https://github.com/lebedov/msgpack-numpy")
473 (synopsis
474 "Numpy data serialization using msgpack")
475 (description
476 "This package provides encoding and decoding routines that enable the
477serialization and deserialization of numerical and array data types provided
478by numpy using the highly efficient @code{msgpack} format. Serialization of
479Python's native complex data types is also supported.")
480 (license license:bsd-3)))