Skip to content

Commit

Permalink
STY: "{foo!r}" -> "{repr(foo)}"
Browse files Browse the repository at this point in the history
  • Loading branch information
MomIsBestFriend committed Dec 2, 2019
1 parent 7e791e4 commit 8047860
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
15 changes: 6 additions & 9 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2589,11 +2589,6 @@ def df_main_dtypes():

class TestNLargestNSmallest:

dtype_error_msg_template = (
"Column {column!r} has dtype {dtype}, cannot "
"use method {method!r} with this dtype"
)

# ----------------------------------------------------------------------
# Top / bottom
@pytest.mark.parametrize(
Expand All @@ -2620,8 +2615,9 @@ def test_n(self, df_strings, nselect_method, n, order):
df = df_strings
if "b" in order:

error_msg = self.dtype_error_msg_template.format(
column="b", method=nselect_method, dtype="object"
error_msg = (
f"Column 'b' has dtype object, "
f"cannot use method {repr(nselect_method)} with this dtype"
)
with pytest.raises(TypeError, match=error_msg):
getattr(df, nselect_method)(n, order)
Expand All @@ -2637,8 +2633,9 @@ def test_n(self, df_strings, nselect_method, n, order):
def test_n_error(self, df_main_dtypes, nselect_method, columns):
df = df_main_dtypes
col = columns[1]
error_msg = self.dtype_error_msg_template.format(
column=col, method=nselect_method, dtype=df[col].dtype
error_msg = (
f"Column {repr(col)} has dtype {df[col].dtype}, "
f"cannot use method {repr(nselect_method)} with this dtype"
)
# escape some characters that may be in the repr
error_msg = (
Expand Down
21 changes: 14 additions & 7 deletions pandas/tests/groupby/test_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,23 @@ def test_groupby_blacklist(df_letters):

blacklist.extend(to_methods)

# e.g., to_csv
defined_but_not_allowed = "(?:^Cannot.+{0!r}.+{1!r}.+try using the 'apply' method$)"

# e.g., query, eval
not_defined = "(?:^{1!r} object has no attribute {0!r}$)"
fmt = defined_but_not_allowed + "|" + not_defined
for bl in blacklist:
for obj in (df, s):
gb = obj.groupby(df.letters)
msg = fmt.format(bl, type(gb).__name__)

# e.g., to_csv
defined_but_not_allowed = (
f"(?:^Cannot.+{repr(bl)}.+{repr(type(gb).__name__)}.+try "
f"using the 'apply' method$)"
)

# e.g., query, eval
not_defined = (
f"(?:^{repr(type(gb).__name__)} object has no attribute {repr(bl)}$)"
)

msg = f"{defined_but_not_allowed}|{not_defined}"

with pytest.raises(AttributeError, match=msg):
getattr(gb, bl)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_week_of_month_frequency(self):
def test_hash_error(self):
index = date_range("20010101", periods=10)
with pytest.raises(
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
TypeError, match=(f"unhashable type: {repr(type(index).__name__)}")
):
hash(index)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/multi/test_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_rangeindex_fallback_coercion_bug():
def test_hash_error(indices):
index = indices
with pytest.raises(
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
TypeError, match=(f"unhashable type: {repr(type(index).__name__)}")
):
hash(indices)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_set_name_methods(self, indices):
def test_hash_error(self, indices):
index = indices
with pytest.raises(
TypeError, match=(f"unhashable type: {type(index).__name__!r}")
TypeError, match=(f"unhashable type: {repr(type(index).__name__)}")
):
hash(indices)

Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/io/msgpack/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def check(length, obj):
v = packb(obj)
assert (
len(v) == length
), "{obj!r} length should be {length!r} but get {got:!r}".format(
obj=obj, length=length, got=len(v)
)
), f"{repr(obj)} length should be {repr(length)} but got {repr(len(v))}"
assert unpackb(v, use_list=0) == obj


Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/msgpack/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def default(obj):
typecode = 123 # application specific typecode
data = tobytes(obj)
return ExtType(typecode, data)
raise TypeError("Unknown type object {obj!r}".format(obj=obj))
raise TypeError(f"Unknown type object {repr(obj)}")

def ext_hook(code, data):
print("ext_hook called", code, data)
Expand Down

0 comments on commit 8047860

Please sign in to comment.