Package: polarscnj
Documentation:Python-Rust-Node.js|StackOverflow:Python-Rust-Node.js|User Guide|DiscordPolars: Blazingly fast DataFrames in Rust, Python & Node.jsPolars is a blazingly fast DataFrames library implemented in Rust usingApache Arrow Columnar Formatas the memory model.Lazy | eager executionMulti-threadedSIMDQuery optimizationPowerful expression APIHybrid Streaming (larger than RAM datasets)Rust | Python | NodeJS | ...To learn more, read theUser Guide.>>>importpolarsaspl>>>df=pl.DataFrame(...{..."A":[1,2,3,4,5],..."fruits":["banana","banana","apple","apple","banana"],..."B":[5,4,3,2,1],..."cars":["beetle","audi","beetle","beetle","beetle"],...}...)# embarrassingly parallel execution & very expressive query language>>>df.sort("fruits").select(...[..."fruits",..."cars",...pl.lit("fruits").alias("literal_string_fruits"),...pl.col("B").filter(pl.col("cars")=="beetle").sum(),...pl.col("A").filter(pl.col("B")>2).sum().over("cars").alias("sum_A_by_cars"),...pl.col("A").sum().over("fruits").alias("sum_A_by_fruits"),...pl.col("A").reverse().over("fruits").alias("rev_A_by_fruits"),...pl.col("A").sort_by("B").over("fruits").alias("sort_A_by_B_by_fruits"),...]...)shape:(5,8)┌──────────┬──────────┬──────────────┬─────┬─────────────┬─────────────┬─────────────┬─────────────┐│fruits┆cars┆literal_stri┆B┆sum_A_by_ca┆sum_A_by_fr┆rev_A_by_fr┆sort_A_by_B││---┆---┆ng_fruits┆---┆rs┆uits┆uits┆_by_fruits││str┆str┆---┆i64┆---┆---┆---┆---││┆┆str┆┆i64┆i64┆i64┆i64│╞══════════╪══════════╪══════════════╪═════╪═════════════╪═════════════╪═════════════╪═════════════╡│"apple"┆"beetle"┆"fruits"┆11┆4┆7┆4┆4│├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤│"apple"┆"beetle"┆"fruits"┆11┆4┆7┆3┆3│├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤│"banana"┆"beetle"┆"fruits"┆11┆4┆8┆5┆5│├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤│"banana"┆"audi"┆"fruits"┆11┆2┆8┆2┆2│├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤│"banana"┆"beetle"┆"fruits"┆11┆4┆8┆1┆1│└──────────┴──────────┴──────────────┴─────┴─────────────┴─────────────┴─────────────┴─────────────┘Performance 🚀🚀Polars is very fast. In fact, it is one of the best performing solutions available.
See the results inh2oai's db-benchmark.In theTPCH benchmarkspolars is orders of magnitudes faster than pandas, dask, modin and vaex
on full queries (including IO).Besides fast, polars is also very lightweight. It comes with zero required dependencies, and this shows in the import times:import time measurements:polars: 70msnumpy: 104mspandas: 520msPython setupInstall the latest polars version with:pipinstallpolarsWe also have a conda package (conda install polars), however pip is the preferred way to install Polars.Install Polars with all optional dependencies.pipinstall'polars[all]'pipinstall'polars[numpy,pandas,pyarrow]'# install a subset of all optional dependenciesYou can also install the dependencies directly.TagDescriptionallInstall all optional dependencies (all of the following)pandasInstall with Pandas for converting data to and from Pandas Dataframes/SeriesnumpyInstall with numpy for converting data to and from numpy arrayspyarrowReading data formats using PyArrowfsspecSupport for reading from remote file systemsconnectorxSupport for reading from SQL databasesxlsx2csvSupport for reading from Excel filestimezoneTimezone support, only needed if 1. you are on Python < 3.9 and/or 2. you are on Windows, otherwise no dependencies will be installedReleases happen quite often (weekly / every few days) at the moment, so updating polars regularly to get the latest bugfixes / features might not be a bad idea.Rust setupYou can take latest release fromcrates.io, or if you want to use the latest features / performance improvements
point to themasterbranch of this repo.polars={git="https://github.com/pola-rs/polars",rev="<optional git tag>"}Rust versionRequired Rust version>=1.58DocumentationWant to know about all the features Polars supports? Read the docs!Larger than RAM dataIf you have data that does not fit into memory, polars lazy is able to process your query (or parts of your query) in a
streaming fashion, this drastically reduces memory requirements you might be able to process your 250GB dataset on your
laptop. Collect withcollect(allow_streaming=True)to run the query streaming. (This might be a little slower, but
it is still very fast!)PythonInstallation guide:pip install polarsPython documentationUser guideRustRust documentation (master branch)User guideNodeInstallation guide:yarn add nodejs-polarsNode documentationUser guideGithubContributionWant to contribute? Read ourcontribution guideline.[Python]: compile polars from sourceIf you want a bleeding edge release or maximal performance you should compilepolarsfrom source.This can be done by going through the following steps in sequence:Install the latestRust compilerInstallmaturin:pip install maturinChoose any of:Fastest binary, very long compile times:$cdpy-polars&&maturindevelop--release---Ctarget-cpu=nativeFast binary, Shorter compile times:$cdpy-polars&&maturindevelop--release---Ccodegen-units=16-Clto=thin-Ctarget-cpu=nativeNote that the Rust crate implementing the Python bindings is calledpy-polarsto distinguish from the wrapped
Rust cratepolarsitself. However, both the Python package and the Python module are namedpolars, so you
canpip install polarsandimport polars.Arrow2Polars has transitioned toarrow2.
Arrow2 is a faster and safer implementation of theApache Arrow Columnar Format.
Arrow2 also has a more granular code base, helping to reduce the compiler bloat.Use custom Rust function in python?Seethis example.Going big...Do you expect more than2^32~4,2 billion rows? Compile polars with thebigidxfeature flag.Or for python users installpip install polars-u64-idx.Don't use this unless you hit the row boundary as the default polars is faster and consumes less memory.LegacyDo you want polars to run on an old CPU (e.g. dating from before 2011)? Installpip polars-lts-cpu. This polars project is
compiled withoutavxtarget features.AcknowledgementsDevelopment of Polars is proudly powered bySponsors