From dea6862f220e7183f0dbb4b70d92aab556d0c99c Mon Sep 17 00:00:00 2001 From: Yihang Chen Date: Wed, 7 Oct 2026 10:18:57 -0700 Subject: [PATCH] fix: Use group_by in Polars backend aggregation polars removed DataFrame.groupby in 1.0 in favour of group_by, so PolarsBackend.groupby_agg raised AttributeError and any aggregation run by the local compute engine with backend=polars failed. Signed-off-by: Yihang Chen --- .../backends/polars_backend.py | 2 +- .../infra/compute_engines/local/test_nodes.py | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/sdk/python/feast/infra/compute_engines/backends/polars_backend.py b/sdk/python/feast/infra/compute_engines/backends/polars_backend.py index 118b0b8eab7..0038e31abe5 100644 --- a/sdk/python/feast/infra/compute_engines/backends/polars_backend.py +++ b/sdk/python/feast/infra/compute_engines/backends/polars_backend.py @@ -26,7 +26,7 @@ def groupby_agg(self, df: pl.DataFrame, group_keys, agg_ops) -> pl.DataFrame: getattr(pl.col(col), self._POLARS_FUNC_MAP.get(func, func))().alias(alias) for alias, (func, col) in agg_ops.items() ] - return df.groupby(group_keys).agg(agg_exprs) + return df.group_by(group_keys).agg(agg_exprs) def filter(self, df: pl.DataFrame, expr: str) -> pl.DataFrame: return df.filter(pl.sql_expr(expr)) diff --git a/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py b/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py index 872dd978c9e..f6d5e577455 100644 --- a/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py +++ b/sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py @@ -3,6 +3,7 @@ import pandas as pd import pyarrow as pa +import pytest from feast.infra.compute_engines.backends.pandas_backend import PandasBackend from feast.infra.compute_engines.dag.context import ColumnInfo, ExecutionContext @@ -104,6 +105,34 @@ def test_local_aggregation_node(): assert result_df["sum_value"].iloc[1] == 70 +def test_local_aggregation_node_polars_backend(): + pytest.importorskip("polars") + from feast.infra.compute_engines.backends.polars_backend import PolarsBackend + + context = create_context( + node_outputs={"source": ArrowTableValue(pa.Table.from_pandas(sample_df))} + ) + + agg_ops = { + "sum_value": ("sum", "value"), + "unique_value": ("nunique", "value"), + } + agg_node = LocalAggregationNode( + name="agg", + backend=PolarsBackend(), + group_keys=["entity_id"], + agg_ops=agg_ops, + ) + agg_node.add_input(MagicMock()) + agg_node.inputs[0].name = "source" + + result = agg_node.execute(context) + assert isinstance(result, ArrowTableValue) + result_df = result.data.to_pandas().sort_values("entity_id") + assert result_df["sum_value"].tolist() == [30, 70] + assert result_df["unique_value"].tolist() == [2, 2] + + def test_local_join_node(): context = create_context( node_outputs={"source": ArrowTableValue(pa.Table.from_pandas(sample_df))}