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

Enable creation of columns from scalar #15181

Merged
Merged
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
26 changes: 26 additions & 0 deletions python/cudf/cudf/_lib/pylibcudf/column.pyx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

from cython.operator cimport dereference
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move

from rmm._lib.device_buffer cimport DeviceBuffer

from cudf._lib.cpp.column.column cimport column, column_contents
from cudf._lib.cpp.column.column_factories cimport make_column_from_scalar
from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.cpp.types cimport size_type

from .gpumemoryview cimport gpumemoryview
from .scalar cimport Scalar
from .types cimport DataType, type_id
from .utils cimport int_to_bitmask_ptr, int_to_void_ptr

Expand Down Expand Up @@ -196,6 +200,28 @@ cdef class Column:
children,
)

@staticmethod
def from_scalar(Scalar slr, size_type size):
"""Create a Column from a Scalar.

Parameters
----------
slr : Scalar
The scalar to create a column from.
size : size_type
The number of elements in the column.

Returns
-------
Column
A Column containing the scalar repeated `size` times.
"""
cdef const scalar* c_scalar = slr.get()
cdef unique_ptr[column] c_result
with nogil:
c_result = move(make_column_from_scalar(dereference(c_scalar), size))
return Column.from_libcudf(move(c_result))

cpdef DataType type(self):
"""The type of data in the column."""
return self._data_type
Expand Down
Loading