summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/pandas/default.nix
blob: 1b6138529d56594b657464d51d719b41023d937f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
{
  lib,
  stdenv,
  buildPythonPackage,
  fetchFromGitHub,

  # build-system
  cython,
  meson-python,
  meson,
  pkg-config,
  versioneer,
  wheel,

  # propagates
  numpy,
  python-dateutil,
  pytz,
  tzdata,

  # optionals
  beautifulsoup4,
  bottleneck,
  blosc2,
  fsspec,
  gcsfs,
  html5lib,
  jinja2,
  lxml,
  matplotlib,
  numba,
  numexpr,
  odfpy,
  openpyxl,
  psycopg2,
  pyarrow,
  pymysql,
  pyqt5,
  pyreadstat,
  pyxlsb,
  qtpy,
  s3fs,
  scipy,
  sqlalchemy,
  tables,
  tabulate,
  xarray,
  xlrd,
  xlsxwriter,
  zstandard,

  # tests
  adv_cmds,
  glibc,
  hypothesis,
  pytestCheckHook,
  pytest-xdist,
  pytest-asyncio,
  python,
  runtimeShell,
}:

let
  pandas = buildPythonPackage rec {
    pname = "pandas";
    version = "2.3.3";
    pyproject = true;

    src = fetchFromGitHub {
      owner = "pandas-dev";
      repo = "pandas";
      tag = "v${version}";
      hash = "sha256-jY1uM9HmJzoFk26ilbtzJnxAsQhmXS19r73JcFeFWRQ=";
    };

    # A NOTE regarding the Numpy version relaxing: Both Numpy versions 1.x &
    # 2.x are supported. However upstream wants to always build with Numpy 2,
    # and with it to still be able to run with a Numpy 1 or 2. We insist to
    # perform this substitution even though python3.pkgs.numpy is of version 2
    # nowadays, because our ecosystem unfortunately doesn't allow easily
    # separating runtime and build-system dependencies. See also:
    #
    # https://discourse.nixos.org/t/several-comments-about-priorities-and-new-policies-in-the-python-ecosystem/51790
    #
    # Being able to build (& run) with Numpy 1 helps for python environments
    # that override globally the `numpy` attribute to point to `numpy_1`.
    postPatch = ''
      substituteInPlace pyproject.toml \
        --replace-fail "numpy>=2.0" numpy
    '';

    build-system = [
      cython
      meson-python
      meson
      numpy
      pkg-config
      versioneer
      wheel
    ]
    ++ versioneer.optional-dependencies.toml;

    enableParallelBuilding = true;

    dependencies = [
      numpy
      python-dateutil
      pytz
      tzdata
    ];

    optional-dependencies =
      let
        extras = {
          aws = [ s3fs ];
          clipboard = [
            pyqt5
            qtpy
          ];
          compression = [ zstandard ];
          computation = [
            scipy
            xarray
          ];
          excel = [
            odfpy
            openpyxl
            pyxlsb
            xlrd
            xlsxwriter
          ];
          feather = [ pyarrow ];
          fss = [ fsspec ];
          gcp = [
            gcsfs
            # TODO: pandas-gqb
          ];
          hdf5 = [
            blosc2
            tables
          ];
          html = [
            beautifulsoup4
            html5lib
            lxml
          ];
          mysql = [
            sqlalchemy
            pymysql
          ];
          output_formatting = [
            jinja2
            tabulate
          ];
          parquet = [ pyarrow ];
          performance = [
            bottleneck
            numba
            numexpr
          ];
          plot = [ matplotlib ];
          postgresql = [
            sqlalchemy
            psycopg2
          ];
          spss = [ pyreadstat ];
          sql-other = [ sqlalchemy ];
          xml = [ lxml ];
        };
      in
      extras // { all = lib.concatLists (lib.attrValues extras); };

    doCheck = false; # various infinite recursions

    passthru.tests.pytest = pandas.overridePythonAttrs (_: {
      doCheck = true;
    });

    nativeCheckInputs = [
      hypothesis
      pytest-asyncio
      pytest-xdist
      pytestCheckHook
    ]
    ++ lib.concatAttrValues optional-dependencies
    ++ lib.optionals (stdenv.hostPlatform.isLinux) [
      # for locale executable
      glibc
    ]
    ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
      # for locale executable
      adv_cmds
    ];

    # don't max out build cores, it breaks tests
    dontUsePytestXdist = true;

    __darwinAllowLocalNetworking = true;

    pytestFlags = [
      # https://github.com/pandas-dev/pandas/issues/54907
      "--no-strict-data-files"
      "--numprocesses=4"
    ];

    disabledTestMarks = [
      # https://github.com/pandas-dev/pandas/blob/main/test_fast.sh
      "single_cpu"
      "slow"
      "network"
      "db"
      "slow_arm"
    ];

    disabledTests = [
      # AssertionError: Did not see expected warning of class 'FutureWarning'
      "test_parsing_tzlocal_deprecated"
    ]
    ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
      # tests/generic/test_finalize.py::test_binops[and_-args4-right] - AssertionError: assert {} == {'a': 1}
      "test_binops"
      # These tests are unreliable on aarch64-darwin. See https://github.com/pandas-dev/pandas/issues/38921.
      "test_rolling"
    ]
    ++ lib.optional stdenv.hostPlatform.is32bit [
      # https://github.com/pandas-dev/pandas/issues/37398
      "test_rolling_var_numerical_issues"
    ];

    # Tests have relative paths, and need to reference compiled C extensions
    # so change directory where `import .test` is able to be resolved
    preCheck = ''
      export HOME=$TMPDIR
      cd $out/${python.sitePackages}/pandas
    ''
    # TODO: Get locale and clipboard support working on darwin.
    #       Until then we disable the tests.
    + lib.optionalString stdenv.hostPlatform.isDarwin ''
      # Fake the impure dependencies pbpaste and pbcopy
      echo "#!${runtimeShell}" > pbcopy
      echo "#!${runtimeShell}" > pbpaste
      chmod a+x pbcopy pbpaste
      export PATH=$(pwd):$PATH
    '';

    pythonImportsCheck = [ "pandas" ];

    meta = {
      # pandas devs no longer test i686, it's commonly broken
      # broken = stdenv.hostPlatform.isi686;
      changelog = "https://pandas.pydata.org/docs/whatsnew/index.html";
      description = "Powerful data structures for data analysis, time series, and statistics";
      downloadPage = "https://github.com/pandas-dev/pandas";
      homepage = "https://pandas.pydata.org";
      license = lib.licenses.bsd3;
      longDescription = ''
        Flexible and powerful data analysis / manipulation library for
        Python, providing labeled data structures similar to R data.frame
        objects, statistical functions, and much more.
      '';
      maintainers = with lib.maintainers; [
        raskin
      ];
    };
  };
in
pandas