1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016 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>
12 ;;; This file is part of GNU Guix.
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
27 (define-module (gnu packages python-science)
28 #:use-module ((guix licenses) #:prefix license:)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages base)
31 #:use-module (gnu packages check)
32 #:use-module (gnu packages gcc)
33 #:use-module (gnu packages maths)
34 #:use-module (gnu packages perl)
35 #:use-module (gnu packages python)
36 #:use-module (gnu packages python-web)
37 #:use-module (gnu packages python-xyz)
38 #:use-module (gnu packages sphinx)
39 #:use-module (gnu packages time)
40 #:use-module (gnu packages xml)
41 #:use-module (guix packages)
42 #:use-module (guix download)
43 #:use-module (guix utils)
44 #:use-module (guix build-system python))
46 (define-public python-scipy
53 (uri (pypi-uri "scipy" version))
55 (base32 "192d8dsybvhv19igkrsafbdafx198nz7pibkjgrqjhlr66s3jfd0"))))
56 (build-system python-build-system)
58 `(("python-numpy" ,python-numpy)
59 ("python-matplotlib" ,python-matplotlib)
60 ("python-pyparsing" ,python-pyparsing)))
63 ("openblas" ,openblas)))
65 `(("python-cython" ,python-cython)
66 ("python-pytest" ,python-pytest)
67 ("python-sphinx" ,python-sphinx)
68 ("python-numpydoc" ,python-numpydoc)
69 ("gfortran" ,gfortran)
72 (outputs '("out" "doc"))
75 (modify-phases %standard-phases
76 (add-after 'unpack 'disable-broken-tests
78 (substitute* "scipy/sparse/linalg/dsolve/tests/test_linsolve.py"
79 (("^( +)def test_threads_parallel\\(self\\):" m indent)
81 "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
83 (substitute* "scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py"
84 (("^def test_parallel_threads\\(\\):" m)
85 (string-append "@pytest.mark.skip(reason=\"Disabled by Guix\")\n"
88 (add-before 'build 'configure-openblas
89 (lambda* (#:key inputs #:allow-other-keys)
90 (call-with-output-file "site.cfg"
96 include_dirs = ~a/include
98 # backslash-n to make emacs happy
100 library_dirs = ~a/lib
101 atlas_libs = openblas
103 (assoc-ref inputs "openblas")
104 (assoc-ref inputs "openblas")
105 (assoc-ref inputs "openblas"))))
107 (add-after 'install 'install-doc
108 (lambda* (#:key inputs outputs #:allow-other-keys)
109 (let* ((data (string-append (assoc-ref outputs "doc") "/share"))
110 (doc (string-append data "/doc/" ,name "-" ,version))
111 (html (string-append doc "/html"))
112 (pyver ,(string-append "PYVER=" (version-major+minor
113 (package-version python))))
114 ;; By default it tries to run sphinx-build through the Python
115 ;; interpreter which won't work with our shell wrapper.
116 (sphinxbuild "SPHINXBUILD=LANG=C sphinx-build"))
117 ;; Make installed package available for building the
119 (add-installed-pythonpath inputs outputs)
120 (with-directory-excursion "doc"
121 ;; Fix generation of images for mathematical expressions.
122 (substitute* (find-files "source" "conf\\.py")
123 (("pngmath_use_preview = True")
124 "pngmath_use_preview = False"))
126 (invoke "make" "html" pyver sphinxbuild)
127 (with-directory-excursion "build/html"
128 (for-each (lambda (file)
129 (let* ((dir (dirname file))
130 (tgt-dir (string-append html "/" dir)))
131 (install-file file html)))
132 (find-files "." ".*")))))
134 ;; Tests can only be run after the library has been installed and not
135 ;; within the source directory.
137 (add-after 'install 'check
138 (lambda* (#:key inputs outputs #:allow-other-keys)
139 (add-installed-pythonpath inputs outputs)
140 (with-directory-excursion "/tmp"
141 (invoke "python" "-c"
142 "import scipy; scipy.test(verbose=2)")))))))
143 (home-page "https://www.scipy.org/")
144 (synopsis "The Scipy library provides efficient numerical routines")
145 (description "The SciPy library is one of the core packages that make up
146 the SciPy stack. It provides many user-friendly and efficient numerical
147 routines such as routines for numerical integration and optimization.")
148 (properties `((python2-variant . ,(delay python2-scipy))))
149 (license license:bsd-3)))
151 ;; Version 1.2.2 is the last version to support Python 2
152 (define-public python2-scipy
154 (inherit (package-with-python2
155 (strip-python2-variant python-scipy)))
160 (uri (pypi-uri "scipy" version))
163 "1cgvgin8fvckv96hjh3ikmwkra5rif51bdb75ifzf7xbil5iwcx4"))))))
165 (define-public python-scikit-image
167 (name "python-scikit-image")
172 (uri (pypi-uri "scikit-image" version))
174 (base32 "07qchljkyxvg5nrm12fvszi7pmjk4m01qp0w0z8syxzxxs20pz8s"))))
175 (build-system python-build-system)
177 ;; TODO: Some tests require running X11 server. Disable them?
179 ;; See DEPENDS.txt for the list of build and run time requiremnts
181 `(("python-cloudpickle" ,python-cloudpickle)
182 ("python-dask" ,python-dask)
183 ("python-matplotlib" ,python-matplotlib)
184 ("python-networkx" ,python-networkx)
185 ("python-numpy" ,python-numpy)
186 ("python-pillow" ,python-pillow)
187 ("python-pywavelets" ,python-pywavelets)
188 ("python-scipy" ,python-scipy)
189 ("python-six" ,python-six)))
191 `(("python-cython" ,python-cython)))
192 (home-page "https://scikit-image.org/")
193 (synopsis "Image processing in Python")
195 "Scikit-image is a collection of algorithms for image processing.")
196 (license license:bsd-3)))
198 (define-public python-pandas
200 (name "python-pandas")
205 (uri (pypi-uri "pandas" version))
207 (base32 "1gp2pvzdiakvgjmykdzdlzrsfbg4vjm49jjdl9s0ha0a3yfs34fa"))))
208 (build-system python-build-system)
210 `(#:modules ((guix build utils)
211 (guix build python-build-system)
214 #:phases (modify-phases %standard-phases
215 (add-after 'unpack 'patch-which
216 (lambda* (#:key inputs #:allow-other-keys)
217 (let ((which (assoc-ref inputs "which")))
218 (substitute* "pandas/io/clipboard/__init__.py"
220 (string-append "CHECK_CMD = \"" which "\"\n"))))
224 (let ((build-directory
227 (car (scandir "build"
228 (cut string-prefix? "lib." <>))))))
229 ;; Disable the "strict data files" option which causes
230 ;; the build to error out if required data files are
231 ;; not available (as is the case with PyPI archives).
232 (substitute* "setup.cfg"
233 (("addopts = --strict-data-files") "addopts = "))
234 (with-directory-excursion build-directory
235 ;; Delete tests that require "moto" which is not yet
237 (for-each delete-file
238 '("pandas/tests/io/conftest.py"
239 "pandas/tests/io/json/test_compression.py"
240 "pandas/tests/io/parser/test_network.py"
241 "pandas/tests/io/test_parquet.py"))
242 (invoke "pytest" "-vv" "pandas" "--skip-slow"
243 "--skip-network" "-k"
244 ;; XXX: Due to the deleted tests above.
245 "not test_read_s3_jsonl"))))))))
247 `(("python-numpy" ,python-numpy)
248 ("python-openpyxl" ,python-openpyxl)
249 ("python-pytz" ,python-pytz)
250 ("python-dateutil" ,python-dateutil)
251 ("python-xlrd" ,python-xlrd)))
255 `(("python-cython" ,python-cython)
256 ("python-beautifulsoup4" ,python-beautifulsoup4)
257 ("python-lxml" ,python-lxml)
258 ("python-html5lib" ,python-html5lib)
259 ("python-nose" ,python-nose)
260 ("python-pytest" ,python-pytest)
261 ("python-pytest-mock" ,python-pytest-mock)))
262 (home-page "https://pandas.pydata.org")
263 (synopsis "Data structures for data analysis, time series, and statistics")
265 "Pandas is a Python package providing fast, flexible, and expressive data
266 structures designed to make working with structured (tabular,
267 multidimensional, potentially heterogeneous) and time series data both easy
268 and intuitive. It aims to be the fundamental high-level building block for
269 doing practical, real world data analysis in Python.")
270 (properties `((python2-variant . ,(delay python2-pandas))))
271 (license license:bsd-3)))
273 ;; Pandas 0.24.x are the last versions that support Python 2.
274 (define-public python2-pandas
275 (let ((pandas (package-with-python2
276 (strip-python2-variant python-pandas))))
282 (uri (pypi-uri "pandas" version))
285 "18imlm8xbhcbwy4wa957a1fkamrcb0z988z006jpfda3ki09z4ag"))
286 (modules '((guix build utils)))
289 ;; Adjust for renamed error message in Python 2.7.17. Taken
290 ;; from <https://github.com/pandas-dev/pandas/pull/29294>.
291 (substitute* "pandas/io/parsers.py"
292 (("if 'NULL byte' in msg:")
293 "if 'NULL byte' in msg or 'line contains NUL' in msg:"))