Skip to content
Merged
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
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

ci:
Expand Down Expand Up @@ -30,11 +30,11 @@ repos:
^python/cudf/cudf/tests/data/vocab.txt
)
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.18.1
rev: v0.19.0
hooks:
- id: cython-lint
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.13.0'
rev: 'v2.1.0'
hooks:
- id: mypy
additional_dependencies: [
Expand Down Expand Up @@ -202,7 +202,7 @@ repos:
pass_filenames: false
verbose: true
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
rev: v2.4.2
hooks:
- id: codespell
additional_dependencies: [tomli]
Expand All @@ -213,13 +213,13 @@ repos:
^CHANGELOG.md$
)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
rev: v0.15.17
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
- repo: https://github.com/rapidsai/pre-commit-hooks
rev: v1.4.1
rev: v1.5.1
hooks:
- id: verify-copyright
name: verify-copyright-cudf
Expand Down Expand Up @@ -317,7 +317,7 @@ repos:
(?x)
^pyproject[.]toml$
- repo: https://github.com/rapidsai/dependency-file-generator
rev: v1.20.2
rev: v1.20.3
hooks:
- id: rapids-dependency-file-generator
args: ["--clean", "--warn-all", "--strict"]
Expand All @@ -327,7 +327,7 @@ repos:
- id: shellcheck
args: ["--severity=warning"]
- repo: https://github.com/zizmorcore/zizmor-pre-commit
rev: v1.24.1
rev: v1.25.2
hooks:
- id: zizmor

Expand Down
4 changes: 2 additions & 2 deletions docs/cudf/source/_ext/PandasCompat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2021-2025, NVIDIA CORPORATION
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# This file is adapted from official sphinx tutorial for `todo` extension:
Expand Down Expand Up @@ -119,7 +119,7 @@ def __init__(self, app, doctree, docname):
self.config = app.config
self.env = app.env
self.domain = cast(
PandasCompatDomain, app.env.get_domain("pandascompat")
"PandasCompatDomain", app.env.get_domain("pandascompat")
)
self.document = new_document("")
self.process(doctree, docname)
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
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

