Visitar URL original
fix: Use group_by in Polars backend aggregation by YHC66 · Pull Request #6965 · feast-dev/feast · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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 <yhc0720@berkeley.edu>
  • Loading branch information
YHC66 committed Oct 7, 2026
commit dea6862f220e7183f0dbb4b70d92aab556d0c99c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions sdk/python/tests/unit/infra/compute_engines/local/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))}
Expand Down
Loading