Skip to content

STY: Bump pre-commit checks #61246

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

Merged
merged 5 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
minimum_pre_commit_version: 2.15.0
minimum_pre_commit_version: 4.0.0
exclude: ^LICENSES/|\.(html|csv|svg)$
# reserve "manual" for relatively slow hooks which we still want to run in CI
default_stages: [
Expand All @@ -19,13 +19,13 @@ ci:
skip: [pyright, mypy]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.9
rev: v0.11.4
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
exclude: ^pandas/tests/frame/test_query_eval.py
- id: ruff
# TODO: remove autofixe-only rules when they are checked by ruff
# TODO: remove autofix only rules when they are checked by ruff
name: ruff-selected-autofixes
alias: ruff-selected-autofixes
files: ^pandas
Expand All @@ -34,7 +34,7 @@ repos:
- id: ruff-format
exclude: ^scripts|^pandas/tests/frame/test_query_eval.py
- repo: https://github.com/jendrikseipp/vulture
rev: 'v2.14'
rev: v2.14
hooks:
- id: vulture
entry: python scripts/run_vulture.py
Expand Down Expand Up @@ -95,14 +95,14 @@ repos:
- id: sphinx-lint
args: ["--enable", "all", "--disable", "line-too-long"]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
rev: v20.1.0
hooks:
- id: clang-format
files: ^pandas/_libs/src|^pandas/_libs/include
args: [-i]
types_or: [c, c++]
- repo: https://github.com/trim21/pre-commit-mirror-meson
rev: v1.7.0
rev: v1.7.2
hooks:
- id: meson-fmt
args: ['--inplace']
Expand Down
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/frame_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def setup(self):
self.df = DataFrame(np.random.randn(1000, 100))

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

def time_apply_user_func(self):
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies:
- flake8=7.1.0 # run in subprocess over docstring examples
- mypy=1.13.0 # pre-commit uses locally installed mypy
- tokenize-rt # scripts/check_for_inconsistent_pandas_namespace.py
- pre-commit>=4.0.1
- pre-commit>=4.2.0

# documentation
- gitpython # obtain contributors from git for whatsnew
Expand Down
6 changes: 2 additions & 4 deletions pandas/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ from typing import (
ClassVar,
Literal,
TypeAlias,
TypeVar,
overload,
)

Expand Down Expand Up @@ -60,7 +59,6 @@ UnitChoices: TypeAlias = Literal[
"nanos",
"nanosecond",
]
_S = TypeVar("_S", bound=timedelta)

def get_unit_for_round(freq, creso: int) -> int: ...
def disallow_ambiguous_unit(unit: str | None) -> None: ...
Expand Down Expand Up @@ -95,11 +93,11 @@ class Timedelta(timedelta):
_value: int # np.int64
# error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]")
def __new__( # type: ignore[misc]
cls: type[_S],
cls: type[Self],
value=...,
unit: str | None = ...,
**kwargs: float | np.integer | np.floating,
) -> _S | NaTType: ...
) -> Self | NaTType: ...
@classmethod
def _from_value_and_reso(cls, value: np.int64, reso: int) -> Timedelta: ...
@property
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def transform(self) -> DataFrame | Series:
if is_series:
func = {com.get_callable_name(v) or v: v for v in func}
else:
func = {col: func for col in obj}
func = dict.fromkeys(obj, func)

if is_dict_like(func):
func = cast(AggFuncTypeDict, func)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]:
]

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

