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

Correctly set bitmask size in from_column_view #13315

Merged
merged 9 commits into from
May 17, 2023
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
3 changes: 2 additions & 1 deletion python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ cdef class Column:
)

if value is not None:
# bitmask size must be relative to offset = 0 data.
required_size = bitmask_allocation_size_bytes(self.base_size)
if value.size < required_size:
error_msg = (
Expand Down Expand Up @@ -599,7 +600,7 @@ cdef class Column:
mask = as_buffer(
rmm.DeviceBuffer(
ptr=mask_ptr,
size=bitmask_allocation_size_bytes(size+offset)
size=bitmask_allocation_size_bytes(base_size)
wence- marked this conversation as resolved.
Show resolved Hide resolved
)
)
else:
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/column/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class StructColumn(ColumnBase):

@property
def base_size(self):
if not self.base_children:
return 0
else:
if self.base_children:
wence- marked this conversation as resolved.
Show resolved Hide resolved
return len(self.base_children[0])
else:
return self.size + self.offset

def to_arrow(self):
children = [
Expand Down
19 changes: 18 additions & 1 deletion python/cudf/cudf/tests/test_struct.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -392,3 +392,20 @@ def test_struct_with_null_memory_usage():

s[2:4] = None
assert s.memory_usage() == 272


@pytest.mark.parametrize(
"indices",
[slice(0, 3), slice(1, 4), slice(None, None, 2), slice(1, None, 2)],
ids=[":3", "1:4", "0::2", "1::2"],
)
@pytest.mark.parametrize(
"values",
[[None, {}, {}, None], [{}, {}, {}, {}]],
ids=["nulls", "no_nulls"],
)
def test_struct_empty_children_slice(indices, values):
s = cudf.Series(values)
actual = s.iloc[indices]
expect = cudf.Series(values[indices], index=range(len(values))[indices])
assert_eq(actual, expect)