Skip to content

Commit 667418e

Browse files
tqa236pmhatre1
authored andcommitted
Autofix ruf010 (pandas-dev#56914)
* STY: Autofix RUF010 * STY: Apply ruff format after autofix * STY: Final manual fix * STY: Remove old repl rule in pre-commit
1 parent 019c337 commit 667418e

Some content is hidden

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

52 files changed

+114
-128
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ repos:
190190
# Check for deprecated messages without sphinx directive
191191
|(DEPRECATED|DEPRECATE|Deprecated)(:|,|\.)
192192
193-
# {foo!r} instead of {repr(foo)}
194-
|!r}
195-
196193
# builtin filter function
197194
|(?<!def)[\(\s]filter\(
198195
types_or: [python, cython, rst]

doc/scripts/eval_performance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def bench_with(n, times=10, repeat=3, engine="numexpr"):
1717
return (
1818
np.array(
1919
timeit(
20-
f"df.eval(s, engine={repr(engine)})",
20+
f"df.eval(s, engine={engine!r})",
2121
setup=setup_common % (n, setup_with),
2222
repeat=repeat,
2323
number=times,
@@ -34,7 +34,7 @@ def bench_subset(n, times=20, repeat=3, engine="numexpr"):
3434
return (
3535
np.array(
3636
timeit(
37-
f"df.query(s, engine={repr(engine)})",
37+
f"df.query(s, engine={engine!r})",
3838
setup=setup_common % (n, setup_subset),
3939
repeat=repeat,
4040
number=times,
@@ -55,7 +55,7 @@ def bench(mn=3, mx=7, num=100, engines=("python", "numexpr"), verbose=False):
5555
for engine in engines:
5656
for i, n in enumerate(r):
5757
if verbose & (i % 10 == 0):
58-
print(f"engine: {repr(engine)}, i == {i:d}")
58+
print(f"engine: {engine!r}, i == {i:d}")
5959
ev_times = bench_with(n, times=1, repeat=1, engine=engine)
6060
ev.loc[i, engine] = np.mean(ev_times)
6161
qu_times = bench_subset(n, times=1, repeat=1, engine=engine)

pandas/_config/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _get_single_key(pat: str, silent: bool) -> str:
130130
if len(keys) == 0:
131131
if not silent:
132132
_warn_if_deprecated(pat)
133-
raise OptionError(f"No such keys(s): {repr(pat)}")
133+
raise OptionError(f"No such keys(s): {pat!r}")
134134
if len(keys) > 1:
135135
raise OptionError("Pattern matched multiple keys")
136136
key = keys[0]

pandas/_testing/_warnings.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,12 @@ def _assert_caught_expected_warning(
152152

153153
if not saw_warning:
154154
raise AssertionError(
155-
f"Did not see expected warning of class "
156-
f"{repr(expected_warning.__name__)}"
155+
f"Did not see expected warning of class {expected_warning.__name__!r}"
157156
)
158157

159158
if match and not matched_message:
160159
raise AssertionError(
161-
f"Did not see warning {repr(expected_warning.__name__)} "
160+
f"Did not see warning {expected_warning.__name__!r} "
162161
f"matching '{match}'. The emitted warning messages are "
163162
f"{unmatched_messages}"
164163
)
@@ -200,7 +199,7 @@ def _assert_caught_no_extra_warnings(
200199
)
201200

202201
if extra_warnings:
203-
raise AssertionError(f"Caused unexpected warning(s): {repr(extra_warnings)}")
202+
raise AssertionError(f"Caused unexpected warning(s): {extra_warnings!r}")
204203

205204

206205
def _is_unexpected_warning(

pandas/_testing/asserters.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,14 @@ def assert_is_valid_plot_return_object(objs) -> None:
432432
for el in objs.ravel():
433433
msg = (
434434
"one of 'objs' is not a matplotlib Axes instance, "
435-
f"type encountered {repr(type(el).__name__)}"
435+
f"type encountered {type(el).__name__!r}"
436436
)
437437
assert isinstance(el, (Axes, dict)), msg
438438
else:
439439
msg = (
440440
"objs is neither an ndarray of Artist instances nor a single "
441441
"ArtistArtist instance, tuple, or dict, 'objs' is a "
442-
f"{repr(type(objs).__name__)}"
442+
f"{type(objs).__name__!r}"
443443
)
444444
assert isinstance(objs, (Artist, tuple, dict)), msg
445445

@@ -661,10 +661,10 @@ def _get_base(obj):
661661

662662
if check_same == "same":
663663
if left_base is not right_base:
664-
raise AssertionError(f"{repr(left_base)} is not {repr(right_base)}")
664+
raise AssertionError(f"{left_base!r} is not {right_base!r}")
665665
elif check_same == "copy":
666666
if left_base is right_base:
667-
raise AssertionError(f"{repr(left_base)} is {repr(right_base)}")
667+
raise AssertionError(f"{left_base!r} is {right_base!r}")
668668

669669
def _raise(left, right, err_msg) -> NoReturn:
670670
if err_msg is None:
@@ -935,7 +935,7 @@ def assert_series_equal(
935935
raise_assert_detail(obj, "Series length are different", msg1, msg2)
936936

937937
if check_flags:
938-
assert left.flags == right.flags, f"{repr(left.flags)} != {repr(right.flags)}"
938+
assert left.flags == right.flags, f"{left.flags!r} != {right.flags!r}"
939939

940940
if check_index:
941941
# GH #38183
@@ -1215,11 +1215,11 @@ def assert_frame_equal(
12151215
# shape comparison
12161216
if left.shape != right.shape:
12171217
raise_assert_detail(
1218-
obj, f"{obj} shape mismatch", f"{repr(left.shape)}", f"{repr(right.shape)}"
1218+
obj, f"{obj} shape mismatch", f"{left.shape!r}", f"{right.shape!r}"
12191219
)
12201220

12211221
if check_flags:
1222-
assert left.flags == right.flags, f"{repr(left.flags)} != {repr(right.flags)}"
1222+
assert left.flags == right.flags, f"{left.flags!r} != {right.flags!r}"
12231223

12241224
# index comparison
12251225
assert_index_equal(
@@ -1369,7 +1369,7 @@ def assert_sp_array_equal(left, right) -> None:
13691369

13701370
def assert_contains_all(iterable, dic) -> None:
13711371
for k in iterable:
1372-
assert k in dic, f"Did not contain item: {repr(k)}"
1372+
assert k in dic, f"Did not contain item: {k!r}"
13731373

13741374

13751375
def assert_copy(iter1, iter2, **eql_kwargs) -> None:
@@ -1384,7 +1384,7 @@ def assert_copy(iter1, iter2, **eql_kwargs) -> None:
13841384
for elem1, elem2 in zip(iter1, iter2):
13851385
assert_almost_equal(elem1, elem2, **eql_kwargs)
13861386
msg = (
1387-
f"Expected object {repr(type(elem1))} and object {repr(type(elem2))} to be "
1387+
f"Expected object {type(elem1)!r} and object {type(elem2)!r} to be "
13881388
"different objects, but they were the same object."
13891389
)
13901390
assert elem1 is not elem2, msg

pandas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):
141141

142142
if verbose:
143143
print(
144-
f"Tried directories {str(rootdirs)} \
144+
f"Tried directories {rootdirs!s} \
145145
but none started with prefix {parentdir_prefix}"
146146
)
147147
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")

pandas/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def configure_tests() -> None:
273273
# ----------------------------------------------------------------
274274
# Common arguments
275275
# ----------------------------------------------------------------
276-
@pytest.fixture(params=[0, 1, "index", "columns"], ids=lambda x: f"axis={repr(x)}")
276+
@pytest.fixture(params=[0, 1, "index", "columns"], ids=lambda x: f"axis={x!r}")
277277
def axis(request):
278278
"""
279279
Fixture for returning the axis numbers of a DataFrame.

pandas/core/accessor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ def plot(self):
306306
def decorator(accessor):
307307
if hasattr(cls, name):
308308
warnings.warn(
309-
f"registration of accessor {repr(accessor)} under name "
310-
f"{repr(name)} for type {repr(cls)} is overriding a preexisting "
309+
f"registration of accessor {accessor!r} under name "
310+
f"{name!r} for type {cls!r} is overriding a preexisting "
311311
f"attribute with the same name.",
312312
UserWarning,
313313
stacklevel=find_stack_level(),

pandas/core/array_algos/replace.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _check_comparison_types(
7878
type_names[0] = f"ndarray(dtype={a.dtype})"
7979

8080
raise TypeError(
81-
f"Cannot compare types {repr(type_names[0])} and {repr(type_names[1])}"
81+
f"Cannot compare types {type_names[0]!r} and {type_names[1]!r}"
8282
)
8383

8484
if not regex or not should_use_regex(regex, b):

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ def fillna(
11091109
try:
11101110
fill_value = self._box_pa(value, pa_type=self._pa_array.type)
11111111
except pa.ArrowTypeError as err:
1112-
msg = f"Invalid value '{str(value)}' for dtype {self.dtype}"
1112+
msg = f"Invalid value '{value!s}' for dtype {self.dtype}"
11131113
raise TypeError(msg) from err
11141114

11151115
try:
@@ -2065,7 +2065,7 @@ def _maybe_convert_setitem_value(self, value):
20652065
try:
20662066
value = self._box_pa(value, self._pa_array.type)
20672067
except pa.ArrowTypeError as err:
2068-
msg = f"Invalid value '{str(value)}' for dtype {self.dtype}"
2068+
msg = f"Invalid value '{value!s}' for dtype {self.dtype}"
20692069
raise TypeError(msg) from err
20702070
return value
20712071

0 commit comments

Comments
 (0)