Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Jan 10, 2025
1 parent 4e0b80d commit 0f67946
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/polars-core/src/frame/column/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,20 @@ impl Column {
match self {
Column::Series(s) => s.rechunk().into(),
Column::Partitioned(_) => self.clone(),
Column::Scalar(_) => self.clone(),
Column::Scalar(s) => {
if s.lazy_as_materialized_series()
.filter(|x| x.n_chunks() > 1)
.is_some()
{
Column::Scalar(ScalarColumn::new(
s.name().clone(),
s.scalar().clone(),
s.len(),
))
} else {
self.clone()
}
},
}
}

Expand Down Expand Up @@ -1700,7 +1713,8 @@ impl Column {
pub fn n_chunks(&self) -> usize {
match self {
Column::Series(s) => s.n_chunks(),
Column::Scalar(_) | Column::Partitioned(_) => 1,
Column::Scalar(s) => s.lazy_as_materialized_series().map_or(1, |x| x.n_chunks()),
Column::Partitioned(_) => 1,
}
}

Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/unit/interop/test_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,8 @@ def test_from_arrow_string_cache_20271() -> None:
assert_series_equal(
df.to_series().to_physical(), pl.Series("b", [3, 4]), check_dtypes=False
)


def test_to_arrow_empty_chunks_20627() -> None:
df = pl.concat(2 * [pl.Series([1])]).filter(pl.Series([False, True])).to_frame()
assert df.to_arrow().shape == (1, 1)
5 changes: 5 additions & 0 deletions py-polars/tests/unit/test_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,8 @@ def test_scalar_identification_function_expr_in_binary() -> None:
pl.select(x).with_columns(o=pl.col("x").null_count() > 0),
pl.select(x, o=False),
)


def test_scalar_rechunk_20627() -> None:
df = pl.concat(2 * [pl.Series([1])]).filter(pl.Series([False, True])).to_frame()
assert df.rechunk().to_series().n_chunks() == 1

0 comments on commit 0f67946

Please sign in to comment.