From 8019730fbdf898fbc5caafdd9f5d8a6bae9560ad Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 28 Feb 2024 21:06:39 +0000 Subject: [PATCH] Enable creation of columns from scalar --- python/cudf/cudf/_lib/pylibcudf/column.pyx | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/python/cudf/cudf/_lib/pylibcudf/column.pyx b/python/cudf/cudf/_lib/pylibcudf/column.pyx index 2a7215099d5..62a83efa3e2 100644 --- a/python/cudf/cudf/_lib/pylibcudf/column.pyx +++ b/python/cudf/cudf/_lib/pylibcudf/column.pyx @@ -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 @@ -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