Scalar#

2026-03-11

20 min read time

Applies to Linux

class pylibhipdf.scalar.Scalar(*args, **kwargs)#

Bases: object

A scalar value in device memory.

This is the Cython representation of cudf::scalar.

__init__(*args, **kwargs)#
static from_arrow(pa_val, dtype: DataType | None = None, stream: Stream | None = None) Scalar#

Convert a pyarrow scalar to a pylibcudf.Scalar.

Parameters#

pa_val: pyarrow scalar

Value to convert to a pylibcudf.Scalar

dtype: DataType | None

The datatype to cast the value to. If None, the type is inferred from the pyarrow scalar.

streamStream | None

CUDA stream on which to perform the operation.

Returns#

Scalar

New pylibcudf.Scalar

classmethod from_numpy(cls, np_val, stream: Stream | None = None)#

Convert a NumPy scalar to a Scalar.

Parameters#

np_val: numpy.generic

Value to convert to a pylibcudf.Scalar

streamStream | None

CUDA stream on which to perform the operation.

Returns#

Scalar

New pylibcudf.Scalar

classmethod from_py(cls, py_val, dtype: DataType | None = None, stream: Stream | None = None)#

Convert a Python standard library object to a Scalar.

Parameters#

py_val: None, bool, int, float, str, datetime, timedelta, list, dict

Value to convert to a pylibcudf.Scalar

dtype: DataType | None

The datatype to cast the value to. If None, the type is inferred from py_val.

streamStream | None

CUDA stream on which to perform the operation.

Returns#

Scalar

New pylibcudf.Scalar

is_valid(self) bool#

True if the scalar is valid, false if not

to_arrow(self, metadata: list[ColumnMetadata] | str | None = None, Stream stream: Stream = None) ArrowLike#

Create a PyArrow array from a pylibcudf scalar.

Parameters#

metadatalist

The metadata to attach to the columns of the table.

streamStream | None

CUDA stream on which to perform the operation.

Returns#

pyarrow.Scalar

to_py(self)#

Convert a Scalar to a Python scalar.

Returns#

Python scalar

A Python scalar associated with the type of the Scalar.

type(self) DataType#

The type of data in the column.