Skip to content

Commit 2522b0a

Browse files
authored
STY: Use ruff instead of black for formatting (#56704)
* STY: Use ruff instead of black for formatting * mypy * move pylint * Remove trailing comma:
1 parent c4b6bed commit 2522b0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+235
-339
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ ci:
1818
# manual stage hooks
1919
skip: [pylint, pyright, mypy]
2020
repos:
21-
- repo: https://github.com/hauntsaninja/black-pre-commit-mirror
22-
# black compiled with mypyc
23-
rev: 23.11.0
24-
hooks:
25-
- id: black
2621
- repo: https://github.com/astral-sh/ruff-pre-commit
2722
rev: v0.1.6
2823
hooks:
@@ -35,6 +30,9 @@ repos:
3530
files: ^pandas
3631
exclude: ^pandas/tests
3732
args: [--select, "ANN001,ANN2", --fix-only, --exit-non-zero-on-fix]
33+
- id: ruff-format
34+
# TODO: "." not needed in ruff 0.1.8
35+
args: ["."]
3836
- repo: https://github.com/jendrikseipp/vulture
3937
rev: 'v2.10'
4038
hooks:

asv_bench/benchmarks/indexing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ def time_loc_slice(self, index, index_structure):
8484

8585
class NumericMaskedIndexing:
8686
monotonic_list = list(range(10**6))
87-
non_monotonic_list = (
88-
list(range(50)) + [54, 53, 52, 51] + list(range(55, 10**6 - 1))
89-
)
87+
non_monotonic_list = list(range(50)) + [54, 53, 52, 51] + list(range(55, 10**6 - 1))
9088

9189
params = [
9290
("Int64", "UInt64", "Float64"),

asv_bench/benchmarks/io/style.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def _style_format(self):
7676
# apply a formatting function
7777
# subset is flexible but hinders vectorised solutions
7878
self.st = self.df.style.format(
79-
"{:,.3f}", subset=IndexSlice["row_1":f"row_{ir}", "float_1":f"float_{ic}"]
79+
"{:,.3f}",
80+
subset=IndexSlice["row_1" : f"row_{ir}", "float_1" : f"float_{ic}"],
8081
)
8182

8283
def _style_apply_format_hide(self):

doc/source/development/contributing_codebase.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Pre-commit
3838
----------
3939

4040
Additionally, :ref:`Continuous Integration <contributing.ci>` will run code formatting checks
41-
like ``black``, ``ruff``,
41+
like ``ruff``,
4242
``isort``, and ``clang-format`` and more using `pre-commit hooks <https://pre-commit.com/>`_.
4343
Any warnings from these checks will cause the :ref:`Continuous Integration <contributing.ci>` to fail; therefore,
4444
it is helpful to run the check yourself before submitting code. This

pandas/_libs/hashtable.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,18 @@ class HashTable:
196196
*,
197197
return_inverse: Literal[True],
198198
mask: None = ...,
199-
) -> tuple[np.ndarray, npt.NDArray[np.intp],]: ... # np.ndarray[subclass-specific]
199+
) -> tuple[np.ndarray, npt.NDArray[np.intp]]: ... # np.ndarray[subclass-specific]
200200
@overload
201201
def unique(
202202
self,
203203
values: np.ndarray, # np.ndarray[subclass-specific]
204204
*,
205205
return_inverse: Literal[False] = ...,
206206
mask: npt.NDArray[np.bool_],
207-
) -> tuple[np.ndarray, npt.NDArray[np.bool_],]: ... # np.ndarray[subclass-specific]
207+
) -> tuple[
208+
np.ndarray,
209+
npt.NDArray[np.bool_],
210+
]: ... # np.ndarray[subclass-specific]
208211
def factorize(
209212
self,
210213
values: np.ndarray, # np.ndarray[subclass-specific]

pandas/_libs/lib.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def indices_fast(
179179
sorted_labels: list[npt.NDArray[np.int64]],
180180
) -> dict[Hashable, npt.NDArray[np.intp]]: ...
181181
def generate_slices(
182-
labels: np.ndarray, ngroups: int # const intp_t[:]
182+
labels: np.ndarray,
183+
ngroups: int, # const intp_t[:]
183184
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...
184185
def count_level_2d(
185186
mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True],
@@ -209,5 +210,6 @@ def get_reverse_indexer(
209210
def is_bool_list(obj: list) -> bool: ...
210211
def dtypes_all_equal(types: list[DtypeObj]) -> bool: ...
211212
def is_range_indexer(
212-
left: np.ndarray, n: int # np.ndarray[np.int64, ndim=1]
213+
left: np.ndarray,
214+
n: int, # np.ndarray[np.int64, ndim=1]
213215
) -> bool: ...

pandas/_testing/_hypothesis.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@
5454
DATETIME_NO_TZ = st.datetimes()
5555

5656
DATETIME_JAN_1_1900_OPTIONAL_TZ = st.datetimes(
57-
min_value=pd.Timestamp(
58-
1900, 1, 1
59-
).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues]
60-
max_value=pd.Timestamp(
61-
1900, 1, 1
62-
).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues]
57+
min_value=pd.Timestamp(1900, 1, 1).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues]
58+
max_value=pd.Timestamp(1900, 1, 1).to_pydatetime(), # pyright: ignore[reportGeneralTypeIssues]
6359
timezones=st.one_of(st.none(), dateutil_timezones(), pytz_timezones()),
6460
)
6561

pandas/core/apply.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,8 @@ def wrapper(*args, **kwargs):
10101010
# [..., Any] | str] | dict[Hashable,Callable[..., Any] | str |
10111011
# list[Callable[..., Any] | str]]"; expected "Hashable"
10121012
nb_looper = generate_apply_looper(
1013-
self.func, **engine_kwargs # type: ignore[arg-type]
1013+
self.func, # type: ignore[arg-type]
1014+
**engine_kwargs,
10141015
)
10151016
result = nb_looper(self.values, self.axis)
10161017
# If we made the result 2-D, squeeze it back to 1-D

pandas/core/arrays/_arrow_string_mixins.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def _str_get(self, i: int) -> Self:
5858
self._pa_array, start=start, stop=stop, step=step
5959
)
6060
null_value = pa.scalar(
61-
None, type=self._pa_array.type # type: ignore[attr-defined]
61+
None,
62+
type=self._pa_array.type, # type: ignore[attr-defined]
6263
)
6364
result = pc.if_else(not_out_of_bounds, selected, null_value)
6465
return type(self)(result)

pandas/core/arrays/_mixins.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ def fillna(
347347
# error: Argument 2 to "check_value_size" has incompatible type
348348
# "ExtensionArray"; expected "ndarray"
349349
value = missing.check_value_size(
350-
value, mask, len(self) # type: ignore[arg-type]
350+
value,
351+
mask, # type: ignore[arg-type]
352+
len(self),
351353
)
352354

353355
if mask.any():

0 commit comments

Comments
 (0)