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

Replace black with ruff-format #15312

Merged
merged 10 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 2 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ repos:
args: ["--config-root=python/", "--resolve-all-configs"]
files: python/.*
types_or: [python, cython, pyi]
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
files: python/.*
# Explicitly specify the pyproject.toml at the repo root, not per-project.
args: ["--config", "pyproject.toml"]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.0
hooks:
Expand Down Expand Up @@ -155,6 +148,8 @@ repos:
hooks:
- id: ruff
files: python/.*$
- id: ruff-format
files: python/.*$
- repo: https://github.com/rapidsai/pre-commit-hooks
rev: v0.0.1
hooks:
Expand Down
22 changes: 2 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
[tool.black]
line-length = 79
target-version = ["py39"]
include = '\.py?$'
force-exclude = '''
/(
thirdparty |
\.eggs |
\.git |
\.hg |
\.mypy_cache |
\.tox |
\.venv |
_build |
buck-out |
build |
dist
)/
'''
# Copyright (c) 2019-2024, NVIDIA CORPORATION.

[tool.pydocstyle]
# Due to https://github.com/PyCQA/pydocstyle/issues/363, we must exclude rather
Expand Down Expand Up @@ -66,7 +48,7 @@ exclude = [
# TODO: Remove this in a follow-up where we fix __all__.
"__init__.py",
]
line-length = 88
line-length = 79

