Skip to content

Commit

Permalink
lint: replace isort with Ruff's rule I (#16685)
Browse files Browse the repository at this point in the history
since #15312 moved formatting from Black to Rufft, it would make sense also unify import formatting under the same ruff so use build-in `I` rule instead of additional `isort`

Authors:
  - Jirka Borovec (https://github.com/Borda)
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Vyas Ramasubramani (https://github.com/vyasr)
  - https://github.com/jakirkham

URL: #16685
  • Loading branch information
Borda authored Oct 25, 2024
1 parent 2113bd6 commit 5cba4fb
Show file tree
Hide file tree
Showing 114 changed files with 318 additions and 380 deletions.
12 changes: 1 addition & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ repos:
^cpp/cmake/thirdparty/patches/.*|
^python/cudf/cudf/tests/data/subword_tokenizer_data/.*
)
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
# Use the config file specific to each subproject so that each
# project can specify its own first/third-party packages.
args: ["--config-root=python/", "--resolve-all-configs"]
files: python/.*
exclude: |
(?x)^(^python/cudf_polars/.*)
types_or: [python, cython, pyi]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.2
hooks:
Expand Down Expand Up @@ -150,6 +139,7 @@ repos:
rev: v0.4.8
hooks:
- id: ruff
args: ["--fix"]
files: python/.*$
- id: ruff-format
files: python/.*$
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ In order to run doxygen as a linter on C++/CUDA code, run
./ci/checks/doxygen.sh
```

Python code runs several linters including [Black](https://black.readthedocs.io/en/stable/),
[isort](https://pycqa.github.io/isort/), and [flake8](https://flake8.pycqa.org/en/latest/).
Python code runs several linters including [Ruff](https://docs.astral.sh/ruff/)
with its various rules for Black-like formatting or Isort.

cuDF also uses [codespell](https://github.com/codespell-project/codespell) to find spelling
mistakes, and this check is run as a pre-commit hook. To apply the suggested spelling fixes,
Expand Down
3 changes: 1 addition & 2 deletions docs/cudf/source/developer_guide/contributing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ Developers are strongly recommended to set up `pre-commit` prior to any developm
The `.pre-commit-config.yaml` file at the root of the repo is the primary source of truth linting.
Specifically, cuDF uses the following tools:

- [`ruff`](https://beta.ruff.rs/) checks for general code formatting compliance.
- [`isort`](https://pycqa.github.io/isort/) ensures imports are sorted consistently.
- [`ruff`](https://docs.astral.sh/ruff/) checks for general code formatting compliance.
- [`mypy`](http://mypy-lang.org/) performs static type checking.
In conjunction with [type hints](https://docs.python.org/3/library/typing.html),
`mypy` can help catch various bugs that are otherwise difficult to find.
Expand Down
2 changes: 1 addition & 1 deletion docs/cudf/source/user_guide/10min.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
"import os\n",
"\n",
"import cupy as cp\n",
"import dask_cudf\n",
"import pandas as pd\n",
"\n",
"import cudf\n",
"import dask_cudf\n",
"\n",
"cp.random.seed(12)\n",
"\n",
Expand Down
6 changes: 6 additions & 0 deletions docs/cudf/source/user_guide/guide-to-udfs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
"outputs": [],
"source": [
"# define a scalar function\n",
"\n",
"\n",
"def f(x):\n",
" return x + 1"
]
Expand Down Expand Up @@ -247,6 +249,8 @@
"outputs": [],
"source": [
"# redefine the same function from above\n",
"\n",
"\n",
"def f(x):\n",
" return x + 1"
]
Expand Down Expand Up @@ -1622,6 +1626,8 @@
"outputs": [],
"source": [
"# a user defined aggregation function.\n",
"\n",
"\n",
"def udaf(df):\n",
" return df[\"b\"].max() - df[\"b\"].min() / 2"
]
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ select = [
"F",
# pycodestyle Warning
"W",
# isort
"I",
# no-blank-line-before-function
"D201",
# one-blank-line-after-class
Expand Down
18 changes: 7 additions & 11 deletions python/cudf/benchmarks/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,23 @@
# into the main repo.
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "common"))

from config import cudf # noqa: W0611, E402, F401
from utils import ( # noqa: E402
OrderedSet,
collapse_fixtures,
column_generators,
make_fixture,
)

# Turn off isort until we upgrade to 5.8.0
# https://github.com/pycqa/isort/issues/1594
# isort: off
from config import ( # noqa: W0611, E402, F401
NUM_COLS,
NUM_ROWS,
collect_ignore,
cudf, # noqa: W0611, E402, F401
pytest_collection_modifyitems,
pytest_sessionfinish,
pytest_sessionstart,
)

# isort: on
from utils import ( # noqa: E402
OrderedSet,
collapse_fixtures,
column_generators,
make_fixture,
)


@pytest_cases.fixture(params=[0, 1], ids=["AxisIndex", "AxisColumn"])
Expand Down
10 changes: 5 additions & 5 deletions python/cudf/cudf/_typing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2021-2024, NVIDIA CORPORATION.

import sys
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Dict, Iterable, TypeVar, Union
from collections.abc import Callable, Iterable
from typing import TYPE_CHECKING, Any, TypeVar, Union

import numpy as np
from pandas import Period, Timedelta, Timestamp
Expand Down Expand Up @@ -42,7 +42,7 @@
SeriesOrSingleColumnIndex = Union["cudf.Series", "cudf.core.index.Index"]

# Groupby aggregation
AggType = Union[str, Callable]
MultiColumnAggType = Union[
AggType, Iterable[AggType], Dict[Any, Iterable[AggType]]
AggType = Union[str, Callable] # noqa: UP007
MultiColumnAggType = Union[ # noqa: UP007
AggType, Iterable[AggType], dict[Any, Iterable[AggType]]
]
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/buffer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pickle
import weakref
from types import SimpleNamespace
from typing import Any, Literal, Mapping
from typing import TYPE_CHECKING, Any, Literal

import numpy
from typing_extensions import Self
Expand All @@ -18,6 +18,9 @@
from cudf.core.abc import Serializable
from cudf.utils.string import format_bytes

if TYPE_CHECKING:
from collections.abc import Mapping


def host_memory_allocation(nbytes: int) -> memoryview:
"""Allocate host memory using NumPy
Expand Down
5 changes: 4 additions & 1 deletion python/cudf/cudf/core/buffer/exposure_tracked_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

from __future__ import annotations

from typing import Literal, Mapping
from typing import TYPE_CHECKING, Literal

from typing_extensions import Self

import cudf
from cudf.core.buffer.buffer import Buffer, BufferOwner

if TYPE_CHECKING:
from collections.abc import Mapping


class ExposureTrackedBuffer(Buffer):
"""An exposure tracked buffer.
Expand Down
1 change: 0 additions & 1 deletion python/cudf/cudf/core/column/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
Decimal128Column,
DecimalBaseColumn,
)
from cudf.core.column.interval import IntervalColumn # noqa: F401
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import warnings
from functools import cached_property
from typing import TYPE_CHECKING, Any, Mapping, Sequence, cast
from typing import TYPE_CHECKING, Any, cast

import numpy as np
import pandas as pd
Expand All @@ -26,6 +26,7 @@

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

import numba.cuda

Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/column/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import pickle
from collections import abc
from collections.abc import MutableSequence, Sequence
from functools import cached_property
from itertools import chain
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, Literal, MutableSequence, Sequence, cast
from typing import TYPE_CHECKING, Any, Literal, cast

import cupy
import numpy as np
Expand Down
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/column/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import locale
import re
from locale import nl_langinfo
from typing import TYPE_CHECKING, Literal, Sequence, cast
from typing import TYPE_CHECKING, Literal, cast

import numpy as np
import pandas as pd
Expand All @@ -31,6 +31,8 @@
from cudf.utils.utils import _all_bools_with_nulls

if TYPE_CHECKING:
from collections.abc import Sequence

from cudf._typing import (
ColumnBinaryOperand,
DatetimeLikeScalar,
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/column/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from __future__ import annotations

import warnings
from collections.abc import Sequence
from decimal import Decimal
from typing import TYPE_CHECKING, Sequence, cast
from typing import TYPE_CHECKING, cast

import cupy as cp
import numpy as np
Expand Down
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/column/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from functools import cached_property
from typing import TYPE_CHECKING, Sequence, cast
from typing import TYPE_CHECKING, cast

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -34,6 +34,8 @@
from cudf.core.missing import NA

if TYPE_CHECKING:
from collections.abc import Sequence

from cudf._typing import ColumnBinaryOperand, ColumnLike, Dtype, ScalarLike
from cudf.core.buffer import Buffer

Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/core/column/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from __future__ import annotations

from typing import Union, overload

from typing_extensions import Literal
from typing import Literal, Union, overload

import cudf
import cudf.core.column
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/column/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import functools
from typing import TYPE_CHECKING, Any, Sequence, cast
from typing import TYPE_CHECKING, Any, cast

import numpy as np
import pandas as pd
Expand All @@ -28,7 +28,7 @@
from .numerical_base import NumericalBaseColumn

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

from cudf._typing import (
ColumnBinaryOperand,
Expand Down
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/column/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import re
import warnings
from functools import cached_property
from typing import TYPE_CHECKING, Sequence, cast, overload
from typing import TYPE_CHECKING, cast, overload

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -35,6 +35,8 @@ def str_to_boolean(column: StringColumn):


if TYPE_CHECKING:
from collections.abc import Sequence

import cupy
import numba.cuda

Expand Down
4 changes: 3 additions & 1 deletion python/cudf/cudf/core/column/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import datetime
import functools
from typing import TYPE_CHECKING, Sequence, cast
from typing import TYPE_CHECKING, cast

import numpy as np
import pandas as pd
Expand All @@ -19,6 +19,8 @@
from cudf.utils.utils import _all_bools_with_nulls

if TYPE_CHECKING:
from collections.abc import Sequence

from cudf._typing import ColumnBinaryOperand, DatetimeLikeScalar, Dtype

_unit_to_nanoseconds_conversion = {
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/core/column_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import itertools
import sys
from collections import abc
from collections.abc import Mapping
from functools import cached_property, reduce
from typing import TYPE_CHECKING, Any, Mapping, cast
from typing import TYPE_CHECKING, Any, cast

import numpy as np
import pandas as pd
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import textwrap
import warnings
from collections import abc, defaultdict
from collections.abc import Callable, Iterator
from typing import TYPE_CHECKING, Any, Literal, MutableMapping, cast
from collections.abc import Callable, Iterator, MutableMapping
from typing import TYPE_CHECKING, Any, Literal, cast

import cupy
import numba
Expand Down
7 changes: 5 additions & 2 deletions python/cudf/cudf/core/df_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import enum
from collections import abc
from typing import Any, Iterable, Mapping, Sequence, Tuple, cast
from typing import TYPE_CHECKING, Any, cast

import cupy as cp
import numpy as np
Expand All @@ -20,6 +20,9 @@
build_column,
)

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping, Sequence

# Implementation of interchange protocol classes
# ----------------------------------------------

Expand Down Expand Up @@ -61,7 +64,7 @@ class _MaskKind(enum.IntEnum):
_DtypeKind.BOOL,
_DtypeKind.STRING,
}
ProtoDtype = Tuple[_DtypeKind, int, str, str]
ProtoDtype = tuple[_DtypeKind, int, str, str]


class _CuDFBuffer:
Expand Down
Loading

0 comments on commit 5cba4fb

Please sign in to comment.