Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions python/cudf/cudf/core/_internals/copying.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def gather(
columns: Sequence[ColumnBase],
gather_map: NumericalColumn,
nullify: bool = False,
) -> list[plc.Column]:
) -> tuple[plc.Column, ...]:
with access_columns(
*columns, gather_map, mode="read", scope="internal"
) as (*columns, gather_map):
Expand All @@ -38,7 +38,7 @@ def scatter(
scatter_map: NumericalColumn,
target_columns: list[ColumnBase],
bounds_check: bool = True,
):
) -> tuple[plc.Column, ...]:
"""
Scattering source into target as per the scatter map.
`source` can be a list of scalars, or a list of columns. The number of
Expand All @@ -51,7 +51,7 @@ def scatter(
raise ValueError("Mismatched number of source and target columns.")

if len(sources) == 0:
return []
return ()

if bounds_check:
n_rows = len(target_columns[0])
Expand Down Expand Up @@ -80,7 +80,7 @@ def scatter(

def columns_split(
input_columns: Sequence[ColumnBase], splits: list[int]
) -> list[list[plc.Column]]:
) -> list[tuple[plc.Column, ...]]:
with access_columns(
*input_columns, mode="read", scope="internal"
) as input_columns:
Expand Down
8 changes: 4 additions & 4 deletions python/cudf/cudf/core/_internals/sorting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

Expand Down Expand Up @@ -143,7 +143,7 @@ def sort_by_key(
na_position: Iterable[Literal["first", "last"]],
*,
stable: bool,
) -> list[plc.Column]:
) -> tuple[plc.Column, ...]:
"""
Sort a table by given keys

