10 pkgs, # zstd hidden by python3Packages.zstd
12 pytest-codspeed ? null, # Not in Nixpkgs
23 # Another alternative is to try `mimalloc`
24 polarsMemoryAllocator ? mimalloc, # polarsJemalloc,
27 jemalloc' = rust-jemalloc-sys.override {
28 jemalloc = jemalloc.override {
29 # "libjemalloc.so.2: cannot allocate memory in static TLS block"
31 # https://github.com/pola-rs/polars/issues/5401#issuecomment-1300998316
32 disableInitExecTls = true;
36 assert builtins.elem "--disable-initial-exec-tls" jemalloc'.configureFlags;
46 # Hide symbols to prevent accidental use
47 rust-jemalloc-sys = throw "polars: use polarsMemoryAllocator over rust-jemalloc-sys";
48 jemalloc = throw "polars: use polarsMemoryAllocator over jemalloc";
55 src = fetchFromGitHub {
58 rev = "py-${version}";
59 hash = "sha256-q//vt8FvVKY9N/BOIoOwxaSB/F/tNX1Zl/9jd0AzSH4=";
62 # Do not type-check assertions because some of them use unstable features (`is_none_or`)
64 while IFS= read -r -d "" path ; do
65 sed -i 's \(\s*\)debug_assert! \1#[cfg(debug_assertions)]\n\1debug_assert! ' "$path"
66 done < <( find -iname '*.rs' -print0 )
69 cargoDeps = rustPlatform.importCargoLock {
70 lockFile = ./Cargo.lock;
72 "numpy-0.21.0" = "sha256-u0Z+6L8pXSPaA3cE1sUpY6sCoaU1clXUcj/avnNzmsw=";
73 "polars-parquet-format-2.10.0" = "sha256-iB3KZ72JSp7tJCLn9moukpDEGf9MUos04rIQ9rDGWfI=";
77 requiredSystemFeatures = [ "big-parallel" ];
79 build-system = [ rustPlatform.maturinBuildHook ];
85 rustPlatform.cargoSetupHook
86 rustPlatform.cargoBuildHook
87 rustPlatform.cargoInstallHook
94 (pkgs.__splicedPackages.zstd or pkgs.zstd)
96 ++ lib.optionals stdenv.hostPlatform.isDarwin [
97 darwin.apple_sdk.frameworks.AppKit
98 darwin.apple_sdk.frameworks.IOKit
99 darwin.apple_sdk.frameworks.Security
103 ZSTD_SYS_USE_PKG_CONFIG = true;
105 # https://github.com/NixOS/nixpkgs/blob/5c38beb516f8da3a823d94b746dd3bf3c6b9bbd7/doc/languages-frameworks/rust.section.md#using-community-maintained-rust-toolchains-using-community-maintained-rust-toolchains
106 # https://discourse.nixos.org/t/nixpkgs-rustplatform-and-nightly/22870
107 RUSTC_BOOTSTRAP = true;
109 # Several `debug_assert!` statements use the unstable `Option::is_none_or` method
110 RUSTFLAGS = lib.concatStringsSep " " (
112 "-Cdebug_assertions=n"
114 ++ lib.optionals (polarsMemoryAllocator.pname == "mimalloc") [
118 RUST_BACKTRACE = true;
121 dontUseCmakeConfigure = true;
123 maturinBuildFlags = [
125 "py-polars/Cargo.toml"
129 # Move polars.abi3.so -> polars.so
132 while IFS= read -r -d "" p ; do
134 soName="$(basename "$polarsSo")"
135 [[ "$soName" == polars.so ]] && break
136 done < <( find "$out" -iname "polars*.so" -print0 )
137 [[ -z "''${polarsSo:-}" ]] && echo "polars.so not found" >&2 && exit 1
138 if [[ "$soName" != polars.so ]] ; then
139 mv "$polarsSo" "$(dirname "$polarsSo")/polars.so"
143 pythonImportsCheck = [
147 passthru.tests.dynloading-1 =
148 runCommand "polars-dynloading-1"
150 nativeBuildInputs = [
151 (python.withPackages (ps: [
158 ((LD_DEBUG=libs python) |& tee $out | tail) << \EOF
164 passthru.tests.dynloading-2 =
165 runCommand "polars-dynloading-2"
167 nativeBuildInputs = [
168 (python.withPackages (ps: [
174 sed "s/^/ /" $out >&2
178 ((LD_DEBUG=libs python) |& tee $out | tail) << \EOF
183 passthru.tests.pytest = stdenv.mkDerivation {
184 pname = "${polars.pname}-pytest";
186 inherit (polars) version src;
188 requiredSystemFeatures = [ "big-parallel" ];
190 sourceRoot = "source/py-polars";
193 [[ "$f" == "tests" ]] || \
194 [[ "$f" == "pyproject.toml" ]] || \
197 for pat in "__pycache__" "*.pyc" ; do
198 find -iname "$pat" -exec rm "{}" ";"
201 dontConfigure = true;
205 checkPhase = "pytestCheckPhase";
206 nativeBuildInputs = [
207 (python.withPackages (ps: [
228 (ps.pyiceberg or null)
237 nativeCheckInputs = [
248 ''-m "slow or not slow"''
251 "test_read_kuzu_graph_database" # kuzu
252 "test_read_database_cx_credentials" # connectorx
255 "test_write_database_append_replace"
256 "test_write_database_create"
257 "test_write_database_create_quoted_tablename"
258 "test_write_database_adbc_temporary_table"
259 "test_write_database_create"
260 "test_write_database_append_replace"
261 "test_write_database_errors"
262 "test_write_database_errors"
263 "test_write_database_create_quoted_tablename"
269 "test_pickle_lazyframe_nested_function_udf"
273 disabledTestPaths = [
277 "tests/unit/io/test_iceberg.py" # Package pyiceberg
278 "tests/unit/io/test_spreadsheet.py" # Package fastexcel
280 # Wrong altair version
281 "tests/unit/operations/namespaces/test_plot.py"
284 "tests/unit/io/database/test_read.py"
287 "tests/unit/cloud/test_prepare_cloud_plan.py"
288 "tests/unit/io/cloud/test_cloud.py"
291 installPhase = "touch $out";
295 description = "Dataframes powered by a multithreaded, vectorized query engine, written in Rust";
296 homepage = "https://github.com/pola-rs/polars";
297 license = lib.licenses.mit;
298 maintainers = with lib.maintainers; [
302 mainProgram = "polars";
303 platforms = lib.platforms.all;