result = pc.is_in(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9705,7 +9705,7 @@ def _where(
# CoW: Make sure reference is not kept alive
if cond.ndim == 1 and self.ndim == 2:
cond = cond._constructor_expanddim(
{i: cond for i in range(len(self.columns))},
dict.fromkeys(range(len(self.columns)), cond),
copy=False,
)
cond.columns = self.columns
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ def _apply_to_column_groupbys(self, func) -> DataFrame:
)
results = [func(sgb) for sgb in sgbs]

if not len(results):
if not results:
# concat would raise
res_df = DataFrame([], columns=columns, index=self._grouper.result_index)
else:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -5175,8 +5175,8 @@ def diff(
shifted = shifted.astype("float32")
else:
to_coerce = [c for c, dtype in obj.dtypes.items() if dtype in dtypes_to_f32]
if len(to_coerce):
shifted = shifted.astype({c: "float32" for c in to_coerce})
if to_coerce:
shifted = shifted.astype(dict.fromkeys(to_coerce, "float32"))

return obj - shifted

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def replace_list(
for x, y in zip(src_list, dest_list)
if (self._can_hold_element(x) or (self.dtype == "string" and is_re(x)))
]
if not len(pairs):
if not pairs:
return [self.copy(deep=False)]

src_len = len(pairs) - 1
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ def _finalize_columns_and_data(
# GH#26429 do not raise user-facing AssertionError
raise ValueError(err) from err

if len(contents) and contents[0].dtype == np.object_:
if contents and contents[0].dtype == np.object_:
contents = convert_object_array(contents, dtype=dtype)

return contents, columns
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ def value_getitem(placement):
# Defer setting the new values to enable consolidation
self._iset_split_block(blkno_l, blk_locs, refs=refs)

if len(removed_blknos):
if removed_blknos:
# Remove blocks & update blknos accordingly
is_deleted = np.zeros(self.nblocks, dtype=np.bool_)
is_deleted[removed_blknos] = True
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def _initialize_colspace(self, col_space: ColspaceArgType | None) -> ColspaceTyp
result = {}
elif isinstance(col_space, (int, str)):
result = {"": col_space}
result.update({column: col_space for column in self.frame.columns})
result.update(dict.fromkeys(self.frame.columns, col_space))
elif isinstance(col_space, Mapping):
for column in col_space.keys():
if column not in self.frame.columns and column != "":
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/formats/style_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ def format(
data = self.data.loc[subset]

if not isinstance(formatter, dict):
formatter = {col: formatter for col in data.columns}
formatter = dict.fromkeys(data.columns, formatter)

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

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

if not isinstance(formatter, dict):
formatter = {level: formatter for level in levels_}
formatter = dict.fromkeys(levels_, formatter)
else:
formatter = {
obj._get_level_number(level): formatter_
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,7 @@ def info(self) -> str:

if self.is_open:
lkeys = sorted(self.keys())
if len(lkeys):
if lkeys:
keys = []
values = []

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

# consolidate masks
if len(masks):
if masks:
mask = masks[0]
for m in masks[1:]:
mask = mask & m
Expand Down Expand Up @@ -4660,7 +4660,7 @@ def delete(
groups = list(diff[diff > 1].index)

# 1 group
if not len(groups):
if not groups:
groups = [0]

# final element
Expand Down
6 changes: 3 additions & 3 deletions pandas/io/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ def prep_table(
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
# dtype[Any], Type[object]]"
dtype = {col_name: dtype for col_name in frame} # type: ignore[misc]
dtype = dict.fromkeys(frame, dtype) # type: ignore[arg-type]
else:
dtype = cast(dict, dtype)

Expand Down Expand Up @@ -2615,7 +2615,7 @@ def _create_table_setup(self):
]

ix_cols = [cname for cname, _, is_index in column_names_and_types if is_index]
if len(ix_cols):
if ix_cols:
cnames = "_".join(ix_cols)
cnames_br = ",".join([escape(c) for c in ix_cols])
create_stmts.append(
Expand Down Expand Up @@ -2859,7 +2859,7 @@ def to_sql(
# Type[str], Type[float], Type[int], Type[complex], Type[bool],
# Type[object]]]]"; expected type "Union[ExtensionDtype, str,
# dtype[Any], Type[object]]"
dtype = {col_name: dtype for col_name in frame} # type: ignore[misc]
dtype = dict.fromkeys(frame, dtype) # type: ignore[arg-type]
else:
dtype = cast(dict, dtype)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/apply/test_frame_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_apply_broadcast_scalars(float_frame):
def test_apply_broadcast_scalars_axis1(float_frame):
result = float_frame.apply(np.mean, axis=1, result_type="broadcast")
m = float_frame.mean(axis=1)
expected = DataFrame({c: m for c in float_frame.columns})
expected = DataFrame(dict.fromkeys(float_frame.columns, m))
tm.assert_frame_equal(result, expected)


Expand All @@ -361,7 +361,7 @@ def test_apply_broadcast_lists_index(float_frame):
)
m = list(range(len(float_frame.index)))
expected = DataFrame(
{c: m for c in float_frame.columns},
dict.fromkeys(float_frame.columns, m),
dtype="float64",
index=float_frame.index,
)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/cast/test_maybe_box_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"obj,expected_dtype",
[
(b"\x00\x10", bytes),
(int(4), int),
((4), int),
(np.uint(4), int),
(np.int32(-4), int),
(np.uint8(4), int),
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_na_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def test_na_values_dict_null_column_name(all_parsers):
parser = all_parsers
data = ",x,y\n\nMA,1,2\nNA,2,1\nOA,,3"
names = [None, "x", "y"]
na_values = {name: STR_NA_VALUES for name in names}
na_values = dict.fromkeys(names, STR_NA_VALUES)
dtype = {None: "object", "x": "float64", "y": "float64"}

if parser.engine == "pyarrow":
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/accessors/test_cat_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_getname_categorical_accessor(self, method):
def test_cat_accessor(self):
ser = Series(Categorical(["a", "b", np.nan, "a"]))
tm.assert_index_equal(ser.cat.categories, Index(["a", "b"]))
assert not ser.cat.ordered, False
assert not ser.cat.ordered

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

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def test_constructor_maskedarray_hardened(self):

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

result = Series(data, index=rng)
assert result.index.is_(rng)
Expand Down
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ select = [
"TID",
# implicit string concatenation
"ISC",
# type-checking imports
"TCH",
# flake8-type-checking
"TC",
# comprehensions
"C4",
# pygrep-hooks
Expand Down Expand Up @@ -390,6 +390,8 @@ ignore = [
"PLW0108",
# global-statement
"PLW0603",
# runtime-cast-value
"TC006",
]

exclude = [
Expand Down Expand Up @@ -429,7 +431,7 @@ exclude = [
"pandas/tests/*" = ["B028", "FLY"]
"scripts/*" = ["B028"]
# Keep this one enabled
"pandas/_typing.py" = ["TCH"]
"pandas/_typing.py" = ["TC"]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ asv>=0.6.1
flake8==7.1.0
mypy==1.13.0
tokenize-rt
pre-commit>=4.0.1
pre-commit>=4.2.0
gitpython
gitdb
google-auth
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def run(self) -> None:
# enable coverage by building cython files by setting the environment variable
# "PANDAS_CYTHON_COVERAGE" (with a Truthy value) or by running build_ext
# with `--with-cython-coverage`enabled
linetrace = os.environ.get("PANDAS_CYTHON_COVERAGE", False)
linetrace = os.environ.get("PANDAS_CYTHON_COVERAGE", False) # noqa: PLW1508
if "--with-cython-coverage" in sys.argv:
linetrace = True
sys.argv.remove("--with-cython-coverage")
Expand Down