polars - Rust |の高速マルチスレッド、ハイブリッドストリーミングデータフレームライブラリパイソン|ノード.js

(Fast multi-threaded, hybrid-streaming DataFrame library in Rust | Python | Node.js)

Created at: 2020-05-14 03:45:33
Language: Rust
License: MIT


ドキュメント: Python - Rust - Node.js |StackOverflow: Python - Rust - Node.js |ユーザーガイド|不和

Polars: Rust, Python & Node の超高速データフレーム.js

Polarsは、メモリモデルとしてApache Arrowカラム形式を使用してRustに実装された非常に高速なデータフレームライブラリです。

  • 怠惰な|熱心な実行
  • マルチスレッド
  • シムド
  • クエリの最適化
  • 強力な式 API
  • ハイブリッド ストリーミング (RAM データセットより大きい)
  • さび|パイソン|ノードJS |...

詳細については、ユーザーガイドをお読みください。

>>> import polars as pl
>>> 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)
┌──────────┬──────────┬──────────────┬─────┬─────────────┬─────────────┬─────────────┬─────────────┐
│ fruitscarsliteral_striBsum_A_by_casum_A_by_frrev_A_by_frsort_A_by_B │
│ ------ng_fruits---rsuitsuits_by_fruits  │
│ strstr---i64------------         │
│          ┆          ┆ str          ┆     ┆ i64i64i64i64         │
╞══════════╪══════════╪══════════════╪═════╪═════════════╪═════════════╪═════════════╪═════════════╡
│ "apple""beetle""fruits"114744           │
│ "apple""beetle""fruits"114733           │
│ "banana""beetle""fruits"114855           │
│ "banana""audi""fruits"112822           │
│ "banana""beetle""fruits"114811           │
└──────────┴──────────┴──────────────┴─────┴─────────────┴─────────────┴─────────────┴─────────────┘

パフォーマンス 🚀🚀

猛烈な速さ

極は非常に高速です。実際、これは利用可能な最高のパフォーマンスを発揮するソリューションの1つです。 h2oaiのdbベンチマークで結果を参照してください。

TPCHベンチマークでは、極地はパンダ、ダスク、モディン、ベイクスよりも桁違いに高速です。 完全なクエリ(IOを含む)で。

軽量

ポーラも非常に軽量です。必要な依存関係はゼロであり、これはインポート時間に表示されます。

  • 極性:70ms
  • ナンピー:104ms
  • パンダ:520ms

RAMデータよりも大きいデータを処理

メモリに収まらないデータがある場合、polars lazyはクエリ(またはクエリの一部)を ストリーミング方式では、これによりメモリ要件が大幅に削減されるため、250GBのデータセットを処理できる可能性があります。 ラップトップ。[収集] をクリックして、クエリ ストリーミングを実行します。(これは少し遅いかもしれませんが、 それはまだ非常に速いです!

collect(streaming=True)

セットアップ

ニシキヘビ

以下を使用して最新の極性バージョンをインストールします。

pip install polars

condaパッケージ()もありますが、Polarsをインストールするにはpipが推奨される方法です。

conda install polars

すべてのオプションの依存関係を使用して Polars をインストールします。

pip install 'polars[all]'
pip install 'polars[numpy,pandas,pyarrow]'  # install a subset of all optional dependencies

You can also install the dependencies directly.

Tag Description
all Install all optional dependencies (all of the following)
pandas Install with Pandas for converting data to and from Pandas Dataframes/Series
numpy Install with numpy for converting data to and from numpy arrays
pyarrow Reading data formats using PyArrow
fsspec Support for reading from remote file systems
connectorx Support for reading from SQL databases
xlsx2csv Support for reading from Excel files
deltalake Support for reading from Delta Lake Tables
timezone Timezone support, only needed if 1. you are on Python < 3.9 and/or 2. you are on Windows, otherwise no dependencies will be installed

Releases 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

You can take latest release from , or if you want to use the latest features / performance improvements point to the branch of this repo.

crates.io
master

polars = { git = "https://github.com/pola-rs/polars", rev = "<optional git tag>" }

Required Rust version

>=1.58

Contributing

Want to contribute? Read our contribution guideline.

Python: compile polars from source

If you want a bleeding edge release or maximal performance you should compile polars from source.

This can be done by going through the following steps in sequence:

  1. Install the latest Rust compiler
  2. Install maturin:
    pip install maturin
  3. Choose any of:
    • Fastest binary, very long compile times:
      $ cd py-polars && maturin develop --release -- -C target-cpu=native
    • Fast binary, Shorter compile times:
      $ cd py-polars && maturin develop --release -- -C codegen-units=16 -C lto=thin -C target-cpu=native

Note that the Rust crate implementing the Python bindings is called to distinguish from the wrapped Rust crate itself. However, both the Python package and the Python module are named , so you can and .

py-polars
polars
polars
pip install polars
import polars

Arrow2

Polars has transitioned to arrow2. Arrow2 is a faster and safer implementation of the Apache Arrow Columnar Format. Arrow2 also has a more granular code base, helping to reduce the compiler bloat.

PythonでカスタムRust関数を使用しますか?

この例を参照してください。

大きくなる...

~42億行以上を見込んでいますか?機能フラグを使用して極性をコンパイルします。

2^32
bigidx

または、Pythonユーザーの場合は、をインストールします。

pip install polars-u64-idx

デフォルトの極が高速でメモリ消費量が少ないため、行の境界にぶつからない限り、これを使用しないでください。

遺産

極性を古いCPUで実行したいですか(たとえば、2011年より前のもの)?取り付ける。この極地プロジェクトは AVX ターゲット機能なしでコンパイルされます。

pip polars-lts-cpu

確認

ポーラーズの開発は誇らしげに力を与えられています

ゾムニア

スポンサー