1{ lib
2, stdenv
3, buildPythonPackage
4, fetchFromGitHub
5, pythonOlder
6
7# build-system
8, cython
9, meson-python
10, meson
11, oldest-supported-numpy
12, pkg-config
13, versioneer
14, wheel
15
16# propagates
17, numpy
18, python-dateutil
19, pytz
20, tzdata
21
22# optionals
23, beautifulsoup4
24, bottleneck
25, blosc2
26, brotlipy
27, fsspec
28, gcsfs
29, html5lib
30, jinja2
31, lxml
32, matplotlib
33, numba
34, numexpr
35, odfpy
36, openpyxl
37, psycopg2
38, pyarrow
39, pymysql
40, pyqt5
41, pyreadstat
42, python-snappy
43, qtpy
44, s3fs
45, scipy
46, sqlalchemy
47, tables
48, tabulate
49, xarray
50, xlrd
51, xlsxwriter
52, zstandard
53
54# tests
55, adv_cmds
56, glibc
57, glibcLocales
58, hypothesis
59, pytestCheckHook
60, pytest-xdist
61, pytest-asyncio
62, python
63, runtimeShell
64}:
65
66buildPythonPackage rec {
67 pname = "pandas";
68 version = "2.1.1";
69 pyproject = true;
70
71 disabled = pythonOlder "3.9";
72
73 src = fetchFromGitHub {
74 owner = "pandas-dev";
75 repo = "pandas";
76 rev = "refs/tags/v${version}";
77 hash = "sha256-6SgW4BtO7EFnS8P8LL4AGk5EdPwOQ0+is0wXgqsm9w0=";
78 };
79
80 postPatch = ''
81 substituteInPlace pyproject.toml \
82 --replace "meson-python==0.13.1" "meson-python>=0.13.1" \
83 --replace "meson==1.2.1" "meson>=1.2.1"
84 '';
85
86 nativeBuildInputs = [
87 cython
88 meson-python
89 meson
90 numpy
91 pkg-config
92 versioneer
93 wheel
94 ]
95 ++ versioneer.optional-dependencies.toml
96 ++ lib.optionals (pythonOlder "3.12") [
97 oldest-supported-numpy
98 ];
99
100 enableParallelBuilding = true;
101
102 propagatedBuildInputs = [
103 numpy
104 python-dateutil
105 pytz
106 tzdata
107 ];
108
109 passthru.optional-dependencies = let
110 extras = {
111 aws = [
112 s3fs
113 ];
114 clipboard = [
115 pyqt5
116 qtpy
117 ];
118 compression = [
119 brotlipy
120 python-snappy
121 zstandard
122 ];
123 computation = [
124 scipy
125 xarray
126 ];
127 excel = [
128 odfpy
129 openpyxl
130 # TODO: pyxlsb
131 xlrd
132 xlsxwriter
133 ];
134 feather = [
135 pyarrow
136 ];
137 fss = [
138 fsspec
139 ];
140 gcp = [
141 gcsfs
142 # TODO: pandas-gqb
143 ];
144 hdf5 = [
145 blosc2
146 tables
147 ];
148 html = [
149 beautifulsoup4
150 html5lib
151 lxml
152 ];
153 mysql = [
154 sqlalchemy
155 pymysql
156 ];
157 output_formatting = [
158 jinja2
159 tabulate
160 ];
161 parquet = [
162 pyarrow
163 ];
164 performance = [
165 bottleneck
166 numba
167 numexpr
168 ];
169 plot = [
170 matplotlib
171 ];
172 postgresql = [
173 sqlalchemy
174 psycopg2
175 ];
176 spss = [
177 pyreadstat
178 ];
179 sql-other = [
180 sqlalchemy
181 ];
182 xml = [
183 lxml
184 ];
185 };
186 in extras // {
187 all = lib.concatLists (lib.attrValues extras);
188 };
189
190 nativeCheckInputs = [
191 glibcLocales
192 hypothesis
193 pytest-asyncio
194 pytest-xdist
195 pytestCheckHook
196 ] ++ lib.optionals (stdenv.isLinux) [
197 # for locale executable
198 glibc
199 ] ++ lib.optionals (stdenv.isDarwin) [
200 # for locale executable
201 adv_cmds
202 ];
203
204 # don't max out build cores, it breaks tests
205 dontUsePytestXdist = true;
206
207 __darwinAllowLocalNetworking = true;
208
209 pytestFlagsArray = [
210 # https://github.com/pandas-dev/pandas/blob/main/test_fast.sh
211 "-m" "'not single_cpu and not slow and not network and not db and not slow_arm'"
212 # https://github.com/pandas-dev/pandas/issues/54907
213 "--no-strict-data-files"
214 "--numprocesses" "4"
215 ];
216
217 disabledTests = [
218 # AssertionError: Did not see expected warning of class 'FutureWarning'
219 "test_parsing_tzlocal_deprecated"
220 ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
221 # tests/generic/test_finalize.py::test_binops[and_-args4-right] - AssertionError: assert {} == {'a': 1}
222 "test_binops"
223 # These tests are unreliable on aarch64-darwin. See https://github.com/pandas-dev/pandas/issues/38921.
224 "test_rolling"
225 ];
226
227 # Tests have relative paths, and need to reference compiled C extensions
228 # so change directory where `import .test` is able to be resolved
229 preCheck = ''
230 export HOME=$TMPDIR
231 export LC_ALL="en_US.UTF-8"
232 cd $out/${python.sitePackages}/pandas
233 ''
234 # TODO: Get locale and clipboard support working on darwin.
235 # Until then we disable the tests.
236 + lib.optionalString stdenv.isDarwin ''
237 # Fake the impure dependencies pbpaste and pbcopy
238 echo "#!${runtimeShell}" > pbcopy
239 echo "#!${runtimeShell}" > pbpaste
240 chmod a+x pbcopy pbpaste
241 export PATH=$(pwd):$PATH
242 '';
243
244 pythonImportsCheck = [
245 "pandas"
246 ];
247
248 meta = with lib; {
249 # https://github.com/pandas-dev/pandas/issues/14866
250 # pandas devs are no longer testing i686 so safer to assume it's broken
251 broken = stdenv.isi686;
252 changelog = "https://pandas.pydata.org/docs/whatsnew/index.html";
253 description = "Powerful data structures for data analysis, time series, and statistics";
254 downloadPage = "https://github.com/pandas-dev/pandas";
255 homepage = "https://pandas.pydata.org";
256 license = licenses.bsd3;
257 longDescription = ''
258 Flexible and powerful data analysis / manipulation library for
259 Python, providing labeled data structures similar to R data.frame
260 objects, statistical functions, and much more.
261 '';
262 maintainers = with maintainers; [ raskin fridh knedlsepp ];
263 };
264}