Skip to content

Commit

Permalink
Correctly set bitmask size in from_column_view
Browse files Browse the repository at this point in the history
An empty struct column (dtype of StructDtype({})) has no children, and
hence a base_size of zero. However, it may still have a non-zero size
and non-empty null mask. When slicing such a column, the mask size
must be transferred over correctly by inspecting the size and offset
of the owning column. Previously, we incorrectly determined the sliced
column to have a mask buffer of zero bytes in this case.

Closes #13305.
  • Loading branch information
wence- committed May 9, 2023
1 parent 34d6b07 commit 5d9801d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
10 changes: 8 additions & 2 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ cdef class Column:
)

if value is not None:
required_size = bitmask_allocation_size_bytes(self.base_size)
# base_size may be zero for a struct column with no
# children, but the column may have non-zero length.
required_size = bitmask_allocation_size_bytes(
max(self.base_size, self._size)
)
if value.size < required_size:
error_msg = (
"The Buffer for mask is smaller than expected, "
Expand Down Expand Up @@ -605,7 +609,9 @@ cdef class Column:
else:
mask = as_buffer(
data=mask_ptr,
size=bitmask_allocation_size_bytes(base_size),
size=bitmask_allocation_size_bytes(
max(size+offset, base_size)
),
owner=mask_owner,
exposed=True
)
Expand Down
13 changes: 1 addition & 12 deletions python/cudf/cudf/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,7 @@ def test_struct_with_null_memory_usage():
assert s.memory_usage() == 272


@pytest.mark.parametrize(
"zlice",
[
pytest.param(
slice(0, 3),
marks=pytest.mark.xfail(
reason="https://github.com/rapidsai/cudf/issues/13305"
),
),
slice(1, 4),
],
)
@pytest.mark.parametrize("zlice", [slice(0, 3), slice(1, 4)])
def test_struct_empty_children_nulls_slice(zlice):
values = [None, {}, {}, None]

Expand Down

0 comments on commit 5d9801d

Please sign in to comment.