Skip to content

Commit cc4f585

Browse files
authored
STY: Bump pre-commit checks (#61246)
* Bump pre-commit version, bump clang-format and meson * Fix type checking abbreviation * Bump to 0.11.4 * Put minimum version at 4 * Change misc to arg-type
1 parent 1bcdfd0 commit cc4f585

24 files changed

+42
-42
lines changed

.pre-commit-config.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
minimum_pre_commit_version: 2.15.0
1+
minimum_pre_commit_version: 4.0.0
22
exclude: ^LICENSES/|\.(html|csv|svg)$
33
# reserve "manual" for relatively slow hooks which we still want to run in CI
44
default_stages: [
@@ -19,13 +19,13 @@ ci:
1919
skip: [pyright, mypy]
2020
repos:
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.9.9
22+
rev: v0.11.4
2323
hooks:
2424
- id: ruff
2525
args: [--exit-non-zero-on-fix]
2626
exclude: ^pandas/tests/frame/test_query_eval.py
2727
- id: ruff
28-
# TODO: remove autofixe-only rules when they are checked by ruff
28+
# TODO: remove autofix only rules when they are checked by ruff
2929
name: ruff-selected-autofixes
3030
alias: ruff-selected-autofixes
3131
files: ^pandas
@@ -34,7 +34,7 @@ repos:
3434
- id: ruff-format
3535
exclude: ^scripts|^pandas/tests/frame/test_query_eval.py
3636
- repo: https://github.com/jendrikseipp/vulture
37-
rev: 'v2.14'
37+
rev: v2.14
3838
hooks:
3939
- id: vulture
4040
entry: python scripts/run_vulture.py
@@ -95,14 +95,14 @@ repos:
9595
- id: sphinx-lint
9696
args: ["--enable", "all", "--disable", "line-too-long"]
9797
- repo: https://github.com/pre-commit/mirrors-clang-format
98-
rev: v19.1.7
98+
rev: v20.1.0
9999
hooks:
100100
- id: clang-format
101101
files: ^pandas/_libs/src|^pandas/_libs/include
102102
args: [-i]
103103
types_or: [c, c++]
104104
- repo: https://github.com/trim21/pre-commit-mirror-meson
105-
rev: v1.7.0
105+
rev: v1.7.2
106106
hooks:
107107
- id: meson-fmt
108108
args: ['--inplace']

asv_bench/benchmarks/frame_methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def setup(self):
517517
self.df = DataFrame(np.random.randn(1000, 100))
518518

519519
self.s = Series(np.arange(1028.0))
520-
self.df2 = DataFrame({i: self.s for i in range(1028)})
520+
self.df2 = DataFrame(dict.fromkeys(range(1028), self.s))
521521
self.df3 = DataFrame(np.random.randn(1000, 3), columns=list("ABC"))
522522

523523
def time_apply_user_func(self):

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ dependencies:
8080
- flake8=7.1.0 # run in subprocess over docstring examples
8181
- mypy=1.13.0 # pre-commit uses locally installed mypy
8282
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
83-
- pre-commit>=4.0.1
83+
- pre-commit>=4.2.0
8484

8585
# documentation
8686
- gitpython # obtain contributors from git for whatsnew

pandas/_libs/tslibs/timedeltas.pyi

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from typing import (
33
ClassVar,
44
Literal,
55
TypeAlias,
6-
TypeVar,
76
overload,
87
)
98

@@ -60,7 +59,6 @@ UnitChoices: TypeAlias = Literal[
6059
"nanos",
6160
"nanosecond",
6261
]
63-
_S = TypeVar("_S", bound=timedelta)
6462

6563
def get_unit_for_round(freq, creso: int) -> int: ...
6664
def disallow_ambiguous_unit(unit: str | None) -> None: ...
@@ -95,11 +93,11 @@ class Timedelta(timedelta):
9593
_value: int # np.int64
9694
# error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
9795
def __new__( # type: ignore[misc]
98-
cls: type[_S],
96+
cls: type[Self],
9997
value=...,
10098
unit: str | None = ...,
10199
**kwargs: float | np.integer | np.floating,
102-
) -> _S | NaTType: ...
100+
) -> Self | NaTType: ...
103101
@classmethod
104102
def _from_value_and_reso(cls, value: np.int64, reso: int) -> Timedelta: ...
105103
@property

pandas/core/apply.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def transform(self) -> DataFrame | Series:
327327
if is_series:
328328
func = {com.get_callable_name(v) or v: v for v in func}
329329
else:
330-
func = {col: func for col in obj}
330+
func = dict.fromkeys(obj, func)
331331

332332
if is_dict_like(func):
333333
func = cast(AggFuncTypeDict, func)

pandas/core/arrays/string_arrow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:
281281
]
282282

