Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/accessors/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from cudf.api.types import is_scalar
from cudf.core.accessors.base_accessor import BaseAccessor
from cudf.core.column.column import as_column
from cudf.core.dtype.validators import is_dtype_obj_list, is_dtype_obj_numeric
from cudf.core.dtypes import ListDtype, dtype as cudf_dtype
from cudf.utils.dtypes import is_dtype_obj_list, is_dtype_obj_numeric
from cudf.utils.scalar import pa_scalar_to_plc_scalar

if TYPE_CHECKING:
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/accessors/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from cudf.core.accessors.base_accessor import BaseAccessor
from cudf.core.column.struct import StructColumn
from cudf.core.dtype.validators import is_dtype_obj_struct
from cudf.core.dtypes import StructDtype
from cudf.utils.dtypes import get_dtype_of_same_kind, is_dtype_obj_struct
from cudf.utils.dtypes import get_dtype_of_same_kind

if TYPE_CHECKING:
from cudf.core.dataframe import DataFrame
Expand Down
9 changes: 9 additions & 0 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class CategoricalColumn(column.ColumnBase):
plc.TypeId.UINT64,
}

@classmethod
def _validate_args( # type: ignore[override]
cls, plc_column: plc.Column, dtype: CategoricalDtype
) -> tuple[plc.Column, CategoricalDtype]:
plc_column, dtype = super()._validate_args(plc_column, dtype) # type: ignore[assignment]
if not isinstance(dtype, CategoricalDtype):
raise ValueError(f"{dtype=} must be a CategoricalDtype instance")
return plc_column, dtype

