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 ] ++ lib.optional stdenv.is32bit [
226 # https://github.com/pandas-dev/pandas/issues/37398
227 "test_rolling_var_numerical_issues"
228 ];
229
230 # Tests have relative paths, and need to reference compiled C extensions
231 # so change directory where `import .test` is able to be resolved
232 preCheck = ''
233 export HOME=$TMPDIR
234 export LC_ALL="en_US.UTF-8"
235 cd $out/${python.sitePackages}/pandas
236 ''
237 # TODO: Get locale and clipboard support working on darwin.
238 # Until then we disable the tests.
239 + lib.optionalString stdenv.isDarwin ''
240 # Fake the impure dependencies pbpaste and pbcopy
241 echo "#!${runtimeShell}" > pbcopy
242 echo "#!${runtimeShell}" > pbpaste
243 chmod a+x pbcopy pbpaste
244 export PATH=$(pwd):$PATH
245 '';
246
247 pythonImportsCheck = [
248 "pandas"
249 ];
250
251 meta = with lib; {
252 # pandas devs no longer test i686, it's commonly broken
253 # broken = stdenv.isi686;
254 changelog = "https://pandas.pydata.org/docs/whatsnew/index.html";
255 description = "Powerful data structures for data analysis, time series, and statistics";
256 downloadPage = "https://github.com/pandas-dev/pandas";
257 homepage = "https://pandas.pydata.org";
258 license = licenses.bsd3;
259 longDescription = ''
260 Flexible and powerful data analysis / manipulation library for
261 Python, providing labeled data structures similar to R data.frame
262 objects, statistical functions, and much more.
263 '';
264 maintainers = with maintainers; [ raskin fridh knedlsepp ];
265 };
266}