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>
14 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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))
50 (define-public python-scipy
57 (uri (pypi-uri "scipy" version))
59 (base32 "192d8dsybvhv19igkrsafbdafx198nz7pibkjgrqjhlr66s3jfd0"))))
60 (build-system python-build-system)
62 `(("python-numpy" ,python-numpy)
63 ("python-matplotlib" ,python-matplotlib)
64 ("python-pyparsing" ,python-pyparsing)))
67 ("openblas" ,openblas)))
69 `(("python-cython" ,python-cython)
70 ("python-pytest" ,python-pytest)
71 ("python-sphinx" ,python-sphinx)
72 ("python-numpydoc" ,python-numpydoc)
73 ("gfortran" ,gfortran)
76 (outputs '("out" "doc"))
79 (modify-phases %standard-phases
80 (add-after 'unpack 'disable-broken-tests
82 (substitute* "scipy/sparse/linalg/dsolve/tests/test_linsolve.py"
83 (("^( +)def test_threads_parallel\\(self\\):" m indent)
85 "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
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"
92 (add-before 'build 'configure-openblas
93 (lambda* (#:key inputs #:allow-other-keys)
94 (call-with-output-file "site.cfg"
100 include_dirs = ~a/include
102 # backslash-n to make emacs happy
104 library_dirs = ~a/lib
105 atlas_libs = openblas
107 (assoc-ref inputs "openblas")
108 (assoc-ref inputs "openblas")
109 (assoc-ref inputs "openblas"))))
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
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"))
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 "." ".*")))))
138 ;; Tests can only be run after the library has been installed and not
139 ;; within the source directory.
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)))
155 ;; Version 1.2.2 is the last version to support Python 2
156 (define-public python2-scipy
158 (inherit (package-with-python2
159 (strip-python2-variant python-scipy)))
164 (uri (pypi-uri "scipy" version))
167 "1cgvgin8fvckv96hjh3ikmwkra5rif51bdb75ifzf7xbil5iwcx4"))))))
169 (define-public python2-weave
171 (name "python2-weave")
176 (uri (pypi-uri "weave" version))
178 (base32 "0jnm3584mfichgwgrd1gk5i42ll9c08nkw9716n947n4338f6ghs"))))
179 (build-system python-build-system)
183 (modify-phases %standard-phases
186 (invoke "nosetests" "-v"
188 "test_(user|incorrect_ownership|char_fail|obj_fail)"))))))
190 `(("python-numpy" ,python2-numpy)))
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
200 (license license:bsd-3)))
202 (define-public python-scikit-fuzzy
204 (name "python-scikit-fuzzy")
209 (uri (pypi-uri "scikit-fuzzy" version))
211 (base32 "0bp1n771fj44kdp7a00bcvfwirvv2rc803b7g6yf3va7v0j29c8s"))))
212 (build-system python-build-system)
215 (modify-phases %standard-phases
218 (invoke "nosetests" "-s" "-v" "skfuzzy")
221 `(("python-nose" ,python-nose)))
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")
229 "This package implements many useful tools for projects involving fuzzy
230 logic, also known as grey logic.")
231 (license license:bsd-3)))
233 (define-public python-scikit-image
235 (name "python-scikit-image")
240 (uri (pypi-uri "scikit-image" version))
242 (base32 "1cyqqbcbrg3prc36wis0sm3q5rjhd7h9bp33jwfyixzhi02lr5dx"))))
243 (build-system python-build-system)
245 ;; TODO: Some tests require running X11 server. Disable them?
247 ;; See DEPENDS.txt for the list of build and run time requiremnts
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)))
261 `(("python-cython" ,python-cython)))
262 (home-page "https://scikit-image.org/")
263 (synopsis "Image processing in Python")
265 "Scikit-image is a collection of algorithms for image processing.")
266 (license license:bsd-3)))
268 (define-public python-sgp4
275 (uri (pypi-uri "sgp4" version))
277 (base32 "0dncp9i5b6afkg7f8mj9j0qzsp008b8v73yc0qkmizhpns7mvwvx"))))
278 (build-system python-build-system)
280 `(("python-numpy" ,python-numpy)))
281 (home-page "https://github.com/brandon-rhodes/python-sgp4")
282 (synopsis "Track earth satellite TLE orbits using SGP4")
284 "This package provides a Python implementation of the most recent version
285 of the SGP4 satellite tracking algorithm.")
286 (license license:expat)))
288 (define-public python-pandas
290 (name "python-pandas")
295 (uri (pypi-uri "pandas" version))
297 (base32 "1a2gv3g6jr6vb5ca43fkwjl5xf86wpfz8y3zcy787adjl0hdkib9"))))
298 (build-system python-build-system)
300 `(#:modules ((guix build utils)
301 (guix build python-build-system)
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"
310 (string-append "WHICH_CMD = \"" which "\"\n"))))
312 (add-before 'check 'prepare-x
315 (setenv "DISPLAY" ":0")
316 ;; xsel needs to write a log file.
317 (setenv "HOME" "/tmp")
321 (let ((build-directory
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"))))))))
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)))
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")
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)))
366 (define-public python-pandas-0.25
368 (inherit python-pandas)
372 (uri (pypi-uri "pandas" version))
375 "191048m6kdc6yfvqs9w412lq60cfvigrsb57y0x116lwibgp9njj"))))
377 (substitute-keyword-arguments (package-arguments python-pandas)
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"
385 (string-append "CHECK_CMD = \"" which "\"\n"))))
387 (delete 'prepare-x)))))))
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))))
398 (uri (pypi-uri "pandas" version))
401 "18imlm8xbhcbwy4wa957a1fkamrcb0z988z006jpfda3ki09z4ag"))
402 (modules '((guix build utils)))
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:"))
412 (define-public python-bottleneck
414 (name "python-bottleneck")
419 (uri (pypi-uri "Bottleneck" version))
421 (base32 "0wz5320jx3n4q2nsvwvc7cpi66b46qbals9v53m955rmcq5ry5r0"))))
422 (build-system python-build-system)
425 (modify-phases %standard-phases
428 (invoke "python" "setup.py" "pytest"))))))
430 `(("python-hypothesis" ,python-hypothesis)
431 ("python-pytest" ,python-pytest)
432 ("python-pytest-runner" ,python-pytest-runner)))
434 `(("python-numpy" ,python-numpy)))
435 (home-page "https://github.com/pydata/bottleneck")
436 (synopsis "Fast NumPy array functions written in C")
438 "Bottleneck is a collection of fast, NaN-aware NumPy array functions
440 (license license:bsd-2)))
442 (define-public python-xarray
444 (name "python-xarray")
448 (uri (pypi-uri "xarray" version))
451 "1yx8j66b7rn10m2l6gmn8yr9cn38pi5cj0x0wwpy4hdnhy6i7qv4"))))
452 (build-system python-build-system)
454 `(("python-setuptools-scm" ,python-setuptools-scm)
455 ("python-pytest" ,python-pytest)))
457 `(("python-numpy" ,python-numpy)
458 ("python-pandas" ,python-pandas)))
461 (modify-phases %standard-phases
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!
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)))
477 (define-public python-msgpack-numpy
479 (name "python-msgpack-numpy")
480 (version "0.4.6.post0")
484 (uri (pypi-uri "msgpack-numpy" version))
487 "0syzy645mwcy7lfjwz6pc8f9p2vv1qk4limc8iina3l5nnf0rjyz"))))
488 (build-system python-build-system)
490 `(("python-msgpack" ,python-msgpack)
491 ("python-numpy" ,python-numpy)))
492 (home-page "https://github.com/lebedov/msgpack-numpy")
494 "Numpy data serialization using msgpack")
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)))