[tool.mypy]
Expand Down Expand Up @@ -103,7 +103,7 @@ select = [
# overload-with-docstring
"D418",
# flake8-type-checking
"TCH",
"TC",
# flake8-future-annotations
"FA",
# non-pep585-annotation
Expand Down Expand Up @@ -138,10 +138,15 @@ ignore = [
# Mutable class attributes should be annotated with
# `typing.ClassVar`
"RUF012",
# import not at top of file (deferred/conditional imports are intentional)
"PLC0415",
]
fixable = ["ALL"]
exclude = [
"cpp/scripts/gdb-pretty-printers.py",
# .pyi stubs use PEP 695 (Python 3.12+) syntax; pylibcudf's own config
# sets target-version = "py312" for these
"*.pyi",
]
extend-unsafe-fixes = [
# zip-without-explicit-strict's autofix sets strict to False, but we want to enforce True
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Define common type operations."""
Expand Down Expand Up @@ -252,7 +252,7 @@ def _union_categoricals(

result_col = cudf.core.column.CategoricalColumn._concat(
[
cast(cudf.core.column.CategoricalColumn, obj._column)
cast("cudf.core.column.CategoricalColumn", obj._column)
for obj in to_union
]
)
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/_internals/copying.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 @@ -66,7 +66,7 @@ def scatter(
*target_columns, mode="write", scope="internal"
) as target_columns:
plc_tbl = plc.copying.scatter(
cast(list[plc.Scalar], sources)
cast("list[plc.Scalar]", sources)
if isinstance(sources[0], plc.Scalar)
else plc.Table(
[col.plc_column for col in cast("list[ColumnBase]", sources)]
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/accessors/string.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Expand Down Expand Up @@ -3851,7 +3851,7 @@ def isempty(self) -> Series | Index:
# mypy can't deduce that the return value of
# StringColumn.__eq__ is ColumnBase because the binops are
# dynamically added by a mixin class
cast(ColumnBase, self._column == "").fillna(False)
cast("ColumnBase", self._column == "").fillna(False)
)

def isspace(self) -> Series | Index:
Expand Down Expand Up @@ -4886,7 +4886,7 @@ def character_ngrams(
if isinstance(result, cudf.Series) and not as_list:
# before exploding, removes those lists which have 0 length
result = result[result.list.len() > 0]
return result.explode() # type: ignore[union-attr]
return result.explode()
return result

def hash_character_ngrams(
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Expand Down Expand Up @@ -254,7 +254,7 @@ def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
)
plc_col = plc.Column.from_scalar(plc_scalar, len(self))
other = cast(
CategoricalColumn,
"CategoricalColumn",
ColumnBase.create(plc_col, self.dtype),
)
equality_ops = {"__eq__", "__ne__", "NULL_EQUALS", "NULL_NOT_EQUALS"}
Expand Down
25 changes: 14 additions & 11 deletions python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Expand Down Expand Up @@ -3479,7 +3479,7 @@ def as_column(
)
elif inferred_dtype == "boolean":
if cudf.get_option("mode.pandas_compatible"):
if dtype.kind != "b" or pd.isna(arbitrary).any():
if dtype.kind != "b" or pd.isna(arbitrary).any(): # type: ignore[union-attr] # (dtype is required for boolean compatibility)
raise MixedTypeError(
f"Cannot have mixed values with {inferred_dtype}"
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -3563,7 +3563,7 @@ def as_column(
if is_arrow_null_dtype(dtype):
if is_na_like(arbitrary):
return column_empty(length, dtype=dtype)
pa.scalar(arbitrary, type=dtype.pyarrow_dtype)
pa.scalar(arbitrary, type=dtype.pyarrow_dtype) # type: ignore[union-attr] # (arrow null dtype has pyarrow_dtype)

pa_type = None
if isinstance(arbitrary, pd.Interval) or _is_categorical_dtype(dtype):
Expand Down Expand Up @@ -3610,17 +3610,18 @@ def as_column(
np.dtype(f"{arbitrary.dtype.kind}8[s]")
)

pa_scalar = pa.scalar(arbitrary, type=pa_type)
pa_scalar = pa.scalar(arbitrary, type=pa_type) # type: ignore[type-var] # (pyarrow accepts normalized scalar inputs)
if length == 0:
if dtype is None:
dtype = cudf_dtype_from_pa_type(pa_scalar.type)
dtype = cudf_dtype_from_pa_type(pa_scalar.type) # type: ignore[arg-type] # (pyarrow scalar exposes a DataType)
return column_empty(length, dtype=dtype)
else:
plc_col = plc.Column.from_scalar(
pa_scalar_to_plc_scalar(pa_scalar), length
)
col = ColumnBase.create(
plc_col, cudf_dtype_from_pa_type(pa_scalar.type)
plc_col,
cudf_dtype_from_pa_type(pa_scalar.type), # type: ignore[arg-type] # (pyarrow scalar exposes a DataType)
)
if dtype is not None:
col = col.astype(dtype)
Expand Down Expand Up @@ -3776,18 +3777,20 @@ def as_column(
ser = pd.Series(arbitrary).astype(dtype)
else:
ser = pd.Series(
arbitrary, dtype=pd.CategoricalDtype(ordered=dtype.ordered)
arbitrary,
dtype=pd.CategoricalDtype(ordered=dtype.ordered), # type: ignore[union-attr] # (categorical dtype converted from cudf dtype)
)
if dtype.categories is not None:
if dtype.categories is not None: # type: ignore[union-attr] # (categorical dtype converted from cudf dtype)
ser = ser.cat.set_categories(
dtype.categories, ordered=dtype.ordered
dtype.categories, # type: ignore[union-attr] # (categorical dtype converted from cudf dtype)
ordered=dtype.ordered, # type: ignore[union-attr] # (categorical dtype converted from cudf dtype)
)
else:
ser = pd.Series(arbitrary, dtype=dtype)
return as_column(ser, nan_as_null=nan_as_null)
elif isinstance(dtype, (StructDtype, ListDtype)):
try:
data = pa.array(arbitrary, type=dtype.to_arrow())
data = pa.array(arbitrary, type=dtype.to_arrow()) # type: ignore[arg-type] # (cudf nested dtype converts to Arrow type)
except (pa.ArrowInvalid, pa.ArrowTypeError):
if isinstance(dtype, ListDtype):
# e.g. test_cudf_list_struct_write
Expand All @@ -3800,7 +3803,7 @@ def as_column(
if is_arrow_null_dtype(dtype):
arbitrary = pa.array(
arbitrary,
type=dtype.pyarrow_dtype,
type=dtype.pyarrow_dtype, # type: ignore[union-attr] # (arrow null dtype has pyarrow_dtype)
from_pandas=True,
)
return as_column(arbitrary, nan_as_null=nan_as_null, dtype=dtype)
Expand Down
18 changes: 9 additions & 9 deletions python/cudf/cudf/core/column/datetime.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 @@ -602,7 +602,7 @@ def strftime(self, format: str, dtype: DtypeObj) -> StringColumn:
)
with self.access(mode="read", scope="internal"):
return cast(
cudf.core.column.string.StringColumn,
"cudf.core.column.string.StringColumn",
ColumnBase.create(
plc.strings.convert.convert_datetime.from_timestamps(
self.plc_column,
Expand Down Expand Up @@ -777,9 +777,9 @@ def _preserve_tz(result_dtype: np.dtype) -> DtypeObj:
# When the operation should yield another datetime and self
# is tz-aware, carry the tz forward with the resolved unit.
if self_is_tz and result_dtype.kind == "M":
tz_dtype = cast(pd.DatetimeTZDtype, self.dtype)
tz_dtype = cast("pd.DatetimeTZDtype", self.dtype)
unit = np.datetime_data(
cast(np.dtype[np.datetime64], result_dtype)
cast("np.dtype[np.datetime64]", result_dtype)
)[0]
return pd.DatetimeTZDtype(unit, tz_dtype.tz)
return result_dtype
Expand Down Expand Up @@ -988,7 +988,7 @@ def tz_localize(
if is_arrow:
dtype = pd.ArrowDtype(pa.timestamp(self.time_unit, tz)) # type: ignore[call-overload]
result = cast(
DatetimeTZColumn, ColumnBase.create(gmt_data.plc_column, dtype)
"DatetimeTZColumn", ColumnBase.create(gmt_data.plc_column, dtype)
)
# Avoid re-computing local times from UTC times
result._local_time = localized
Expand Down Expand Up @@ -1070,7 +1070,7 @@ def _local_time(self) -> DatetimeColumn:
# Perform the add on the tz-naive UTC view so the result is naive
# (``self + offsets`` now preserves tz by default). The local-time
# column must be tz-naive to represent the wall-clock values.
return cast(DatetimeColumn, self._utc_time + offsets_from_utc)
return cast("DatetimeColumn", self._utc_time + offsets_from_utc)

def as_string_column(self, dtype: DtypeObj) -> StringColumn:
return self._local_time.as_string_column(dtype)
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def as_datetime_column(
.plc_column
)
casted = cast(
DatetimeTZColumn, ColumnBase.create(casted_plc, dtype)
"DatetimeTZColumn", ColumnBase.create(casted_plc, dtype)
)
else:
casted = self
Expand All @@ -1118,7 +1118,7 @@ def as_datetime_column(
.plc_column
)
casted = cast(
DatetimeTZColumn, ColumnBase.create(casted_plc, dtype)
"DatetimeTZColumn", ColumnBase.create(casted_plc, dtype)
)
else:
casted = self
Expand Down Expand Up @@ -1192,6 +1192,6 @@ def tz_convert(self, tz: str | None) -> DatetimeColumn | DatetimeTZColumn:
pd.DatetimeTZDtype(self.time_unit, tz)
)
return cast(
DatetimeTZColumn,
"DatetimeTZColumn",
ColumnBase.create(self.plc_column, target_dtype),
)
10 changes: 5 additions & 5 deletions python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations
Expand Down Expand Up @@ -131,12 +131,12 @@ def as_string_column(self, dtype: DtypeObj) -> StringColumn:
)
)
return cast(
cudf.core.column.string.StringColumn,
"cudf.core.column.string.StringColumn",
ColumnBase.create(plc_column, dtype),
)
else:
return cast(
cudf.core.column.StringColumn,
"cudf.core.column.StringColumn",
cudf.core.column.column_empty(0, dtype=dtype),
)

Expand Down Expand Up @@ -239,7 +239,7 @@ def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
if isinstance(lhs, (int, Decimal)):
lhs_binop = _to_plc_scalar(lhs, new_lhs_dtype)
else:
lhs_binop = lhs.astype(new_lhs_dtype)
lhs_binop = lhs.astype(new_lhs_dtype) # type: ignore[union-attr] # (lhs is decimal column here)
if isinstance(rhs, (int, Decimal)):
rhs_binop = _to_plc_scalar(rhs, new_rhs_dtype)
else:
Expand All @@ -256,7 +256,7 @@ def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
}:
lhs_comp: plc.Scalar | ColumnBase = lhs # type: ignore[assignment]
rhs_comp: plc.Scalar | ColumnBase = (
_to_plc_scalar(rhs, self.dtype) # type: ignore[arg-type]
_to_plc_scalar(rhs, self.dtype)
if isinstance(rhs, (int, Decimal))
else rhs
)
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/interval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2018-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

Expand Down Expand Up @@ -133,7 +133,7 @@ def set_closed(
)

def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
reflect, op = self._check_reflected_op(op)
_reflect, op = self._check_reflected_op(op)
if not isinstance(other, type(self)):
return NotImplemented
if op in {"__eq__", "__ne__", "NULL_EQUALS", "NULL_NOT_EQUALS"}:
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/lists.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 @@ -77,7 +77,7 @@ def _cast_setitem_value(self, value: Any) -> plc.Scalar:

def _binaryop(self, other: ColumnBinaryOperand, op: str) -> ColumnBase:
# Lists only support __add__, which concatenates lists.
reflect, op = self._check_reflected_op(op)
_reflect, op = self._check_reflected_op(op)
if not isinstance(other, type(self)):
return NotImplemented
if is_dtype_obj_list(other.dtype):
Expand Down
Loading
Loading