def __contains__(self, item: ScalarLike) -> bool:
try:
encoded = self._encode(item)
Expand Down
14 changes: 8 additions & 6 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
)
from cudf.core.column.utils import access_columns
from cudf.core.copy_types import GatherMap
from cudf.core.dtype.validators import (
is_dtype_obj_decimal,
is_dtype_obj_interval,
is_dtype_obj_list,
is_dtype_obj_numeric,
is_dtype_obj_struct,
)
from cudf.core.dtypes import (
CategoricalDtype,
DecimalDtype,
Expand All @@ -72,11 +79,6 @@
find_common_type,
get_dtype_of_same_kind,
is_column_like,
is_dtype_obj_decimal,
is_dtype_obj_interval,
is_dtype_obj_list,
is_dtype_obj_numeric,
is_dtype_obj_struct,
is_mixed_with_object_dtype,
is_pandas_nullable_extension_dtype,
min_signed_type,
Expand Down Expand Up @@ -863,7 +865,7 @@ def _prep_pandas_compat_repr(self) -> StringColumn | Self:
* null (other types)= str(pd.NA)
"""
if self.has_nulls():
return self.astype(np.dtype("str")).fillna(
return self.astype(CUDF_STRING_DTYPE).fillna(
str(self._PANDAS_NA_VALUE)
)
return self
Expand Down
25 changes: 15 additions & 10 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import warnings
from decimal import Decimal
from typing import TYPE_CHECKING, Any, Self, cast
from typing import TYPE_CHECKING, Any, ClassVar, Self, cast

import numpy as np
import pandas as pd
Expand All @@ -19,14 +19,16 @@
from cudf.core._internals import binaryop
from cudf.core.column.column import ColumnBase, as_column
from cudf.core.column.numerical_base import NumericalBaseColumn
from cudf.core.dtype.validators import (
is_dtype_obj_decimal32,
is_dtype_obj_decimal64,
is_dtype_obj_decimal128,
)
from cudf.core.dtypes import (
Decimal32Dtype,
Decimal64Dtype,
Decimal128Dtype,
DecimalDtype,
is_decimal32_dtype,
is_decimal64_dtype,
is_decimal128_dtype,
)
from cudf.core.mixins import BinaryOperand
from cudf.utils.dtypes import (
Expand All @@ -38,7 +40,7 @@
from cudf.utils.utils import is_na_like

if TYPE_CHECKING:
from collections.abc import Mapping
from collections.abc import Callable, Mapping

from cudf._typing import (
ColumnBinaryOperand,
Expand Down Expand Up @@ -70,14 +72,17 @@ class DecimalBaseColumn(NumericalBaseColumn):
"""Base column for decimal32, decimal64 or decimal128 columns"""

_VALID_BINARY_OPERATIONS = BinaryOperand._SUPPORTED_BINARY_OPERATIONS
_decimal_type_check: ClassVar[Callable[[DtypeObj], bool]]

@classmethod
def _validate_args( # type: ignore[override]
cls, plc_column: plc.Column, dtype: DecimalDtype
) -> tuple[plc.Column, DecimalDtype]:
plc_column, dtype = super()._validate_args(plc_column, dtype) # type: ignore[assignment]
if not cls._decimal_check(dtype): # type: ignore[attr-defined]
raise ValueError(f"{dtype=} must be a Decimal128Dtype instance")
if not cls._decimal_type_check(dtype):
raise ValueError(
f"{dtype=} must be a valid decimal dtype instance"
)
return plc_column, dtype

def _with_type_metadata(self: Self, dtype: DtypeObj) -> Self:
Expand Down Expand Up @@ -379,19 +384,19 @@ def to_pandas(
class Decimal32Column(DecimalBaseColumn):
_VALID_PLC_TYPES = {plc.TypeId.DECIMAL32}
_decimal_cls = Decimal32Dtype
_decimal_check = is_decimal32_dtype
_decimal_type_check = is_dtype_obj_decimal32


class Decimal64Column(DecimalBaseColumn):
_VALID_PLC_TYPES = {plc.TypeId.DECIMAL64}
_decimal_cls = Decimal64Dtype
_decimal_check = is_decimal64_dtype
_decimal_type_check = is_dtype_obj_decimal64


class Decimal128Column(DecimalBaseColumn):
_VALID_PLC_TYPES = {plc.TypeId.DECIMAL128}
_decimal_cls = Decimal128Dtype
_decimal_check = is_decimal128_dtype
_decimal_type_check = is_dtype_obj_decimal128

def to_arrow(self) -> pa.Array:
arrow_array = super().to_arrow()
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/column/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

import cudf
from cudf.core.column.column import ColumnBase, _handle_nulls, as_column
from cudf.core.dtype.validators import is_dtype_obj_interval
from cudf.core.dtypes import IntervalDtype, _dtype_to_metadata
from cudf.utils.dtypes import is_dtype_obj_interval
from cudf.utils.scalar import maybe_nested_pa_scalar_to_py

if TYPE_CHECKING:
Expand Down
6 changes: 2 additions & 4 deletions python/cudf/cudf/core/column/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@

import cudf
from cudf.core.column.column import ColumnBase, as_column, column_empty
from cudf.core.dtype.validators import is_dtype_obj_list
from cudf.core.dtypes import ListDtype
from cudf.core.missing import NA
from cudf.utils.dtypes import (
get_dtype_of_same_kind,
is_dtype_obj_list,
)
from cudf.utils.dtypes import get_dtype_of_same_kind
from cudf.utils.scalar import (
maybe_nested_pa_scalar_to_py,
pa_scalar_to_plc_scalar,
Expand Down
20 changes: 3 additions & 17 deletions python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
from cudf.api.types import is_scalar
from cudf.core._internals import binaryop
from cudf.core.column.column import ColumnBase, as_column, column_empty
from cudf.core.dtype.validators import is_dtype_obj_string
from cudf.core.mixins import Scannable
from cudf.errors import MixedTypeError
from cudf.utils.dtypes import (
CUDF_STRING_DTYPE,
cudf_dtype_to_pa_type,
dtype_to_pylibcudf_type,
get_dtype_of_same_kind,
is_dtype_obj_string,
is_pandas_nullable_extension_dtype,
)
from cudf.utils.scalar import pa_scalar_to_plc_scalar
Expand Down Expand Up @@ -117,21 +116,8 @@ def _validate_args(
cls, plc_column: plc.Column, dtype: np.dtype
) -> tuple[plc.Column, np.dtype]:
plc_column, dtype = super()._validate_args(plc_column, dtype)
if (
not cudf.get_option("mode.pandas_compatible")
and dtype != CUDF_STRING_DTYPE
and dtype.kind != "U"
) or (
cudf.get_option("mode.pandas_compatible")
and not is_dtype_obj_string(dtype)
):
raise ValueError(f"dtype must be {CUDF_STRING_DTYPE}")
if (
cudf.get_option("mode.pandas_compatible")
and isinstance(dtype, np.dtype)
and dtype.kind == "U"
):
dtype = CUDF_STRING_DTYPE
if not is_dtype_obj_string(dtype):
raise ValueError("dtype must be a valid cuDF string dtype")
return plc_column, dtype

@property
Expand Down
6 changes: 2 additions & 4 deletions python/cudf/cudf/core/column/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

import cudf
from cudf.core.column.column import ColumnBase
from cudf.core.dtype.validators import is_dtype_obj_struct
from cudf.core.dtypes import StructDtype
from cudf.utils.dtypes import (
dtype_from_pylibcudf_column,
is_dtype_obj_struct,
)
from cudf.utils.dtypes import dtype_from_pylibcudf_column
from cudf.utils.scalar import (
maybe_nested_pa_scalar_to_py,
pa_scalar_to_plc_scalar,
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
)
from cudf.core.column_accessor import ColumnAccessor
from cudf.core.copy_types import BooleanMask
from cudf.core.dtype.validators import is_dtype_obj_numeric
from cudf.core.dtypes import (
CategoricalDtype,
Decimal32Dtype,
Expand Down Expand Up @@ -107,7 +108,6 @@
find_common_type,
get_dtype_of_same_kind,
is_column_like,
is_dtype_obj_numeric,
is_mixed_with_object_dtype,
is_pandas_nullable_extension_dtype,
min_signed_type,
Expand Down
2 changes: 2 additions & 0 deletions python/cudf/cudf/core/dtype/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
# SPDX-License-Identifier: Apache-2.0
Loading