Skip to content

Commit 320e72e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ca24f37 commit 320e72e

Some content is hidden

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

80 files changed

+246
-242
lines changed

asv_bench/benchmarks/frame_methods.py

Lines changed: 1 addition & 1 deletion
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):

pandas/_config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ def inner(key: str, *args, **kwds):
775775
pkey = f"{prefix}.{key}"
776776
return func(pkey, *args, **kwds)
777777

778-
return cast(F, inner)
778+
return cast("F", inner)
779779

780780
_register_option = register_option
781781
_get_option = get_option

pandas/_config/localization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ def get_locales(
156156
out_locales = []
157157
for x in split_raw_locales:
158158
try:
159-
out_locales.append(str(x, encoding=cast(str, options.display.encoding)))
159+
out_locales.append(
160+
str(x, encoding=cast("str", options.display.encoding))
161+
)
160162
except UnicodeError:
161163
# 'locale -a' is used to populated 'raw_locales' and on
162164
# Redhat 7 Linux (and maybe others) prints locale names

pandas/_testing/_warnings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class for all warnings. To raise multiple types of exceptions,
121121
)
122122
else:
123123
expected_warning = cast(
124-
Union[type[Warning], tuple[type[Warning], ...]],
124+
"Union[type[Warning], tuple[type[Warning], ...]]",
125125
expected_warning,
126126
)
127127
match = (
@@ -241,7 +241,7 @@ def _is_unexpected_warning(
241241
"""Check if the actual warning issued is unexpected."""
242242
if actual_warning and not expected_warning:
243243
return True
244-
expected_warning = cast(type[Warning], expected_warning)
244+
expected_warning = cast("type[Warning]", expected_warning)
245245
return bool(not issubclass(actual_warning.category, expected_warning))
246246

247247

pandas/_testing/asserters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def _check_types(left, right, obj: str = "Index") -> None:
283283

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

288288
for level in range(left.nlevels):
289289
lobj = f"{obj} level [{level}]"
@@ -776,11 +776,11 @@ def assert_extension_array_equal(
776776
# GH 52449
777777
if not check_dtype and left.dtype.kind in "mM":
778778
if not isinstance(left.dtype, np.dtype):
779-
l_unit = cast(DatetimeTZDtype, left.dtype).unit
779+
l_unit = cast("DatetimeTZDtype", left.dtype).unit
780780
else:
781781
l_unit = np.datetime_data(left.dtype)[0]
782782
if not isinstance(right.dtype, np.dtype):
783-
r_unit = cast(DatetimeTZDtype, right.dtype).unit
783+
r_unit = cast("DatetimeTZDtype", right.dtype).unit
784784
else:
785785
r_unit = np.datetime_data(right.dtype)[0]
786786
if (

pandas/compat/numpy/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def validate_argsort_with_ascending(ascending: bool | int | None, args, kwargs)
169169
ascending = True
170170

171171
validate_argsort_kind(args, kwargs, max_fname_arg_count=3)
172-
ascending = cast(bool, ascending)
172+
ascending = cast("bool", ascending)
173173
return ascending
174174

175175

pandas/core/algorithms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ def _ensure_data(values: ArrayLike) -> np.ndarray:
172172
return np.asarray(values)
173173

174174
elif is_complex_dtype(values.dtype):
175-
return cast(np.ndarray, values)
175+
return cast("np.ndarray", values)
176176

177177
# datetimelike
178178
elif needs_i8_conversion(values.dtype):
179179
npvalues = values.view("i8")
180-
npvalues = cast(np.ndarray, npvalues)
180+
npvalues = cast("np.ndarray", npvalues)
181181
return npvalues
182182

183183
# we have failed, return object
@@ -1289,9 +1289,9 @@ def searchsorted(
12891289

12901290
if is_integer(value):
12911291
# We know that value is int
1292-
value = cast(int, dtype.type(value))
1292+
value = cast("int", dtype.type(value))
12931293
else:
1294-
value = pd_array(cast(ArrayLike, value), dtype=dtype)
1294+
value = pd_array(cast("ArrayLike", value), dtype=dtype)
12951295
else:
12961296
# E.g. if `arr` is an array with dtype='datetime64[ns]'
12971297
# and `value` is a pd.Timestamp, we may need to convert value

pandas/core/apply.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,19 +322,19 @@ def transform(self) -> DataFrame | Series:
322322
return obj.T.transform(func, 0, *args, **kwargs).T
323323

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

336336
# func is either str or callable
337-
func = cast(AggFuncTypeBase, func)
337+
func = cast("AggFuncTypeBase", func)
338338
try:
339339
result = self.transform_str_or_callable(func)
340340
except TypeError:
@@ -434,7 +434,7 @@ def compute_list_like(
434434
Data for result. When aggregating with a Series, this can contain any
435435
Python objects.
436436
"""
437-
func = cast(list[AggFuncTypeBase], self.func)
437+
func = cast("list[AggFuncTypeBase]", self.func)
438438
obj = self.obj
439439

440440
results = []
@@ -541,7 +541,7 @@ def compute_dict_like(
541541

542542
obj = self.obj
543543
is_groupby = isinstance(obj, (DataFrameGroupBy, SeriesGroupBy))
544-
func = cast(AggFuncTypeDict, self.func)
544+
func = cast("AggFuncTypeDict", self.func)
545545
func = self.normalize_dictlike_arg(op_name, selected_obj, func)
546546

547547
is_non_unique_col = (
@@ -666,7 +666,7 @@ def apply_str(self) -> DataFrame | Series:
666666
result: Series or DataFrame
667667
"""
668668
# Caller is responsible for checking isinstance(self.f, str)
669-
func = cast(str, self.func)
669+
func = cast("str", self.func)
670670

671671
obj = self.obj
672672

@@ -1262,7 +1262,7 @@ def numba_func(values, col_names, df_index, *args):
12621262
return numba_func
12631263

12641264
def apply_with_numba(self) -> dict[int, Any]:
1265-
func = cast(Callable, self.func)
1265+
func = cast("Callable", self.func)
12661266
args, kwargs = prepare_function_arguments(
12671267
func, self.args, self.kwargs, num_required_args=1
12681268
)
@@ -1404,7 +1404,7 @@ def numba_func(values, col_names_index, index, *args):
14041404
return numba_func
14051405

14061406
def apply_with_numba(self) -> dict[int, Any]:
1407-
func = cast(Callable, self.func)
1407+
func = cast("Callable", self.func)
14081408
args, kwargs = prepare_function_arguments(
14091409
func, self.args, self.kwargs, num_required_args=1
14101410
)
@@ -1551,7 +1551,7 @@ def apply_compat(self):
15511551

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

15571557
if isinstance(func, np.ufunc):

pandas/core/arrays/_mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def method(self, *args, **kwargs):
8585
order = "F" if flags.f_contiguous else "C"
8686
return result.reshape(self.shape, order=order)
8787

88-
return cast(F, method)
88+
return cast("F", method)
8989

9090

9191
# error: Definition of "delete/ravel/T/repeat/copy" in base class "NDArrayBacked"

pandas/core/arrays/arrow/accessors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ def get_name(
445445
while level_name_or_index:
446446
# we need the cast, otherwise mypy complains about
447447
# getting ints, bytes, or str here, which isn't possible.
448-
level_name_or_index = cast(list, level_name_or_index)
448+
level_name_or_index = cast("list", level_name_or_index)
449449
name_or_index = level_name_or_index.pop()
450450
name = get_name(name_or_index, selected)
451451
selected = selected.type.field(selected.type.get_field_index(name))

0 commit comments

Comments
 (0)