返回

Snowpark Python Supports Native to_polars()

RSS Snowflake Engineering (Medium) 原文 · 未翻译 发布 2026-10-30 01:22

有效阅读仅保存在当前浏览器,用于「为你」推荐;暂停或清除记录。

DataHot 速览

Photo by Annie Spratt on Unsplash Snowpark Python’s DataFrame.to_polars() is now generally available, bringing Snowflake query results into a Polars DataFrame with a single call. Its default Parquet transport reads files in parallel to accelerate large data transfers, connecting data preparation in

原文

Snowpark Python’s DataFrame.to_polars() is now generally available, bringing Snowflake query results into a Polars DataFrame with a single call. Its default Parquet transport reads files in parallel to accelerate large data transfers, connecting data preparation in Snowflake with analytics and data processing in Polars.

Why it matters

Snowpark already supports pandas through to_pandas(). With to_polars(), we are extending that interoperability to developers who use Polars in their Python workflows.

You can use Snowpark to filter, join, and aggregate large datasets in Snowflake, then return the results as a Polars DataFrame for further processing. This lets you combine Snowflake’s data processing with your existing Polars application, using the same Snowpark session.

How to use it

With a configured Snowpark session and Polars installed, call to_polars() on a Snowpark DataFrame. Here is a small example:

import polars as pl
from snowflake.snowpark.functions import col

snowpark_df = session.create_dataframe(
    [["North", 120], ["South", 80], ["North", 200]],
    schema=["REGION", "REVENUE"],
).filter(col("REVENUE") >= 100)

polars_df = snowpark_df.to_polars()

# Continue processing with Polars.
summary = polars_df.group_by("REGION").agg(
    pl.col("REVENUE").sum()
)
print(summary)

In this example, calling to_polars() executes the Snowpark query, filtering out rows with revenue above 100 in Snowflake and returning the remaining rows as an eager Polars DataFrame. Polars then groups those rows by region and sums their revenue, producing one result: North with a total of 320. South is excluded by the filter.

Note

DataFrame.to_polars() uses Parquet transport by default. Snowpark unloads query results to the session stage as Parquet files and reads them in parallel into Polars. This can speed up large, transfer-heavy workloads, especially in Snowpark Python stored procedures.

Use to_polars(transport="arrow") when you need to preserve timezone-aware timestamps or full timestamp and floating-point precision. Parquet does not support TIMESTAMP_LTZ or TIMESTAMP_TZ columns, rounds TIMESTAMP_NTZ values to milliseconds, and reduces FLOAT precision to float32.

Both transports return a fully materialized DataFrame, so the result must fit in your Python environment’s memory. Filter rows and select the columns you need in Snowpark before converting; subsequent Polars operations run in your Python environment.

Get started

Use Snowpark Python 1.55.3 and Polars 1.0 or later. Start with a Snowpark DataFrame from your own workflow and call to_polars() to continue working with the results in Polars.

Explore the API reference for parameters and transport guidance.

Snowpark Python Supports Native to_polars() was originally published in Snowflake Builders Blog: Data Engineers, App Developers, AI, & Data Science on Medium, where people are continuing the conversation by highlighting and responding to this story.

这篇内容对你有用吗?

反馈只用于改善内容筛选,不等同于收藏

分享这条资讯
分享海报
保存图片
iOS 也可以长按图片保存