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