Polars 2.2 is out. This post gives an overview of the highlights grouped by area. Everything else is in the release notes.
Upgrade with:
pip install -U polars
Before you upgrade
Six changes may need your attention:
#31026– Return character offsets instr.findandstr.find_many.pl.Series(["héllo"]).str.find("l")used to return the byte offset3and now returns2. For byte offsets, use the newbin.findandbin.find_many#30914– Require scalar function arguments at plan time. Arguments such as thenofhead, thekoftop_kor the quantile ofquantilemust now be a scalar when the query is planned.pl.col("a").head(pl.col("n").head(1))used to run when it happened to return one row and now raises aShapeError; use.first()or.item()instead#30869– Make SQLDELETEchange the registered table in aSQLContext. Later queries on the table no longer see the deleted rows, andDELETE FROM (subquery)is an error#30942– Makemedian,mean,quantileandsumconsistent across dtypes and contexts.Series.mean()andSeries.median()onString,Categorical,List,Structand similar dtypes used to returnNoneand now raise, as the expressions already did.sumof aDate,Datetime,Time,CategoricalorEnumcolumn now raises in every context, also in agroup_bywhere it used to return nulls#30493– ReturnInt64from SQL string length, position and date part functions. They used to returnUInt32orInt32#30243– Raise on extra keys infrom_dicts. Keys that didn’t appear in the firstinfer_schema_lengthdicts used to be dropped silently. Increaseinfer_schema_lengthor pass the fullschema
Out-of-core joins
In 2.1 the group-by learned to spill to disk. In this release joins follow. When the build side of a streaming equi-join doesn’t fit in the memory budget, the join splits it into partitions by key hash, builds the hash tables of the partitions that fit in memory and spills the rest to disk. This release Polars is also better at the bookkeeping required to spill.
#30679– Run equi-joins out of core when the build side is larger than the memory budget#30558– Make the build side of the streaming equi-join fully spillable#30524– Add a memory grant system, so operators that need hash tables share the memory budget instead of each taking a fixed share#30496– Store rows once in unordered streaming windows under memory pressure#30749– Use a purge-before-grow dirty page strategy in jemalloc while running out of core#30838– Lower the default out-of-core dirty page limit to 0.8 of total memory
SQL
SQL is again the largest area of this release. Tables registered in a SQLContext can now be changed with INSERT, UPDATE, DELETE and COPY, and many statements and functions from other databases now work in Polars.
#30958– SupportINSERTandUPDATEon registered tables#30975– SupportCOPY <table> FROM '<file>'on registered tables#30834– SupportCOPY ... TO '<file>'#30778– SupportCREATE VIEW,DROP VIEWandDESCRIBE#30840– Support query parameters, passed withSQLContext.execute(..., params=...)#30852– Support SQL macros#30799– SupportPIVOT,UNPIVOTandPOSITIONAL JOIN#30467– Support derived tables that read the relations joined before them (LATERAL)#30453– Support correlated subqueries withGROUP BY#30763– AddBOOL_AND,BOOL_OR,ANY_VALUE,COUNT_IF,MAX_BY,MIN_BY,APPROX_COUNT_DISTINCTandREGEXP_EXTRACT#30809– AddTO_CHAR,TO_DATE,TO_TIMESTAMP,TYPEOF,REGEXP_MATCHESand JSON text access#30442– SupportPERCENTILE_CONTandPERCENTILE_DISCwithWITHIN GROUP#30849– Support offsets inRANGEwindow frames#31017– SupportUNNEST ... WITH ORDINALITY#30819– SupportSELECTalias reuse andinformation_schema.columns#30825– AddSQLContext(allow_file_reads=False)to turn off reading files from SQL
Iceberg
In 2.1 you could attach an Iceberg catalog to a SQLContext and create and drop tables in it. Now you can also write to those tables, change them and maintain them from SQL.
#30463– SupportINSERT INTOandINSERT OVERWRITEon attached catalog tables#30603– SupportUPDATEon attached catalog tables#30530– SupportDELETEon attached catalog tables#30633– SupportMERGE INTOon attached catalog tables#30267– SupportCREATE TABLE ... AS SELECTin attached catalogs#30436– SupportALTER TABLEon attached catalog tables#30756– Support partition evolution on attached catalog tables#30751– Support time travel on attached catalog tables#30888– Support tags and branches on attached catalog tables#30697– Read Iceberg metadata tables in SQL (lake.ns.t$snapshots)#30856– SupportCALL rewrite_data_filesto compact catalog tables#30974– SupportCALL add_fileson attached catalog tables#30690– Answer min, max and counts over an Iceberg scan from manifest statistics#30620– Accept a catalog name inscan_iceberg, resolved where the plan runs
Databases, Delta and Parquet
#30331– Addscan_databaseto read a database table or query lazily, with projections, filters and limits pushed into the SQL#30721– Write Delta tables with the native Parquet sink, in parallel#30359– Allow using a KMS for Parquet encryption#30816– Make Parquet encryption and decryption properties serializable#30737– Support per-row bounding box (bbox covering) columns in experimental GeoParquet
Smaller additions
#30950– Support a pattern per row instr.replaceandstr.replace_all#30835– Add format specifications topl.formatand SQLPRINTFandFORMAT#30875– Allow reading other columns inlist.eval,arr.evalandcumulative_eval#30826– Addstr.from_code_pointand SQLCHR#30318– Support more dtypes inapprox_quantile#30861– Release free-threaded Python wheels using the stable ABI
Performance
This release has 111 performance PRs. These are the ones you are most likely to notice:
Joins
#30708– Pack multi-column join and group-by keys into fixed-width integers#30681– Use estimated rows to choose the build side of streaming equi-joins#30662– Use an exact bitset as runtime filter for integer join keys in a small range#30651– Use a hash join for outer joins on an equality and a condition on one input#30692– Skip the probe side of joins without non-null build keys
Group-by and aggregations
#30813– Reduce runs of consecutive rows of one group as slices in the streaming group-by#30808– Reduce runs of equal groups locally insum,mean,minandmax#30569– Compute quantiles and quantile and rank bins by selection instead of sorting#31062– Run streaming cumulative aggregations in parallel#29445– Speed uprolling_minandrolling_maxwith a van Herk block scan#30636– Use the streaming group-by forvalue_countswithsortornormalize
Optimizer
#30694– Move inner, semi and anti joins below left joins in more cases#30680– Use column equalities between joined inputs as join keys when reordering joins#30598– Prune unused struct fields in projection pushdown#30802– Skip files by predicates on theinclude_file_pathscolumn#30773– Rewriteget(arg_max())tomax_by
Parquet, CSV and cloud
#30522– Keep dictionary-encoded ParquetStringcolumns as dictionaries in memory#30601– Speed up decoding of ParquetStruct,Map,ArrayandListrows#30982– Avoid redundant dictionary scans and byte-array copies in Parquet writes#30639– Parse CSV a column at a time over a mask-based field index#30102– Let the cloud read rate limiter follow demand#30966– Abandon stalled cloud reads after a stall timeout
Kernels
#30704– VectorizeDecimalmean and sum#30777– Compute date parts with integer arithmetic#30604– Add a dedicated kernel forconcat_list#30261– Trim leading and trailing.*fromstr.containsregexes
Bug fixes
Some of the bug fixes in this release:
Wrong results
#30682– Don’t create spurious nulls inwhen/then/otherwise#30315– Keep row order forwhen/then/otherwisewith literal branches#30310– Keep null rows foris_null() & ~is_in(..., nulls_equal=True)filters#30330– Use the exact join column mapping in projection and predicate pushdown#30817– Keep deleted rows deleted indelete_icebergandsink_icebergoverwrites#30412– Fix a slice returning too many rows when an Iceberg position delete is past the end of the file#30454– Apply Delta deletion vectors to files in escaped partition paths#30313– Don’t drop rows after an empty chunk inwrite_json#30743– Return null instead of silently overflowing in the temporaltotal_*functions#31048– Fix a streaming window over a literal returning 0 rows
Hangs, panics and crashes
#31021– Fix a race condition in the spill token waiters#30361– Prevent ato_pandas()deadlock withmap_elementson another thread#30665– Avoid a segfault on environment changes after a cloud scan#30458– Fix segfaults and leaked references withObjectvalues in group contexts#30886– Turn panics in Arrow C stream callbacks into stream errors#30940– Don’t panic on extreme counts in string, binary and list slicing
Other fixes
#30897– Lower the cloud connect timeout from 300 to 10 seconds and addPOLARS_HTTP_READ_TIMEOUT_SECONDSandPOLARS_HTTP_REQUEST_TIMEOUT_SECONDS#30279– Don’t finish a sink’s output file when its query fails#29450– Report the failing object path in object-store errors#30052– Load Delta partition values from the log inscan_delta
Last words
Thanks to everyone who contributed code or filed an issue for this release. If something breaks after upgrading, please let us know.
