Skip to content

[pre-commit.ci] pre-commit autoupdate #61243

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

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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]
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 pandas/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ def inner(key: str, *args, **kwds):
pkey = f"{prefix}.{key}"
return func(pkey, *args, **kwds)

return cast(F, inner)
return cast("F", inner)

_register_option = register_option
_get_option = get_option
Expand Down
4 changes: 3 additions & 1 deletion pandas/_config/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def get_locales(
out_locales = []
for x in split_raw_locales:
try:
out_locales.append(str(x, encoding=cast(str, options.display.encoding)))
out_locales.append(
str(x, encoding=cast("str", options.display.encoding))
)
except UnicodeError:
# 'locale -a' is used to populated 'raw_locales' and on
# Redhat 7 Linux (and maybe others) prints locale names
Expand Down
4 changes: 2 additions & 2 deletions pandas/_testing/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class for all warnings. To raise multiple types of exceptions,
)
else:
expected_warning = cast(
Union[type[Warning], tuple[type[Warning], ...]],
"Union[type[Warning], tuple[type[Warning], ...]]",
expected_warning,
)
match = (
Expand Down Expand Up @@ -241,7 +241,7 @@ def _is_unexpected_warning(
"""Check if the actual warning issued is unexpected."""
if actual_warning and not expected_warning:
return True
expected_warning = cast(type[Warning], expected_warning)
expected_warning = cast("type[Warning]", expected_warning)
return bool(not issubclass(actual_warning.category, expected_warning))


Expand Down
6 changes: 3 additions & 3 deletions pandas/_testing/asserters.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def _check_types(left, right, obj: str = "Index") -> None:

# MultiIndex special comparison for little-friendly error messages
if isinstance(left, MultiIndex):
right = cast(MultiIndex, right)
right = cast("MultiIndex", right)

for level in range(left.nlevels):
lobj = f"{obj} level [{level}]"
Expand Down Expand Up @@ -776,11 +776,11 @@ def assert_extension_array_equal(
# GH 52449
if not check_dtype and left.dtype.kind in "mM":
if not isinstance(left.dtype, np.dtype):
l_unit = cast(DatetimeTZDtype, left.dtype).unit
l_unit = cast("DatetimeTZDtype", left.dtype).unit
else:
l_unit = np.datetime_data(left.dtype)[0]
if not isinstance(right.dtype, np.dtype):
r_unit = cast(DatetimeTZDtype, right.dtype).unit
r_unit = cast("DatetimeTZDtype", right.dtype).unit
else:
r_unit = np.datetime_data(right.dtype)[0]
if (
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def validate_argsort_with_ascending(ascending: bool | int | None, args, kwargs)
ascending = True

validate_argsort_kind(args, kwargs, max_fname_arg_count=3)
ascending = cast(bool, ascending)
ascending = cast("bool", ascending)
return ascending


Expand Down
8 changes: 4 additions & 4 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ def _ensure_data(values: ArrayLike) -> np.ndarray:
return np.asarray(values)

elif is_complex_dtype(values.dtype):
return cast(np.ndarray, values)
return cast("np.ndarray", values)

# datetimelike
elif needs_i8_conversion(values.dtype):
npvalues = values.view("i8")
npvalues = cast(np.ndarray, npvalues)
npvalues = cast("np.ndarray", npvalues)
return npvalues

# we have failed, return object
Expand Down Expand Up @@ -1289,9 +1289,9 @@ def searchsorted(

if is_integer(value):
# We know that value is int
value = cast(int, dtype.type(value))
value = cast("int", dtype.type(value))
else:
value = pd_array(cast(ArrayLike, value), dtype=dtype)
value = pd_array(cast("ArrayLike", value), dtype=dtype)
else:
# E.g. if `arr` is an array with dtype='datetime64[ns]'
# and `value` is a pd.Timestamp, we may need to convert value
Expand Down
20 changes: 10 additions & 10 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,19 @@ def transform(self) -> DataFrame | Series:
return obj.T.transform(func, 0, *args, **kwargs).T

if is_list_like(func) and not is_dict_like(func):
func = cast(list[AggFuncTypeBase], func)
func = cast("list[AggFuncTypeBase]", func)
# Convert func equivalent dict
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)
func = cast("AggFuncTypeDict", func)
return self.transform_dict_like(func)

# func is either str or callable
func = cast(AggFuncTypeBase, func)
func = cast("AggFuncTypeBase", func)
try:
result = self.transform_str_or_callable(func)
except TypeError:
Expand Down Expand Up @@ -434,7 +434,7 @@ def compute_list_like(
Data for result. When aggregating with a Series, this can contain any
Python objects.
"""
func = cast(list[AggFuncTypeBase], self.func)
func = cast("list[AggFuncTypeBase]", self.func)
obj = self.obj

results = []
Expand Down Expand Up @@ -541,7 +541,7 @@ def compute_dict_like(

obj = self.obj
is_groupby = isinstance(obj, (DataFrameGroupBy, SeriesGroupBy))
func = cast(AggFuncTypeDict, self.func)
func = cast("AggFuncTypeDict", self.func)
func = self.normalize_dictlike_arg(op_name, selected_obj, func)

is_non_unique_col = (
Expand Down Expand Up @@ -666,7 +666,7 @@ def apply_str(self) -> DataFrame | Series:
result: Series or DataFrame
"""
# Caller is responsible for checking isinstance(self.f, str)
func = cast(str, self.func)
func = cast("str", self.func)

obj = self.obj

Expand Down Expand Up @@ -1262,7 +1262,7 @@ def numba_func(values, col_names, df_index, *args):
return numba_func

def apply_with_numba(self) -> dict[int, Any]:
func = cast(Callable, self.func)
func = cast("Callable", self.func)
args, kwargs = prepare_function_arguments(
func, self.args, self.kwargs, num_required_args=1
)
Expand Down Expand Up @@ -1404,7 +1404,7 @@ def numba_func(values, col_names_index, index, *args):
return numba_func

def apply_with_numba(self) -> dict[int, Any]:
func = cast(Callable, self.func)
func = cast("Callable", self.func)
args, kwargs = prepare_function_arguments(
func, self.args, self.kwargs, num_required_args=1
)
Expand Down Expand Up @@ -1551,7 +1551,7 @@ def apply_compat(self):

def apply_standard(self) -> DataFrame | Series:
# caller is responsible for ensuring that f is Callable
func = cast(Callable, self.func)
func = cast("Callable", self.func)
obj = self.obj

if isinstance(func, np.ufunc):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def method(self, *args, **kwargs):
order = "F" if flags.f_contiguous else "C"
return result.reshape(self.shape, order=order)

return cast(F, method)
return cast("F", method)


# error: Definition of "delete/ravel/T/repeat/copy" in base class "NDArrayBacked"
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/arrow/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def get_name(
while level_name_or_index:
# we need the cast, otherwise mypy complains about
# getting ints, bytes, or str here, which isn't possible.
level_name_or_index = cast(list, level_name_or_index)
level_name_or_index = cast("list", level_name_or_index)
name_or_index = level_name_or_index.pop()
name = get_name(name_or_index, selected)
selected = selected.type.field(selected.type.get_field_index(name))
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ def factorize(
uniques = type(self)(combined.dictionary)

if pa_version_under11p0 and pa.types.is_duration(pa_type):
uniques = cast(ArrowExtensionArray, uniques.astype(self.dtype))
uniques = cast("ArrowExtensionArray", uniques.astype(self.dtype))
return indices, uniques

def reshape(self, *args, **kwargs):
Expand Down Expand Up @@ -1991,7 +1991,7 @@ def __setitem__(self, key, value) -> None:

elif is_integer(key):
# fast path
key = cast(int, key)
key = cast("int", key)
n = len(self)
if key < 0:
key += n
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ def equals(self, other: object) -> bool:
"""
if type(self) != type(other):
return False
other = cast(ExtensionArray, other)
other = cast("ExtensionArray", other)
if self.dtype != other.dtype:
return False
elif len(self) != len(other):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ def _mode(self, dropna: bool = True) -> Categorical:
mask = self.isna()

res_codes, _ = algorithms.mode(codes, mask=mask)
res_codes = cast(np.ndarray, res_codes)
res_codes = cast("np.ndarray", res_codes)
assert res_codes.dtype == codes.dtype
res = self._from_backing_data(res_codes)
return res
Expand Down
10 changes: 5 additions & 5 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def new_meth(self, *args, **kwargs):
res_i8 = result.view("i8")
return self._from_backing_data(res_i8)

return cast(F, new_meth)
return cast("F", new_meth)


# error: Definition of "_concat_same_type" in base class "NDArrayBacked" is
Expand Down Expand Up @@ -391,7 +391,7 @@ def __getitem__(self, key: PositionalIndexer2D) -> Self | DTScalarOrNaT:
return result
else:
# At this point we know the result is an array.
result = cast(Self, result)
result = cast("Self", result)
result._freq = self._get_getitem_freq(key)
return result

Expand Down Expand Up @@ -990,7 +990,7 @@ def _cmp_method(self, other, op):
return result

if not isinstance(self.dtype, PeriodDtype):
self = cast(TimelikeOps, self)
self = cast("TimelikeOps", self)
if self._creso != other._creso:
if not isinstance(other, type(self)):
# i.e. Timedelta/Timestamp, cast to ndarray and let
Expand Down Expand Up @@ -1637,7 +1637,7 @@ def _mode(self, dropna: bool = True):

i8modes, _ = algorithms.mode(self.view("i8"), mask=mask)
npmodes = i8modes.view(self._ndarray.dtype)
npmodes = cast(np.ndarray, npmodes)
npmodes = cast("np.ndarray", npmodes)
return self._from_backing_data(npmodes)

# ------------------------------------------------------------------
Expand Down Expand Up @@ -2198,7 +2198,7 @@ def _round(self, freq, mode, ambiguous, nonexistent):
)

values = self.view("i8")
values = cast(np.ndarray, values)
values = cast("np.ndarray", values)
nanos = get_unit_for_round(freq, self._creso)
if nanos == 0:
# GH 52761
Expand Down
16 changes: 8 additions & 8 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def _generate_range(
# Nanosecond-granularity timestamps aren't always correctly
# representable with doubles, so we limit the range that we
# pass to np.linspace as much as possible
periods = cast(int, periods)
periods = cast("int", periods)
i8values = (
np.linspace(0, end._value - start._value, periods, dtype="int64")
+ start._value
Expand Down Expand Up @@ -2430,7 +2430,7 @@ def _sequence_to_dt64(
if data_dtype == object or is_string_dtype(data_dtype):
# TODO: We do not have tests specific to string-dtypes,
# also complex or categorical or other extension
data = cast(np.ndarray, data)
data = cast("np.ndarray", data)
copy = False
if lib.infer_dtype(data, skipna=False) == "integer":
# Much more performant than going through array_to_datetime
Expand Down Expand Up @@ -2475,7 +2475,7 @@ def _sequence_to_dt64(
# so we need to handle these types.
if isinstance(data_dtype, DatetimeTZDtype):
# DatetimeArray -> ndarray
data = cast(DatetimeArray, data)
data = cast("DatetimeArray", data)
tz = _maybe_infer_tz(tz, data.tz)
result = data._ndarray

Expand All @@ -2484,7 +2484,7 @@ def _sequence_to_dt64(
if isinstance(data, DatetimeArray):
data = data._ndarray

data = cast(np.ndarray, data)
data = cast("np.ndarray", data)
result, copy = _construct_from_dt64_naive(
data, tz=tz, copy=copy, ambiguous=ambiguous
)
Expand All @@ -2495,7 +2495,7 @@ def _sequence_to_dt64(
if data.dtype != INT64_DTYPE:
data = data.astype(np.int64, copy=False)
copy = False
data = cast(np.ndarray, data)
data = cast("np.ndarray", data)
result = data.view(out_dtype)

if copy:
Expand Down Expand Up @@ -2760,7 +2760,7 @@ def _validate_dt64_dtype(dtype):
# Without this, things like adding an array of timedeltas and
# a tz-aware Timestamp (with a tz specific to its datetime) will
# be incorrect(ish?) for the array as a whole
dtype = cast(DatetimeTZDtype, dtype)
dtype = cast("DatetimeTZDtype", dtype)
dtype = DatetimeTZDtype(
unit=dtype.unit, tz=timezones.tz_standardize(dtype.tz)
)
Expand Down Expand Up @@ -2985,8 +2985,8 @@ def _generate_range(
# argument type "None"
start = end - (periods - 1) * offset # type: ignore[operator]

start = cast(Timestamp, start)
end = cast(Timestamp, end)
start = cast("Timestamp", start)
end = cast("Timestamp", end)

cur = start
if offset.n >= 0:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _from_sequence(cls, scalars, *, dtype=None, copy: bool = False) -> Self:
@classmethod
@doc(ExtensionArray._empty)
def _empty(cls, shape: Shape, dtype: ExtensionDtype) -> Self:
dtype = cast(BaseMaskedDtype, dtype)
dtype = cast("BaseMaskedDtype", dtype)
values: np.ndarray = np.empty(shape, dtype=dtype.type)
values.fill(dtype._internal_fill_value)
mask = np.ones(shape, dtype=bool)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def __init__(self, values, dtype: Dtype | None = None, copy: bool = False) -> No
values = np.array(values, dtype="int64", copy=copy)
if dtype is None:
raise ValueError("dtype is not specified and cannot be inferred")
dtype = cast(PeriodDtype, dtype)
dtype = cast("PeriodDtype", dtype)
NDArrayBacked.__init__(self, values, dtype)

# error: Signature of "_simple_new" incompatible with supertype "NDArrayBacked"
Expand Down
Loading
Loading