Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: replace isort with Ruff's rule I #16685

Merged
merged 23 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 2 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
needs: ${{ toJSON(needs) }}
changed-files:
secrets: inherit
uses: rapidsai/shared-workflows/.github/workflows/[email protected]
# TODO: Change back to @branch-24.12 before merging
uses: rapidsai/shared-workflows/.github/workflows/changed-files.yaml@fix-changed-files-too-long
KyleFromNVIDIA marked this conversation as resolved.
Show resolved Hide resolved
with:
files_yaml: |
test_cpp:
Expand Down
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
1 change: 0 additions & 1 deletion docs/cudf/source/developer_guide/contributing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ The `.pre-commit-config.yaml` file at the root of the repo is the primary source
Specifically, cuDF uses the following tools:

- [`ruff`](https://beta.ruff.rs/) checks for general code formatting compliance.
bdice marked this conversation as resolved.
Show resolved Hide resolved
- [`isort`](https://pycqa.github.io/isort/) ensures imports are sorted consistently.
- [`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
2 changes: 1 addition & 1 deletion python/cudf/benchmarks/API/bench_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import string

from config import cudf, cupy
import numba.cuda
import numpy
import pytest
import pytest_cases
from config import cudf, cupy
from utils import benchmark_with_object


Expand Down
2 changes: 1 addition & 1 deletion python/cudf/benchmarks/API/bench_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

"""Benchmarks of free functions that accept cudf objects."""

from config import NUM_ROWS, cudf, cupy
import numpy as np
import pytest
import pytest_cases
from config import NUM_ROWS, cudf, cupy
from utils import benchmark_with_object


Expand Down
4 changes: 2 additions & 2 deletions python/cudf/benchmarks/API/bench_index.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

"""Benchmarks of Index methods."""

import pytest
from config import cudf, cupy
import pytest
from utils import benchmark_with_object


Expand Down
2 changes: 1 addition & 1 deletion python/cudf/benchmarks/API/bench_multiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

"""Benchmarks of MultiIndex methods."""

from config import cudf
import numpy as np
import pandas as pd
import pytest
from config import cudf


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/benchmarks/API/bench_series.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

"""Benchmarks of Series methods."""

import pytest
from config import cudf, cupy
import pytest
from utils import benchmark_with_object


Expand Down
2 changes: 1 addition & 1 deletion python/cudf/benchmarks/API/cases_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

"""Test cases for benchmarks in bench_functions.py."""

import pytest_cases
from config import NUM_ROWS, cudf, cupy
import pytest_cases


@pytest_cases.parametrize("nr", NUM_ROWS)
Expand Down
10 changes: 5 additions & 5 deletions python/cudf/benchmarks/common/utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Copyright (c) 2022, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

"""Common utilities for fixture creation and benchmarking."""

import inspect
import re
import textwrap
from collections.abc import MutableSet
import inspect
from itertools import groupby
from numbers import Real
import re
import textwrap

import pytest_cases
from config import NUM_COLS, NUM_ROWS, cudf, cupy
import pytest_cases


def make_gather_map(len_gather_map: Real, len_column: Real, how: str):
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
2 changes: 1 addition & 1 deletion python/cudf/cudf/_fuzz_testing/json.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

from collections import abc
import logging
import random
from collections import abc

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_fuzz_testing/tests/fuzz_test_csv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

import sys
from io import StringIO
import sys

import pandas as pd

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.

from collections.abc import Callable, Iterable
import sys
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Dict, Iterable, TypeVar, Union
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]]
]
2 changes: 1 addition & 1 deletion python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from __future__ import annotations

import warnings
from collections import abc
from functools import wraps
from inspect import isclass
from typing import cast
import warnings

import cupy as cp
import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from __future__ import annotations

import pickle
import warnings
from functools import cached_property
import pickle
from typing import TYPE_CHECKING, Any, Literal
import warnings

import pandas as pd
from typing_extensions import Self
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/_compat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

import pandas as pd
from packaging import version
import pandas as pd

PANDAS_CURRENT_SUPPORTED_VERSION = version.parse("2.2.3")
PANDAS_VERSION = version.parse(pd.__version__)
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/_internals/timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from __future__ import annotations

import datetime
import os
import zoneinfo
from functools import lru_cache
import os
from typing import TYPE_CHECKING, Literal
import zoneinfo

import numpy as np
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/_internals/where.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING
import warnings

import numpy as np

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/algorithms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING
import warnings

import cupy as cp
import numpy as np
Expand Down
7 changes: 5 additions & 2 deletions python/cudf/cudf/core/buffer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import math
import pickle
import weakref
from types import SimpleNamespace
from typing import Any, Literal, Mapping
from typing import TYPE_CHECKING, Any, Literal
import weakref

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
Loading
Loading