283283
# short-circuit to return all False array.
284-
if not len(value_set):
284+
if not value_set:
285285
return np.zeros(len(self), dtype=bool)
286286

287287
result = pc.is_in(

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9705,7 +9705,7 @@ def _where(
97059705
# CoW: Make sure reference is not kept alive
97069706
if cond.ndim == 1 and self.ndim == 2:
97079707
cond = cond._constructor_expanddim(
9708-
{i: cond for i in range(len(self.columns))},
9708+
dict.fromkeys(range(len(self.columns)), cond),
97099709
copy=False,
97109710
)
97119711
cond.columns = self.columns

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,7 @@ def _apply_to_column_groupbys(self, func) -> DataFrame:
25052505
)
25062506
results = [func(sgb) for sgb in sgbs]
25072507

2508-
if not len(results):
2508+
if not results:
25092509
# concat would raise
25102510
res_df = DataFrame([], columns=columns, index=self._grouper.result_index)
25112511
else:

pandas/core/groupby/groupby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5175,8 +5175,8 @@ def diff(
51755175
shifted = shifted.astype("float32")
51765176
else:
51775177
to_coerce = [c for c, dtype in obj.dtypes.items() if dtype in dtypes_to_f32]
5178-
if len(to_coerce):
5179-
shifted = shifted.astype({c: "float32" for c in to_coerce})
5178+
if to_coerce:
5179+
shifted = shifted.astype(dict.fromkeys(to_coerce, "float32"))
51805180

51815181
return obj - shifted
51825182

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def replace_list(
805805
for x, y in zip(src_list, dest_list)
806806
if (self._can_hold_element(x) or (self.dtype == "string" and is_re(x)))
807807
]
808-
if not len(pairs):
808+
if not pairs:
809809
return [self.copy(deep=False)]
810810

811811
src_len = len(pairs) - 1

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ def _finalize_columns_and_data(
864864
# GH#26429 do not raise user-facing AssertionError
865865
raise ValueError(err) from err
866866

867-
if len(contents) and contents[0].dtype == np.object_:
867+
if contents and contents[0].dtype == np.object_:
868868
contents = convert_object_array(contents, dtype=dtype)
869869

870870
return contents, columns

pandas/core/internals/managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ def value_getitem(placement):
12981298
# Defer setting the new values to enable consolidation
12991299
self._iset_split_block(blkno_l, blk_locs, refs=refs)
13001300

1301-
if len(removed_blknos):
1301+
if removed_blknos:
13021302
# Remove blocks & update blknos accordingly
13031303
is_deleted = np.zeros(self.nblocks, dtype=np.bool_)
13041304
is_deleted[removed_blknos] = True

pandas/io/formats/format.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def _initialize_colspace(self, col_space: ColspaceArgType | None) -> ColspaceTyp
566566
result = {}
567567
elif isinstance(col_space, (int, str)):
568568
result = {"": col_space}
569-
result.update({column: col_space for column in self.frame.columns})
569+
result.update(dict.fromkeys(self.frame.columns, col_space))
570570
elif isinstance(col_space, Mapping):
571571
for column in col_space.keys():
572572
if column not in self.frame.columns and column != "":

pandas/io/formats/style_render.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def format(
12251225
data = self.data.loc[subset]
12261226

12271227
if not isinstance(formatter, dict):
1228-
formatter = {col: formatter for col in data.columns}
1228+
formatter = dict.fromkeys(data.columns, formatter)
12291229

12301230
cis = self.columns.get_indexer_for(data.columns)
12311231
ris = self.index.get_indexer_for(data.index)
@@ -1411,7 +1411,7 @@ def format_index(
14111411
return self # clear the formatter / revert to default and avoid looping
14121412

14131413
if not isinstance(formatter, dict):
1414-
formatter = {level: formatter for level in levels_}
1414+
formatter = dict.fromkeys(levels_, formatter)
14151415
else:
14161416
formatter = {
14171417
obj._get_level_number(level): formatter_
@@ -1708,7 +1708,7 @@ def format_index_names(
17081708
return self # clear the formatter / revert to default and avoid looping
17091709

17101710
if not isinstance(formatter, dict):
1711-
formatter = {level: formatter for level in levels_}
1711+
formatter = dict.fromkeys(levels_, formatter)
17121712
else:
17131713
formatter = {
17141714
obj._get_level_number(level): formatter_

pandas/io/pytables.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ def info(self) -> str:
17601760

17611761
if self.is_open:
17621762
lkeys = sorted(self.keys())
1763-
if len(lkeys):
1763+
if lkeys:
17641764
keys = []
17651765
values = []
17661766

@@ -4540,7 +4540,7 @@ def write_data(self, chunksize: int | None, dropna: bool = False) -> None:
45404540
masks.append(mask.astype("u1", copy=False))
45414541

45424542
# consolidate masks
4543-
if len(masks):
4543+
if masks:
45444544
mask = masks[0]
45454545
for m in masks[1:]:
45464546
mask = mask & m
@@ -4660,7 +4660,7 @@ def delete(
46604660
groups = list(diff[diff > 1].index)
46614661

46624662
# 1 group
4663-
if not len(groups):
4663+
if not groups:
46644664
groups = [0]
46654665

46664666
# final element

pandas/io/sql.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ def prep_table(
19011901
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
19021902
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
19031903
# dtype[Any], Type[object]]"
1904-
dtype = {col_name: dtype for col_name in frame} # type: ignore[misc]
1904+
dtype = dict.fromkeys(frame, dtype) # type: ignore[arg-type]
19051905
else:
19061906
dtype = cast(dict, dtype)
19071907

@@ -2615,7 +2615,7 @@ def _create_table_setup(self):
26152615
]
26162616

26172617
ix_cols = [cname for cname, _, is_index in column_names_and_types if is_index]
2618-
if len(ix_cols):
2618+
if ix_cols:
26192619
cnames = "_".join(ix_cols)
26202620
cnames_br = ",".join([escape(c) for c in ix_cols])
26212621
create_stmts.append(
@@ -2859,7 +2859,7 @@ def to_sql(
28592859
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
28602860
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
28612861
# dtype[Any], Type[object]]"
2862-
dtype = {col_name: dtype for col_name in frame} # type: ignore[misc]
2862+
dtype = dict.fromkeys(frame, dtype) # type: ignore[arg-type]
28632863
else:
28642864
dtype = cast(dict, dtype)
28652865

pandas/tests/apply/test_frame_apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def test_apply_broadcast_scalars(float_frame):
334334
def test_apply_broadcast_scalars_axis1(float_frame):
335335
result = float_frame.apply(np.mean, axis=1, result_type="broadcast")
336336
m = float_frame.mean(axis=1)
337-
expected = DataFrame({c: m for c in float_frame.columns})
337+
expected = DataFrame(dict.fromkeys(float_frame.columns, m))
338338
tm.assert_frame_equal(result, expected)
339339

340340

@@ -361,7 +361,7 @@ def test_apply_broadcast_lists_index(float_frame):
361361
)
362362
m = list(range(len(float_frame.index)))
363363
expected = DataFrame(
364-
{c: m for c in float_frame.columns},
364+
dict.fromkeys(float_frame.columns, m),
365365
dtype="float64",
366366
index=float_frame.index,
367367
)

pandas/tests/dtypes/cast/test_maybe_box_native.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"obj,expected_dtype",
1818
[
1919
(b"\x00\x10", bytes),
20-
(int(4), int),
20+
((4), int),
2121
(np.uint(4), int),
2222
(np.int32(-4), int),
2323
(np.uint8(4), int),

pandas/tests/io/parser/test_na_values.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def test_na_values_dict_null_column_name(all_parsers):
546546
parser = all_parsers
547547
data = ",x,y\n\nMA,1,2\nNA,2,1\nOA,,3"
548548
names = [None, "x", "y"]
549-
na_values = {name: STR_NA_VALUES for name in names}
549+
na_values = dict.fromkeys(names, STR_NA_VALUES)
550550
dtype = {None: "object", "x": "float64", "y": "float64"}
551551

552552
if parser.engine == "pyarrow":

pandas/tests/series/accessors/test_cat_accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_getname_categorical_accessor(self, method):
4040
def test_cat_accessor(self):
4141
ser = Series(Categorical(["a", "b", np.nan, "a"]))
4242
tm.assert_index_equal(ser.cat.categories, Index(["a", "b"]))
43-
assert not ser.cat.ordered, False
43+
assert not ser.cat.ordered
4444

4545
exp = Categorical(["a", "b", np.nan, "a"], categories=["b", "a"])
4646

pandas/tests/series/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def test_constructor_maskedarray_hardened(self):
632632

633633
def test_series_ctor_plus_datetimeindex(self):
634634
rng = date_range("20090415", "20090519", freq="B")
635-
data = {k: 1 for k in rng}
635+
data = dict.fromkeys(rng, 1)
636636

637637
result = Series(data, index=rng)
638638
assert result.index.is_(rng)

pyproject.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ select = [
234234
"TID",
235235
# implicit string concatenation
236236
"ISC",
237-
# type-checking imports
238-
"TCH",
237+
# flake8-type-checking
238+
"TC",
239239
# comprehensions
240240
"C4",
241241
# pygrep-hooks
@@ -390,6 +390,8 @@ ignore = [
390390
"PLW0108",
391391
# global-statement
392392
"PLW0603",
393+
# runtime-cast-value
394+
"TC006",
393395
]
394396

395397
exclude = [
@@ -429,7 +431,7 @@ exclude = [
429431
"pandas/tests/*" = ["B028", "FLY"]
430432
"scripts/*" = ["B028"]
431433
# Keep this one enabled
432-
"pandas/_typing.py" = ["TCH"]
434+
"pandas/_typing.py" = ["TC"]
433435

434436
[tool.ruff.lint.flake8-pytest-style]
435437
fixture-parentheses = false

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ asv>=0.6.1
5757
flake8==7.1.0
5858
mypy==1.13.0
5959
tokenize-rt
60-
pre-commit>=4.0.1
60+
pre-commit>=4.2.0
6161
gitpython
6262
gitdb
6363
google-auth

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def run(self) -> None:
364364
# enable coverage by building cython files by setting the environment variable
365365
# "PANDAS_CYTHON_COVERAGE" (with a Truthy value) or by running build_ext
366366
# with `--with-cython-coverage`enabled
367-
linetrace = os.environ.get("PANDAS_CYTHON_COVERAGE", False)
367+
linetrace = os.environ.get("PANDAS_CYTHON_COVERAGE", False) # noqa: PLW1508
368368
if "--with-cython-coverage" in sys.argv:
369369
linetrace = True
370370
sys.argv.remove("--with-cython-coverage")

0 commit comments

Comments
 (0)