Skip to content

Commit

Permalink
fix: Return correct dtype for s.clear() when dtype is Object (#15315
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mcrumiller committed Mar 28, 2024
1 parent 85a5e38 commit 3888b86
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
20 changes: 10 additions & 10 deletions crates/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ impl Series {
}

pub fn clear(&self) -> Series {
// Only the inner of objects know their type, so use this hack.
#[cfg(feature = "object")]
if matches!(self.dtype(), DataType::Object(_, _)) {
return if self.is_empty() {
self.clone()
} else {
let av = self.get(0).unwrap();
Series::new(self.name(), [av]).slice(0, 0)
};
if self.is_empty() {
self.clone()
} else {
match self.dtype() {
#[cfg(feature = "object")]
DataType::Object(_, _) => self
.take(&ChunkedArray::<IdxType>::new_vec("", vec![]))
.unwrap(),
dt => Series::new_empty(self.name(), dt),
}
}
Series::new_empty(self.name(), self.dtype())
}

#[doc(hidden)]
Expand Down
1 change: 0 additions & 1 deletion py-polars/tests/unit/operations/test_clear.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def test_clear_lf() -> None:
assert ldfe.collect().rows() == [(None, None, None), (None, None, None)]


@pytest.mark.skip("Currently bugged: https://github.com/pola-rs/polars/issues/15303")
def test_clear_series_object_starting_with_null() -> None:
s = pl.Series([None, object()])

Expand Down

0 comments on commit 3888b86

Please sign in to comment.