Skip to content

Commit

Permalink
fix: Fix gather_every for Scalar (#19964)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Nov 25, 2024
1 parent 84a68a7 commit 742c737
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/polars-core/src/frame/column/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,10 @@ impl Column {
match self {
Column::Series(s) => s.gather_every(n, offset).into(),
Column::Partitioned(s) => s.as_materialized_series().gather_every(n, offset).into(),
Column::Scalar(s) => s.resize(s.len() - offset / n).into(),
Column::Scalar(s) => {
let total = s.len() - offset;
s.resize(1 + (total - 1) / n).into()
},
}
}

Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/unit/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ def test_null_literals(dtype: pl.DataType) -> None:
.collect_schema()
.dtypes()
) == [pl.Int64, dtype]


def test_scalar_19957() -> None:
value = 1
values = [value] * 5
foo = pl.DataFrame({"foo": values})
foo_with_bar_from_literal = foo.with_columns(pl.lit(value).alias("bar"))
assert foo_with_bar_from_literal.gather_every(2).to_dict(as_series=False) == {
"foo": [1, 1, 1],
"bar": [1, 1, 1],
}

0 comments on commit 742c737

Please sign in to comment.