Expand All @@ -165,8 +165,8 @@ def sort_by_key(

Returns
-------
list[Column]
list of value columns sorted by keys
tuple[Column, ...]
value columns sorted by keys
"""
column_order, null_precedence = ordering(ascending, na_position)
func = (
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Expand Down Expand Up @@ -249,7 +249,7 @@ def _drop_duplicates_columns(
keys: list[int],
keep: Literal["first", "last", False],
nulls_are_equal: bool,
) -> list[plc.Column]:
) -> tuple[plc.Column, ...]:
"""Core stable_distinct implementation shared by Index and IndexedFrame."""
_keep_options = {
"first": plc.stream_compaction.DuplicateKeepOption.KEEP_FIRST,
Expand Down Expand Up @@ -277,7 +277,7 @@ def _drop_nulls_columns(
keys: list[int],
how: Literal["any", "all"],
thresh: int | None = None,
) -> list[plc.Column]:
) -> tuple[plc.Column, ...]:
"""Core drop_nulls implementation shared by Index and IndexedFrame."""
if how not in {"any", "all"}:
raise ValueError("how must be 'any' or 'all'")
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3455,7 +3455,7 @@ def _split(self, splits: list[int], keep_index: bool = True) -> list[Self]:
)

def split_with_dtypes(
split: list[plc.Column],
split: tuple[plc.Column, ...],
) -> list[ColumnBase]:
return [
ColumnBase.create(col, dtype)
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/io/parquet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

Expand Down Expand Up @@ -1419,13 +1419,13 @@ def _read_parquet(
column_names = tbl_w_meta.column_names(include_children=False)
child_names = tbl_w_meta.child_names
per_file_user_data = tbl_w_meta.per_file_user_data
concatenated_columns = tbl_w_meta.tbl.columns()
concatenated_columns = tbl_w_meta.tbl.release()

# save memory
del tbl_w_meta

while reader.has_next():
columns = reader.read_chunk().tbl.columns()
columns = reader.read_chunk().tbl.release()
# Iterate in reverse to avoid O(n²) cost from popping
for i in range(len(concatenated_columns) - 1, -1, -1):
concatenated_columns[i] = plc.concatenate.concatenate(
Expand Down
8 changes: 5 additions & 3 deletions python/cudf_polars/cudf_polars/dsl/expressions/rolling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# TODO: remove need for this
# ruff: noqa: D101
Expand Down Expand Up @@ -422,6 +422,7 @@ def _( # type: ignore[no-untyped-def]

# Instead of calling self._gather_columns, let's call plc.copying.gather directly
# since we need plc.Column objects, not cudf_polars Column objects
val_cols: Sequence[plc.Column]
if order_index is not None:
plc_cols = [
ne.value.children[0].evaluate(df, context=ExecutionContext.FRAME).obj
Expand Down Expand Up @@ -694,15 +695,16 @@ def _build_groupby_requests(
eval_cols.append(child.evaluate(df, context=ExecutionContext.FRAME).obj)
val_nodes.append((ne, val))

gathered_cols: Sequence[plc.Column] = eval_cols
if order_index is not None and eval_cols:
eval_cols = plc.copying.gather(
gathered_cols = plc.copying.gather(
plc.Table(eval_cols),
order_index,
plc.copying.OutOfBoundsPolicy.NULLIFY,
stream=df.stream,
).columns()

gathered_iter = iter(eval_cols)
gathered_iter = iter(gathered_cols)
for ne in named_exprs:
val = ne.value
if isinstance(val, expr.Len):
Expand Down
2 changes: 1 addition & 1 deletion python/cudf_polars/cudf_polars/dsl/expressions/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def do_evaluate(
max_splits - 1,
stream=df.stream,
)
children = plc_table.columns()
children = plc_table.release()
ref_column = children[0]
if (remainder := n + int(not is_split_n) - len(children)) > 0:
# Reach expected number of splits by padding with nulls
Expand Down
8 changes: 4 additions & 4 deletions python/cudf_polars/cudf_polars/dsl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ def read_csv_header(
chunk = reader.read_chunk()
# TODO: Nested column names
names = chunk.column_names(include_children=False)
concatenated_columns = chunk.tbl.columns()
concatenated_columns = chunk.tbl.release()
while reader.has_next():
columns = reader.read_chunk().tbl.columns()
columns = reader.read_chunk().tbl.release()
# Discard columns while concatenating to reduce memory footprint.
# Reverse order to avoid O(n^2) list popping cost.
for i in reversed(range(len(concatenated_columns))):
Expand Down Expand Up @@ -2328,7 +2328,7 @@ def _reorder_maps(
*,
left_primary: bool = True,
stream: Stream,
) -> list[plc.Column]:
) -> tuple[plc.Column, ...]:
"""
Reorder gather maps to satisfy polars join order restrictions.

Expand All @@ -2355,7 +2355,7 @@ def _reorder_maps(

Returns
-------
list[plc.Column]
tuple[plc.Column, ...]
Reordered left and right gather maps.

Notes
Expand Down
7 changes: 5 additions & 2 deletions python/pylibcudf/pylibcudf/column.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Column:
mask: Span | None,
null_count: int,
offset: int,
children: list[Column],
children: Iterable[Column],
validate: bool = True,
) -> None: ...
def type(self) -> DataType: ...
Expand Down Expand Up @@ -94,7 +94,10 @@ class Column:
) -> Column: ...
@staticmethod
def from_rmm_buffer(
buff: DeviceBuffer, dtype: DataType, size: int, children: list[Column]
buff: DeviceBuffer,
dtype: DataType,
size: int,
children: Iterable[Column],
) -> Column: ...
def to_arrow(
self,
Expand Down
12 changes: 7 additions & 5 deletions python/pylibcudf/pylibcudf/column.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ cdef class Column:
The number of null rows in the column.
offset : int
The offset into the data buffer where the column's data begins.
children : list
children : Iterable[Column]
The children of this column if it is a compound column type.
validate : bool, default True
Whether to validate that data and mask satisfy Span protocol.
Expand All @@ -343,8 +343,9 @@ 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,
list children, bint validate=True
children, bint validate=True
):
children = list(children)
if not all(isinstance(c, Column) for c in children):
raise ValueError("All children must be pylibcudf Column objects")

Expand Down Expand Up @@ -600,7 +601,7 @@ cdef class Column:
DeviceBuffer buff,
DataType dtype,
size_type size,
list children,
children,
):
"""
Create a Column from an RMM DeviceBuffer.
Expand All @@ -613,14 +614,15 @@ cdef class Column:
The number of rows in the column.
dtype : DataType
The type of the data in the buffer.
children : list
List of child columns.
children : Iterable[Column]
The child columns.

Notes
-----
To provide a mask and null count, use `Column.with_mask` after
this method.
"""
children = list(children)
if plc_is_fixed_width(dtype) and len(children) != 0:
raise ValueError("Fixed-width types must have zero children.")
elif dtype.id() == type_id.STRING and len(children) != 1:
Expand Down
4 changes: 2 additions & 2 deletions python/pylibcudf/pylibcudf/concatenate.pxd
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 .table cimport Table
Expand All @@ -10,4 +10,4 @@ from rmm.pylibrmm.memory_resource cimport DeviceMemoryResource
# unify the column and table paths without using runtime dispatch instead. In this case
# we choose to prioritize API consistency over performance, so we use the same function
# with a bit of runtime dispatch overhead.
cpdef concatenate(list objects, object stream = *, DeviceMemoryResource mr=*)
cpdef concatenate(objects, object stream = *, DeviceMemoryResource mr=*)
6 changes: 4 additions & 2 deletions python/pylibcudf/pylibcudf/concatenate.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# 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 collections.abc import Sequence

