Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 2 additions & 2 deletions python/pylibcudf/pylibcudf/aggregation.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from cython.operator cimport dereference
Expand Down Expand Up @@ -428,7 +428,7 @@ cpdef Aggregation median():
return Aggregation.from_libcudf(move(make_median_aggregation[aggregation]()))


cpdef Aggregation quantile(list quantiles, interpolation interp = interpolation.LINEAR):
cpdef Aggregation quantile(list quantiles: list[float], interpolation interp = interpolation.LINEAR):
"""Create a quantile aggregation.

For details, see :cpp:func:`make_quantile_aggregation`.
Expand Down
6 changes: 5 additions & 1 deletion python/pylibcudf/pylibcudf/binaryop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ from .scalar cimport Scalar
from .types cimport DataType
from .utils cimport _get_stream, _get_memory_resource
from cuda.bindings.cyruntime cimport cudaStream_t
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pylibcudf.utils import CudaStreamLike

__all__ = ["BinaryOperator", "binary_operation", "is_supported_operation"]

Expand All @@ -30,7 +34,7 @@ cpdef Column binary_operation(
RightBinaryOperand rhs,
binary_operator op,
DataType output_type,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Perform a binary operation between a column and another column or scalar.
Expand Down
70 changes: 52 additions & 18 deletions python/pylibcudf/pylibcudf/column.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from collections.abc import Iterable, Sequence
from cython.operator cimport dereference

from cpython.exc cimport PyErr_Occurred
Expand Down Expand Up @@ -58,15 +59,19 @@ from .traits cimport (
from .types cimport DataType, size_of, type_id
from pylibcudf.types import TypeId
from .utils cimport _get_stream, _get_memory_resource
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pylibcudf.utils import CudaStreamLike

from .gpumemoryview import _datatype_from_dtype_desc
from ._interop_helpers import ArrowLike, ColumnMetadata, _ObjectWithArrowMetadata

from itertools import accumulate
from typing import Iterable, Protocol, TypedDict
import array
import functools
import operator
from itertools import accumulate
from typing import Iterable
from cuda.bindings.cyruntime cimport cudaStream_t

try:
Expand All @@ -80,6 +85,23 @@ except ImportError as e:
__all__ = ["Column", "ListsColumnView", "StructsColumnView", "is_c_contiguous"]


class ArrayInterfaceBase(TypedDict):
data: tuple[int, bool]
shape: tuple[int, ...]
typestr: str
version: int


class SupportsCudaArrayInterface(Protocol):
@property
def __cuda_array_interface__(self) -> ArrayInterfaceBase: ...


class SupportsArrayInterface(Protocol):
@property
def __array_interface__(self) -> ArrayInterfaceBase: ...


Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
cdef is_iterable(obj):
try:
iter(obj)
Expand Down Expand Up @@ -157,7 +179,7 @@ class ArrayInterfaceWrapper:
self.__array_interface__ = iface


cdef gpumemoryview _copy_array_to_device(object buf, object stream=None):
cdef gpumemoryview _copy_array_to_device(object buf, object stream: CudaStreamLike | None = None):
"""
Copy a host-side array.array buffer to device memory.

Expand Down Expand Up @@ -346,7 +368,7 @@ cdef class Column:
def __init__(
self, DataType data_type not None, size_type size, object data,
object mask, size_type null_count, size_type offset,
children, bint validate=True
children: Iterable[Column], bint validate=True
):
children = list(children)
if not all(isinstance(c, Column) for c in children):
Expand Down Expand Up @@ -406,7 +428,7 @@ cdef class Column:
def from_arrow(
obj: ArrowLike,
dtype: DataType | None = None,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None
) -> ArrowLike:
"""
Expand Down Expand Up @@ -604,7 +626,7 @@ cdef class Column:
DeviceBuffer buff,
DataType dtype,
size_type size,
children,
children: Iterable[Column],
):
"""
Create a Column from an RMM DeviceBuffer.
Expand Down Expand Up @@ -813,7 +835,7 @@ cdef class Column:
def from_scalar(
Scalar slr,
size_type size,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Create a Column from a Scalar.
Expand Down Expand Up @@ -846,7 +868,7 @@ cdef class Column:
)
return Column.from_libcudf(move(c_result), _stream, mr)

cpdef Scalar to_scalar(self, object stream=None, DeviceMemoryResource mr=None):
cpdef Scalar to_scalar(self, object stream: CudaStreamLike | None = None, DeviceMemoryResource mr=None):
"""
Return the first value of 1-element column as a Scalar.

Expand Down Expand Up @@ -882,7 +904,7 @@ cdef class Column:
def all_null_like(
Column like,
size_type size,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Create an all null column from a template.
Expand Down Expand Up @@ -921,7 +943,7 @@ cdef class Column:
tuple shape,
DataType dtype,
Column base=None,
object stream=None,
object stream: CudaStreamLike | None = None,
):
"""
Construct a list Column from a gpumemoryview and array
Expand Down Expand Up @@ -974,7 +996,11 @@ cdef class Column:
return nested

