Skip to content

Commit a3af78f

Browse files
ShaharNavehproost
authored andcommitted
STY: "{foo!r}" -> "{repr(foo)}" #batch-5 (pandas-dev#29963)
1 parent 6952d62 commit a3af78f

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

pandas/tests/frame/test_analytics.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -2589,11 +2589,6 @@ def df_main_dtypes():
25892589

25902590
class TestNLargestNSmallest:
25912591

2592-
dtype_error_msg_template = (
2593-
"Column {column!r} has dtype {dtype}, cannot "
2594-
"use method {method!r} with this dtype"
2595-
)
2596-
25972592
# ----------------------------------------------------------------------
25982593
# Top / bottom
25992594
@pytest.mark.parametrize(
@@ -2620,8 +2615,9 @@ def test_n(self, df_strings, nselect_method, n, order):
26202615
df = df_strings
26212616
if "b" in order:
26222617

2623-
error_msg = self.dtype_error_msg_template.format(
2624-
column="b", method=nselect_method, dtype="object"
2618+
error_msg = (
2619+
f"Column 'b' has dtype object, "
2620+
f"cannot use method '{nselect_method}' with this dtype"
26252621
)
26262622
with pytest.raises(TypeError, match=error_msg):
26272623
getattr(df, nselect_method)(n, order)
@@ -2637,8 +2633,9 @@ def test_n(self, df_strings, nselect_method, n, order):
26372633
def test_n_error(self, df_main_dtypes, nselect_method, columns):
26382634
df = df_main_dtypes
26392635
col = columns[1]
2640-
error_msg = self.dtype_error_msg_template.format(
2641-
column=col, method=nselect_method, dtype=df[col].dtype
2636+
error_msg = (
2637+
f"Column '{col}' has dtype {df[col].dtype}, "
2638+
f"cannot use method '{nselect_method}' with this dtype"
26422639
)
26432640
# escape some characters that may be in the repr
26442641
error_msg = (

pandas/tests/groupby/test_whitelist.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,23 @@ def test_groupby_blacklist(df_letters):
236236

237237
blacklist.extend(to_methods)
238238

239-
# e.g., to_csv
240-
defined_but_not_allowed = "(?:^Cannot.+{0!r}.+{1!r}.+try using the 'apply' method$)"
241-
242-
# e.g., query, eval
243-
not_defined = "(?:^{1!r} object has no attribute {0!r}$)"
244-
fmt = defined_but_not_allowed + "|" + not_defined
245239
for bl in blacklist:
246240
for obj in (df, s):
247241
gb = obj.groupby(df.letters)
248-
msg = fmt.format(bl, type(gb).__name__)
242+
243+
# e.g., to_csv
244+
defined_but_not_allowed = (
245+
f"(?:^Cannot.+{repr(bl)}.+'{type(gb).__name__}'.+try "
246+
f"using the 'apply' method$)"
247+
)
248+
249+
# e.g., query, eval
250+
not_defined = (
251+
f"(?:^'{type(gb).__name__}' object has no attribute {repr(bl)}$)"
252+
)
253+
254+
msg = f"{defined_but_not_allowed}|{not_defined}"
255+
249256
with pytest.raises(AttributeError, match=msg):
250257
getattr(gb, bl)
251258

pandas/tests/indexes/datetimes/test_datetime.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_week_of_month_frequency(self):
8989
def test_hash_error(self):
9090
index = date_range("20010101", periods=10)
9191
with pytest.raises(
92-
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
92+
TypeError, match=f"unhashable type: '{type(index).__name__}'"
9393
):
9494
hash(index)
9595

pandas/tests/indexes/multi/test_integrity.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,7 @@ def test_rangeindex_fallback_coercion_bug():
252252

253253
def test_hash_error(indices):
254254
index = indices
255-
with pytest.raises(
256-
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
257-
):
255+
with pytest.raises(TypeError, match=f"unhashable type: '{type(index).__name__}'"):
258256
hash(indices)
259257

260258

pandas/tests/indexes/test_common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def test_set_name_methods(self, indices):
161161
def test_hash_error(self, indices):
162162
index = indices
163163
with pytest.raises(
164-
TypeError, match=(f"unhashable type: {type(index).__name__!r}")
164+
TypeError, match=f"unhashable type: '{type(index).__name__}'"
165165
):
166166
hash(indices)
167167

pandas/tests/io/msgpack/test_case.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ def check(length, obj):
77
v = packb(obj)
88
assert (
99
len(v) == length
10-
), "{obj!r} length should be {length!r} but get {got:!r}".format(
11-
obj=obj, length=length, got=len(v)
12-
)
10+
), f"{repr(obj)} length should be {length} but got {repr(len(v))}"
1311
assert unpackb(v, use_list=0) == obj
1412

1513

pandas/tests/io/msgpack/test_extension.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def default(obj):
4848
typecode = 123 # application specific typecode
4949
data = tobytes(obj)
5050
return ExtType(typecode, data)
51-
raise TypeError("Unknown type object {obj!r}".format(obj=obj))
51+
raise TypeError(f"Unknown type object {repr(obj)}")
5252

5353
def ext_hook(code, data):
5454
print("ext_hook called", code, data)

0 commit comments

Comments
 (0)