from rmm.pylibrmm.memory_resource import DeviceMemoryResource

from pylibcudf.column import Column
from pylibcudf.table import Table
from pylibcudf.utils import CudaStreamLike

def concatenate[ColumnOrTable: (Column, Table)](
objects: list[ColumnOrTable],
objects: Sequence[ColumnOrTable],
stream: CudaStreamLike | None = None,
mr: DeviceMemoryResource | None = None,
) -> ColumnOrTable: ...
8 changes: 4 additions & 4 deletions python/pylibcudf/pylibcudf/concatenate.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
Expand All @@ -20,13 +20,13 @@ from cuda.bindings.cyruntime cimport cudaStream_t

__all__ = ["concatenate"]

cpdef concatenate(list objects, object stream=None, DeviceMemoryResource mr=None):
cpdef concatenate(objects, object stream=None, DeviceMemoryResource mr=None):
"""Concatenate columns or tables.

Parameters
----------
objects : Union[List[Column], List[Table]]
The list of Columns or Tables to concatenate.
objects : Sequence[Column] | Sequence[Table]
The Columns or Tables to concatenate.
stream : Stream | None
CUDA stream on which to perform the operation.
mr : DeviceMemoryResource | None
Expand Down
2 changes: 1 addition & 1 deletion python/pylibcudf/pylibcudf/io/types.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TableWithMetadata:
self, tbl: Table, column_names: list[ColumnNameSpec]
) -> None: ...
@property
def columns(self) -> list[Column]: ...
def columns(self) -> tuple[Column, ...]: ...
@overload
def column_names(self, include_children: Literal[False]) -> list[str]: ...
@overload
Expand Down
2 changes: 1 addition & 1 deletion python/pylibcudf/pylibcudf/io/types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ cdef class TableWithMetadata:
@property
def columns(self):
"""
Return a list containing the columns of the table
Return a tuple containing the columns of the table
"""
return self.tbl.columns()

Expand Down
6 changes: 3 additions & 3 deletions python/pylibcudf/pylibcudf/null_mask.pxd
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 pylibcudf.libcudf.types cimport mask_state, size_type
Expand Down Expand Up @@ -30,9 +30,9 @@ cpdef DeviceBuffer create_null_mask(
DeviceMemoryResource mr=*
)

cpdef tuple bitmask_and(list columns, object stream = *, DeviceMemoryResource mr=*)
cpdef tuple bitmask_and(columns, object stream = *, DeviceMemoryResource mr=*)

cpdef tuple bitmask_or(list columns, object stream = *, DeviceMemoryResource mr=*)
cpdef tuple bitmask_or(columns, object stream = *, DeviceMemoryResource mr=*)

cpdef size_type null_count(
object bitmask,
Expand Down
8 changes: 5 additions & 3 deletions python/pylibcudf/pylibcudf/null_mask.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 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 collections.abc import Sequence

from rmm.pylibrmm.device_buffer import DeviceBuffer
from rmm.pylibrmm.memory_resource import DeviceMemoryResource

Expand Down Expand Up @@ -29,12 +31,12 @@ def create_null_mask(
mr: DeviceMemoryResource | None = None,
) -> DeviceBuffer: ...
def bitmask_and(
columns: list[Column],
columns: Sequence[Column],
stream: CudaStreamLike | None = None,
mr: DeviceMemoryResource | None = None,
) -> tuple[DeviceBuffer, int]: ...
def bitmask_or(
columns: list[Column],
columns: Sequence[Column],
stream: CudaStreamLike | None = None,
mr: DeviceMemoryResource | None = None,
) -> tuple[DeviceBuffer, int]: ...
Expand Down
Loading
Loading