Skip to content

Commit a38e4dc

Browse files
wtnclaude
andcommitted
fix: Make sum on strings error in group_by context
Co-authored-by: Claude <[email protected]>
1 parent 76758c7 commit a38e4dc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/polars-core/src/series/implementations/string.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ impl private::PrivateSeries for SeriesWrap<StringChunked> {
6969
self.0.agg_max(groups)
7070
}
7171

72+
#[cfg(feature = "algorithm_group_by")]
73+
unsafe fn agg_sum(&self, _groups: &GroupsType) -> Series {
74+
invalid_operation_panic!(agg_sum, self)
75+
}
76+
7277
fn subtract(&self, rhs: &Series) -> PolarsResult<Series> {
7378
NumOpsDispatch::subtract(&self.0, rhs)
7479
}

py-polars/tests/unit/operations/test_group_by.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import polars as pl
1313
import polars.selectors as cs
1414
from polars import Expr
15-
from polars.exceptions import ColumnNotFoundError
15+
from polars.exceptions import (
16+
ColumnNotFoundError,
17+
InvalidOperationError,
18+
)
1619
from polars.meta import get_index_type
1720
from polars.testing import assert_frame_equal, assert_series_equal
1821
from polars.testing.parametric import column, dataframes, series
@@ -2724,3 +2727,10 @@ def test_agg_first_last_non_null_25405() -> None:
27242727
}
27252728
)
27262729
assert_frame_equal(result.collect(), expected)
2730+
2731+
2732+
def test_group_by_sum_on_strings_should_error_24659() -> None:
2733+
with pytest.raises(
2734+
InvalidOperationError, match=r"sum.*operation not supported for dtype.*str"
2735+
):
2736+
pl.DataFrame({"str": ["a", "b"]}).group_by(1).agg(pl.col.str.sum())

0 commit comments

Comments
 (0)