diff --git a/pyproject.toml b/pyproject.toml index e15cb7b3cdd..8f9aa165e5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,7 +87,9 @@ select = [ # non-pep585-annotation "UP006", # non-pep604-annotation - "UP007" + "UP007", + # Import from `collections.abc` instead: `Callable` + "UP035", ] ignore = [ # whitespace before : diff --git a/python/cudf/cudf/_typing.py b/python/cudf/cudf/_typing.py index 34c96cc8cb3..6e8ad556b08 100644 --- a/python/cudf/cudf/_typing.py +++ b/python/cudf/cudf/_typing.py @@ -1,7 +1,8 @@ # Copyright (c) 2021-2024, NVIDIA CORPORATION. import sys -from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, TypeVar, Union +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, Dict, Iterable, TypeVar, Union import numpy as np from pandas import Period, Timedelta, Timestamp diff --git a/python/cudf/cudf/core/column/numerical.py b/python/cudf/cudf/core/column/numerical.py index 90bec049831..7f391c8a79c 100644 --- a/python/cudf/cudf/core/column/numerical.py +++ b/python/cudf/cudf/core/column/numerical.py @@ -3,7 +3,7 @@ from __future__ import annotations import functools -from typing import TYPE_CHECKING, Any, Callable, Sequence, cast +from typing import TYPE_CHECKING, Any, Sequence, cast import numpy as np import pandas as pd @@ -28,6 +28,8 @@ from .numerical_base import NumericalBaseColumn if TYPE_CHECKING: + from collections.abc import Callable + from cudf._typing import ( ColumnBinaryOperand, ColumnLike, diff --git a/python/cudf/cudf/core/column_accessor.py b/python/cudf/cudf/core/column_accessor.py index 34076fa0060..09b0f453692 100644 --- a/python/cudf/cudf/core/column_accessor.py +++ b/python/cudf/cudf/core/column_accessor.py @@ -6,7 +6,7 @@ import sys from collections import abc from functools import cached_property, reduce -from typing import TYPE_CHECKING, Any, Callable, Mapping, cast +from typing import TYPE_CHECKING, Any, Mapping, cast import numpy as np import pandas as pd @@ -639,7 +639,7 @@ def _pad_key( def rename_levels( self, - mapper: Mapping[abc.Hashable, abc.Hashable] | Callable, + mapper: Mapping[abc.Hashable, abc.Hashable] | abc.Callable, level: int | None = None, ) -> Self: """ diff --git a/python/cudf/cudf/core/dataframe.py b/python/cudf/cudf/core/dataframe.py index a309b9117eb..6065e0e1eeb 100644 --- a/python/cudf/cudf/core/dataframe.py +++ b/python/cudf/cudf/core/dataframe.py @@ -13,8 +13,8 @@ import textwrap import warnings from collections import abc, defaultdict -from collections.abc import Iterator -from typing import TYPE_CHECKING, Any, Callable, Literal, MutableMapping, cast +from collections.abc import Callable, Iterator +from typing import TYPE_CHECKING, Any, Literal, MutableMapping, cast import cupy import numba diff --git a/python/cudf/cudf/core/dtypes.py b/python/cudf/cudf/core/dtypes.py index 6d532e01cba..2110e610c37 100644 --- a/python/cudf/cudf/core/dtypes.py +++ b/python/cudf/cudf/core/dtypes.py @@ -7,7 +7,7 @@ import textwrap import warnings from functools import cached_property -from typing import TYPE_CHECKING, Any, Callable +from typing import TYPE_CHECKING, Any import numpy as np import pandas as pd @@ -27,6 +27,8 @@ PANDAS_NUMPY_DTYPE = pd.core.dtypes.dtypes.PandasDtype if TYPE_CHECKING: + from collections.abc import Callable + from cudf._typing import Dtype from cudf.core.buffer import Buffer diff --git a/python/cudf/cudf/core/frame.py b/python/cudf/cudf/core/frame.py index 3e1efd7c97a..cbe1e97d834 100644 --- a/python/cudf/cudf/core/frame.py +++ b/python/cudf/cudf/core/frame.py @@ -6,7 +6,7 @@ import pickle import warnings from collections import abc -from typing import TYPE_CHECKING, Any, Callable, Literal, MutableMapping +from typing import TYPE_CHECKING, Any, Literal, MutableMapping # TODO: The `numpy` import is needed for typing purposes during doc builds # only, need to figure out why the `np` alias is insufficient then remove. @@ -403,7 +403,7 @@ def __arrow_array__(self, type=None): @_performance_tracking def _to_array( self, - get_array: Callable, + get_array: abc.Callable, module: ModuleType, copy: bool, dtype: Dtype | None = None, diff --git a/python/cudf/cudf/core/udf/utils.py b/python/cudf/cudf/core/udf/utils.py index d616761cb3b..6d7362952c9 100644 --- a/python/cudf/cudf/core/udf/utils.py +++ b/python/cudf/cudf/core/udf/utils.py @@ -3,7 +3,7 @@ import functools import os -from typing import Any, Callable +from typing import TYPE_CHECKING, Any import cachetools import cupy as cp @@ -41,6 +41,9 @@ from cudf.utils.performance_tracking import _performance_tracking from cudf.utils.utils import initfunc +if TYPE_CHECKING: + from collections.abc import Callable + # Maximum size of a string column is 2 GiB _STRINGS_UDF_DEFAULT_HEAP_SIZE = os.environ.get("STRINGS_UDF_HEAP_SIZE", 2**31) _heap_size = 0 diff --git a/python/cudf/cudf/io/parquet.py b/python/cudf/cudf/io/parquet.py index 6b895abbf66..d6b2ae2f31c 100644 --- a/python/cudf/cudf/io/parquet.py +++ b/python/cudf/cudf/io/parquet.py @@ -10,7 +10,7 @@ from collections import defaultdict from contextlib import ExitStack from functools import partial, reduce -from typing import Callable +from typing import TYPE_CHECKING from uuid import uuid4 import numpy as np @@ -24,6 +24,10 @@ from cudf.utils import ioutils from cudf.utils.performance_tracking import _performance_tracking +if TYPE_CHECKING: + from collections.abc import Callable + + BYTE_SIZES = { "kb": 1000, "mb": 1000000, diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 94e73021cec..df7bbe22a61 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -5,10 +5,10 @@ import textwrap from contextlib import ContextDecorator from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Callable +from typing import TYPE_CHECKING, Any if TYPE_CHECKING: - from collections.abc import Container + from collections.abc import Callable, Container @dataclass diff --git a/python/cudf/cudf/pandas/fast_slow_proxy.py b/python/cudf/cudf/pandas/fast_slow_proxy.py index bb678fd1efe..4b0fd9a5b36 100644 --- a/python/cudf/cudf/pandas/fast_slow_proxy.py +++ b/python/cudf/cudf/pandas/fast_slow_proxy.py @@ -10,9 +10,9 @@ import pickle import types import warnings -from collections.abc import Iterator +from collections.abc import Callable, Iterator from enum import IntEnum -from typing import Any, Callable, Literal, Mapping +from typing import Any, Literal, Mapping import numpy as np diff --git a/python/cudf/cudf/utils/ioutils.py b/python/cudf/cudf/utils/ioutils.py index e5944d7093c..94974e595b1 100644 --- a/python/cudf/cudf/utils/ioutils.py +++ b/python/cudf/cudf/utils/ioutils.py @@ -4,9 +4,9 @@ import os import urllib import warnings +from collections.abc import Callable from io import BufferedWriter, BytesIO, IOBase, TextIOWrapper from threading import Thread -from typing import Callable import fsspec import fsspec.implementations.local diff --git a/python/cudf_polars/cudf_polars/dsl/ir.py b/python/cudf_polars/cudf_polars/dsl/ir.py index ebc7dee6bfb..e334e6f5cc5 100644 --- a/python/cudf_polars/cudf_polars/dsl/ir.py +++ b/python/cudf_polars/cudf_polars/dsl/ir.py @@ -18,7 +18,7 @@ import types from functools import cache from pathlib import Path -from typing import TYPE_CHECKING, Any, Callable, ClassVar +from typing import TYPE_CHECKING, Any, ClassVar import pyarrow as pa import pylibcudf as plc @@ -31,7 +31,7 @@ from cudf_polars.utils import sorting if TYPE_CHECKING: - from collections.abc import MutableMapping + from collections.abc import Callable, MutableMapping from typing import Literal from cudf_polars.typing import Schema diff --git a/python/cudf_polars/cudf_polars/typing/__init__.py b/python/cudf_polars/cudf_polars/typing/__init__.py index 5276073e62a..adab10bdded 100644 --- a/python/cudf_polars/cudf_polars/typing/__init__.py +++ b/python/cudf_polars/cudf_polars/typing/__init__.py @@ -13,7 +13,8 @@ from polars.polars import _expr_nodes as pl_expr, _ir_nodes as pl_ir if TYPE_CHECKING: - from typing import Callable, TypeAlias + from collections.abc import Callable + from typing import TypeAlias import polars as pl diff --git a/python/cudf_polars/pyproject.toml b/python/cudf_polars/pyproject.toml index 0382e3ce6a2..f2bab9e6623 100644 --- a/python/cudf_polars/pyproject.toml +++ b/python/cudf_polars/pyproject.toml @@ -115,7 +115,6 @@ ignore = [ # tryceratops "TRY003", # Avoid specifying long messages outside the exception class # pyupgrade - "UP035", # Import from `collections.abc` instead: `Callable` "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` # Lints below are turned off because of conflicts with the ruff # formatter diff --git a/python/dask_cudf/dask_cudf/io/json.py b/python/dask_cudf/dask_cudf/io/json.py index 8705d98e9d6..98c5ceedb76 100644 --- a/python/dask_cudf/dask_cudf/io/json.py +++ b/python/dask_cudf/dask_cudf/io/json.py @@ -81,7 +81,7 @@ def read_json( If str, this value will be used as the ``engine`` argument when :func:`cudf.read_json` is used to create each partition. - If a :obj:`~typing.Callable`, this value will be used as the + If a :obj:`~collections.abc.Callable`, this value will be used as the underlying function used to create each partition from JSON data. The default value is "auto", so that ``engine=partial(cudf.read_json, engine="auto")`` will be