[tool.ruff.per-file-ignores]
mroeschke marked this conversation as resolved.
Show resolved Hide resolved
# Lots of pytest implicitly injected attributes in conftest-patch.py
Expand Down
5 changes: 3 additions & 2 deletions python/cudf/cudf/core/_internals/timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def _read_tzfile_as_frame(tzdir, zone_name):
if not transition_times_and_offsets:
# this happens for UTC-like zones
min_date = np.int64(np.iinfo("int64").min + 1).astype("M8[s]")
transition_times_and_offsets = as_column([min_date]), as_column(
[np.timedelta64(0, "s")]
transition_times_and_offsets = (
as_column([min_date]),
as_column([np.timedelta64(0, "s")]),
)

return DataFrame._from_data(
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 @@ -1731,7 +1731,8 @@ def as_column(
If None (default), treats NaN values in arbitrary as null if there is
no mask passed along with it. If True, combines the mask and NaNs to
form a new validity mask. If False, leaves NaN values as is.
Only applies when arbitrary is not a cudf object (Index, Series, Column).
Only applies when arbitrary is not a cudf object
(Index, Series, Column).
dtype : optional
Optionally typecast the constructed Column to the given
dtype.
Expand Down
33 changes: 21 additions & 12 deletions python/cudf/cudf/core/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,12 @@ class _DataFrameIlocIndexer(_DataFrameIndexer):
_frame: DataFrame

def __getitem__(self, arg):
row_key, (
col_is_scalar,
column_names,
(
row_key,
(
col_is_scalar,
column_names,
),
) = indexing_utils.destructure_dataframe_iloc_indexer(arg, self._frame)
row_spec = indexing_utils.parse_row_iloc_indexer(
row_key, len(self._frame)
Expand Down Expand Up @@ -6901,16 +6904,18 @@ def stack(self, level=-1, dropna=no_default, future_stack=False):
if future_stack:
if dropna is not no_default:
raise ValueError(
"dropna must be unspecified with future_stack=True as the new "
"implementation does not introduce rows of NA values. This "
"argument will be removed in a future version of cudf."
"dropna must be unspecified with future_stack=True as "
"the new implementation does not introduce rows of NA "
"values. This argument will be removed in a future "
"version of cudf."
)
else:
if dropna is not no_default or self._data.nlevels > 1:
warnings.warn(
"The previous implementation of stack is deprecated and will be "
"removed in a future version of cudf. Specify future_stack=True "
"to adopt the new implementation and silence this warning.",
"The previous implementation of stack is deprecated and "
"will be removed in a future version of cudf. Specify "
"future_stack=True to adopt the new implementation and "
"silence this warning.",
FutureWarning,
)
if dropna is no_default:
Expand Down Expand Up @@ -7028,9 +7033,13 @@ def unnamed_group_generator():
unique_named_levels, axis=0, fill_value=-1
).values
else:
yield grpdf.reindex(
unique_named_levels, axis=0, fill_value=-1
).sort_index().values
yield (
grpdf.reindex(
unique_named_levels, axis=0, fill_value=-1
)
.sort_index()
.values
)
else:
if future_stack:
yield column_idx_df.values
Expand Down
13 changes: 8 additions & 5 deletions python/cudf/cudf/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,12 @@ def __iter__(self):
if isinstance(group_names, cudf.BaseIndex):
group_names = group_names.to_pandas()
for i, name in enumerate(group_names):
yield (name,) if isinstance(self._by, list) and len(
self._by
) == 1 else name, grouped_values[offsets[i] : offsets[i + 1]]
yield (
(name,)
if isinstance(self._by, list) and len(self._by) == 1
else name,
grouped_values[offsets[i] : offsets[i + 1]],
)

@property
def dtypes(self):
Expand Down Expand Up @@ -2269,8 +2272,8 @@ def fillna(
"""
warnings.warn(
"groupby fillna is deprecated and "
"will be removed in a future version. Use groupby ffill or groupby bfill "
"for forward or backward filling instead.",
"will be removed in a future version. Use groupby ffill "
"or groupby bfill for forward or backward filling instead.",
FutureWarning,
)
if inplace:
Expand Down
35 changes: 11 additions & 24 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def _get_label_range_or_mask(index, start, stop, step):
return slice(start_loc, stop_loc)
else:
raise KeyError(
"Value based partial slicing on non-monotonic DatetimeIndexes "
"with non-existing keys is not allowed.",
"Value based partial slicing on non-monotonic "
"DatetimeIndexes with non-existing keys is not allowed.",
)
elif start is not None:
boolean_mask = index >= start
Expand Down Expand Up @@ -2449,7 +2449,8 @@ def squeeze(self, axis: Literal["index", "columns", 0, 1, None] = None):
----------
axis : {0 or 'index', 1 or 'columns', None}, default None
A specific axis to squeeze. By default, all length-1 axes are
squeezed. For `Series` this parameter is unused and defaults to `None`.
squeezed. For `Series` this parameter is unused and defaults
to `None`.

Returns
-------
Expand Down Expand Up @@ -5835,9 +5836,7 @@ def floordiv(self, other, axis, level=None, fill_value=None): # noqa: D102
),
)
)
def rfloordiv(
self, other, axis, level=None, fill_value=None
): # noqa: D102
def rfloordiv(self, other, axis, level=None, fill_value=None): # noqa: D102
if level is not None:
raise NotImplementedError("level parameter is not supported yet.")

Expand Down Expand Up @@ -5967,9 +5966,7 @@ def rtruediv(self, other, axis, level=None, fill_value=None): # noqa: D102
),
)
)
def eq(
self, other, axis="columns", level=None, fill_value=None
): # noqa: D102
def eq(self, other, axis="columns", level=None, fill_value=None): # noqa: D102
return self._binaryop(
other=other, op="__eq__", fill_value=fill_value, can_reindex=True
)
Expand Down Expand Up @@ -6009,9 +6006,7 @@ def eq(
),
)
)
def ne(
self, other, axis="columns", level=None, fill_value=None
): # noqa: D102
def ne(self, other, axis="columns", level=None, fill_value=None): # noqa: D102
return self._binaryop(
other=other, op="__ne__", fill_value=fill_value, can_reindex=True
)
Expand Down Expand Up @@ -6051,9 +6046,7 @@ def ne(
),
)
)
def lt(
self, other, axis="columns", level=None, fill_value=None
): # noqa: D102
def lt(self, other, axis="columns", level=None, fill_value=None): # noqa: D102
return self._binaryop(
other=other, op="__lt__", fill_value=fill_value, can_reindex=True
)
Expand Down Expand Up @@ -6093,9 +6086,7 @@ def lt(
),
)
)
def le(
self, other, axis="columns", level=None, fill_value=None
): # noqa: D102
def le(self, other, axis="columns", level=None, fill_value=None): # noqa: D102
return self._binaryop(
other=other, op="__le__", fill_value=fill_value, can_reindex=True
)
Expand Down Expand Up @@ -6135,9 +6126,7 @@ def le(
),
)
)
def gt(
self, other, axis="columns", level=None, fill_value=None
): # noqa: D102
def gt(self, other, axis="columns", level=None, fill_value=None): # noqa: D102
return self._binaryop(
other=other, op="__gt__", fill_value=fill_value, can_reindex=True
)
Expand Down Expand Up @@ -6177,9 +6166,7 @@ def gt(
),
)
)
def ge(
self, other, axis="columns", level=None, fill_value=None
): # noqa: D102
def ge(self, other, axis="columns", level=None, fill_value=None): # noqa: D102
return self._binaryop(
other=other, op="__ge__", fill_value=fill_value, can_reindex=True
)
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/resample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2021-2024, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2021-2024, NVIDIA CORPORATION & AFFILIATES. # noqa: E501
# All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want to make linter exceptions for the copyrights "inline". 😕 What alternatives do we have? A line length of 88 would permit this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost everywhere else (which is why we don't need it), we have NVIDIA CORPORATION rather than NVIDIA CORPORATION & AFFILIATES.

Not saying which is right/wrong, just noting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these files, it needs to stay as-is with the "& AFFILIATES".

# SPDX-License-Identifier: Apache-2.0
#
Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ def to_datetime(

if errors == "ignore":
warnings.warn(
"errors='ignore' is deprecated and will raise in a future version. "
"Use to_datetime without passing `errors` and catch exceptions "
"explicitly instead",
"errors='ignore' is deprecated and will raise in a "
"future version. Use to_datetime without passing `errors` "
"and catch exceptions explicitly instead",
FutureWarning,
)

Expand Down
6 changes: 3 additions & 3 deletions python/cudf/cudf/core/tools/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ def to_numeric(arg, errors="raise", downcast=None):
raise ValueError("invalid error value specified")
elif errors == "ignore":
warnings.warn(
"errors='ignore' is deprecated and will raise in a future version. "
"Use to_numeric without passing `errors` and catch exceptions "
"explicitly instead",
"errors='ignore' is deprecated and will raise in "
"a future version. Use to_numeric without passing `errors` "
"and catch exceptions explicitly instead",
FutureWarning,
)

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

import operator
from functools import partial
Expand Down Expand Up @@ -249,7 +249,7 @@ def replace_impl(context, builder, sig, args):
replacement_ptr = builder.alloca(args[2].type)

builder.store(args[0], src_ptr)
builder.store(args[1], to_replace_ptr),
builder.store(args[1], to_replace_ptr)
builder.store(args[2], replacement_ptr)

udf_str_ptr = builder.alloca(default_manager[udf_string].get_value_type())
Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/core/udf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
from cudf.utils.utils import initfunc

# Maximum size of a string column is 2 GiB
_STRINGS_UDF_DEFAULT_HEAP_SIZE = os.environ.get(
"STRINGS_UDF_HEAP_SIZE", 2**31
)
_STRINGS_UDF_DEFAULT_HEAP_SIZE = os.environ.get("STRINGS_UDF_HEAP_SIZE", 2**31)
_heap_size = 0
_cudf_str_dtype = dtype(str)

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/pandas/_wrappers/pandas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. # noqa: E501
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import copyreg
Expand Down
6 changes: 2 additions & 4 deletions python/cudf/cudf/pandas/fast_slow_proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. # noqa: E501
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -437,9 +437,7 @@ def __get__(self, obj, owner=None) -> Any:
# methods because dir for the method won't be the same as for
# the pure unbound function, but the alternative is
# materializing the slow object when we don't really want to.
result._fsproxy_slow_dir = dir(
slow_result_type
) # type: ignore
result._fsproxy_slow_dir = dir(slow_result_type) # type: ignore

return result

Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/pandas/module_accelerator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. # noqa: E501
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0

Expand Down
18 changes: 8 additions & 10 deletions python/cudf/cudf/pandas/profiler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
# SPDX-FileCopyrightText: Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. # noqa: E501
# All rights reserved.
# SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -124,7 +124,7 @@ def get_namespaced_function_name(
_MethodProxy,
type[_FinalProxy],
type[_IntermediateProxy],
]
],
):
if isinstance(func_obj, _MethodProxy):
# Extract classname from method object
Expand Down Expand Up @@ -177,17 +177,15 @@ def _tracefunc(self, frame, event, arg):
if self._currkey is not None and arg is not None:
if arg[1]: # fast
run_time = time.perf_counter() - self._timer[self._currkey]
self._results[self._currkey][
"gpu_time"
] = run_time + self._results[self._currkey].get(
"gpu_time", 0
self._results[self._currkey]["gpu_time"] = (
run_time
+ self._results[self._currkey].get("gpu_time", 0)
)
else:
run_time = time.perf_counter() - self._timer[self._currkey]
self._results[self._currkey][
"cpu_time"
] = run_time + self._results[self._currkey].get(
"cpu_time", 0
self._results[self._currkey]["cpu_time"] = (
run_time
+ self._results[self._currkey].get("cpu_time", 0)
)

frame_locals = inspect.getargvalues(frame).locals
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ def test_dataframe_reductions(data, axis, func, skipna):
for kwargs in all_kwargs:
if expected_exception is not None:
with pytest.raises(expected_exception):
getattr(gdf, func)(axis=axis, skipna=skipna, **kwargs),
(getattr(gdf, func)(axis=axis, skipna=skipna, **kwargs),)
else:
expect = getattr(pdf, func)(axis=axis, skipna=skipna, **kwargs)
with expect_warning_if(
Expand Down
Loading
Loading