Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Properly slice validity mask on pl.Object series #18631

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion crates/polars-core/src/chunked_array/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,11 @@ where

unsafe fn slice_unchecked(&mut self, offset: usize, length: usize) {
let len = std::cmp::min(self.len - offset, length);

self.null_bitmap = self
.null_bitmap
.take()
.map(|bitmap| bitmap.sliced_unchecked(offset, length))
.filter(|bitmap| bitmap.unset_bits() > 0);
self.len = len;
self.offset = offset;
}
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/datatypes/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import polars as pl
from polars.exceptions import ComputeError
from polars.testing import assert_series_equal


def test_series_init_instantiated_object() -> None:
Expand Down Expand Up @@ -190,3 +191,11 @@ def test_raise_list_object() -> None:
# We don't want to support this. Unsafe enough as it is already.
with pytest.raises(ValueError):
pl.Series([[object()]], dtype=pl.List(pl.Object()))


def test_object_null_slice() -> None:
s = pl.Series("x", [1, None, 42], dtype=pl.Object)
assert_series_equal(s.is_null(), pl.Series("x", [False, True, False]))
assert_series_equal(s.slice(0, 2).is_null(), pl.Series("x", [False, True]))
assert_series_equal(s.slice(1, 1).is_null(), pl.Series("x", [True]))
assert_series_equal(s.slice(2, 1).is_null(), pl.Series("x", [False]))
Loading