@classmethod
def from_array_interface(cls, obj, object stream=None):
def from_array_interface(
cls,
obj: SupportsArrayInterface,
object stream: CudaStreamLike | None = None,
):
"""
Create a Column from an object implementing the NumPy Array Interface.

Expand Down Expand Up @@ -1028,7 +1054,11 @@ cdef class Column:
)

@classmethod
def from_cuda_array_interface(cls, obj, object stream=None):
def from_cuda_array_interface(
cls,
obj: SupportsCudaArrayInterface,
object stream: CudaStreamLike | None = None,
):
"""
Create a Column from an object implementing the CUDA Array Interface.

Expand Down Expand Up @@ -1067,7 +1097,11 @@ cdef class Column:
)

@classmethod
def from_array(cls, obj, object stream=None):
def from_array(
cls,
obj: SupportsCudaArrayInterface | SupportsArrayInterface,
object stream: CudaStreamLike | None = None,
):
"""
Create a Column from any object which supports the NumPy
or CUDA array interface.
Expand Down Expand Up @@ -1113,7 +1147,7 @@ cdef class Column:
def from_iterable_of_py(
obj: Iterable,
dtype: DataType | None = None,
object stream=None
object stream: CudaStreamLike | None = None
) -> Column:
"""
Create a Column from a Python iterable of scalar values or nested iterables.
Expand Down Expand Up @@ -1399,7 +1433,7 @@ cdef class Column:
"""The children of the column."""
return self._children

cpdef Column copy(self, object stream=None, DeviceMemoryResource mr=None):
cpdef Column copy(self, object stream: CudaStreamLike | None = None, DeviceMemoryResource mr=None):
"""Create a copy of the column."""
cdef unique_ptr[column] c_result
cdef Stream _stream = _get_stream(stream)
Expand Down Expand Up @@ -1461,7 +1495,7 @@ cdef class Column:

return PyCapsule_New(<void*>raw_schema_ptr, 'arrow_schema', _release_schema)

def _to_host_array(self, object stream):
def _to_host_array(self, object stream: CudaStreamLike):
cdef ArrowArray* raw_host_array_ptr
cdef Stream _stream = _get_stream(stream)
cdef cudaStream_t _cs = _stream.view().value()
Expand Down Expand Up @@ -1532,7 +1566,7 @@ cdef class ListsColumnView:
"""
return lists_column_view(self._column.view())

cpdef Column get_sliced_child(self, object stream=None):
cpdef Column get_sliced_child(self, object stream: CudaStreamLike | None = None):
"""
Get the list elements child properly sliced to match parent's view.

Expand Down Expand Up @@ -1570,7 +1604,7 @@ cdef class StructsColumnView:
"""
return structs_column_view(self._column.view())

cpdef Column get_sliced_child(self, int index, object stream=None):
cpdef Column get_sliced_child(self, int index, object stream: CudaStreamLike | None = None):
"""
Get the struct elements child properly sliced to match parent's view.

Expand Down
22 changes: 13 additions & 9 deletions python/pylibcudf/pylibcudf/column_factories.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move
Expand All @@ -20,6 +20,10 @@ from .types cimport DataType, type_id

from .types import MaskState, TypeId
from .utils cimport _get_stream, _get_memory_resource
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pylibcudf.utils import CudaStreamLike
from cuda.bindings.cyruntime cimport cudaStream_t


Expand All @@ -34,8 +38,8 @@ __all__ = [
]

cpdef Column make_empty_column(
MakeEmptyColumnOperand type_or_id,
object stream=None,
MakeEmptyColumnOperand type_or_id: DataType | TypeId,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Creates an empty column of the specified type.
Expand Down Expand Up @@ -83,7 +87,7 @@ cpdef Column make_numeric_column(
DataType type_,
size_type size,
MaskArg mstate,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Creates an empty numeric column.
Expand Down Expand Up @@ -122,7 +126,7 @@ cpdef Column make_fixed_point_column(
DataType type_,
size_type size,
MaskArg mstate,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):

Expand Down Expand Up @@ -158,7 +162,7 @@ cpdef Column make_timestamp_column(
DataType type_,
size_type size,
MaskArg mstate,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):

Expand Down Expand Up @@ -194,7 +198,7 @@ cpdef Column make_duration_column(
DataType type_,
size_type size,
MaskArg mstate,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):

Expand Down Expand Up @@ -230,7 +234,7 @@ cpdef Column make_fixed_width_column(
DataType type_,
size_type size,
MaskArg mstate,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):

Expand Down Expand Up @@ -264,7 +268,7 @@ cpdef Column make_fixed_width_column(

cpdef Column make_empty_lists_column(
DataType child_type,
object stream=None,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Creates an empty column of the specified type.
Expand Down
11 changes: 10 additions & 1 deletion python/pylibcudf/pylibcudf/concatenate.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from collections.abc import Sequence
from libcpp.memory cimport unique_ptr
from libcpp.utility cimport move
from libcpp.vector cimport vector
Expand All @@ -16,11 +17,19 @@ from rmm.pylibrmm.memory_resource cimport DeviceMemoryResource
from .column cimport Column
from .table cimport Table
from .utils cimport _get_stream, _get_memory_resource
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from pylibcudf.utils import CudaStreamLike
from cuda.bindings.cyruntime cimport cudaStream_t

__all__ = ["concatenate"]

cpdef concatenate(objects, object stream=None, DeviceMemoryResource mr=None):
cpdef concatenate(
objects: Sequence[Column] | Sequence[Table],
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"""Concatenate columns or tables.

Parameters
Expand Down
Loading
Loading