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 6 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
7 changes: 5 additions & 2 deletions python/cudf/cudf/_lib/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ cdef class Column:
)

if value is not None:
required_size = bitmask_allocation_size_bytes(self.base_size)
# bitmask size must be relative to offset = 0 data.
required_size = bitmask_allocation_size_bytes(
self._size + self._offset
)
if value.size < required_size:
error_msg = (
"The Buffer for mask is smaller than expected, "
Expand Down Expand Up @@ -605,7 +608,7 @@ cdef class Column:
else:
mask = as_buffer(
data=mask_ptr,
size=bitmask_allocation_size_bytes(base_size),
size=bitmask_allocation_size_bytes(size+offset),
owner=mask_owner,
exposed=True
)
Expand Down
12 changes: 11 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,13 @@ 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)])
def test_struct_empty_children_nulls_slice(indices):
values = [None, {}, {}, None]

s = cudf.Series([None, {}, {}, None])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse the input from the previous line if it’s equivalent.

Suggested change
s = cudf.Series([None, {}, {}, None])
s = cudf.Series(values)

actual = s.iloc[indices]
expect = cudf.Series(values[indices], index=range(len(values))[indices])
assert_eq(actual, expect)