Skip to content

CLN: Change old string formatting syntax into f-strings #34094

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

Merged
merged 1 commit into from
May 9, 2020
Merged
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: 2 additions & 4 deletions pandas/core/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,8 @@ def ensure_key_mapped(values, key: Optional[Callable], levels=None):
result = type_of_values(result) # try to revert to original type otherwise
except TypeError:
raise TypeError(
"User-provided `key` function returned an invalid type {} \
which could not be converted to {}.".format(
type(result), type(values)
)
f"User-provided `key` function returned an invalid type {type(result)} \
which could not be converted to {type(values)}."
)

return result
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/datetimes/test_date_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,8 @@ def test_all_custom_freq(self, freq):
)

bad_freq = freq + "FOO"
msg = "invalid custom frequency string: {freq}"
with pytest.raises(ValueError, match=msg.format(freq=bad_freq)):
msg = f"invalid custom frequency string: {bad_freq}"
with pytest.raises(ValueError, match=msg):
bdate_range(START, END, freq=bad_freq)

@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ def test_maybe_convert_i8_errors(self, breaks1, breaks2, make_key):
key = make_key(breaks2)

msg = (
"Cannot index an IntervalIndex of subtype {dtype1} with "
"values of dtype {dtype2}"
f"Cannot index an IntervalIndex of subtype {breaks1.dtype} with "
f"values of dtype {breaks2.dtype}"
)
msg = re.escape(msg.format(dtype1=breaks1.dtype, dtype2=breaks2.dtype))
msg = re.escape(msg)
with pytest.raises(ValueError, match=msg):
index._maybe_convert_i8(key)

Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexing/test_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def has_test(combo):

for combo in combos:
if not has_test(combo):
msg = "test method is not defined: {0}, {1}"
raise AssertionError(msg.format(cls.__name__, combo))
raise AssertionError(f"test method is not defined: {cls.__name__}, {combo}")

yield

Expand Down
11 changes: 6 additions & 5 deletions pandas/tests/reshape/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,12 +1869,13 @@ def test_concat_invalid(self):

# trying to concat a ndframe with a non-ndframe
df1 = tm.makeCustomDataframe(10, 2)
msg = (
"cannot concatenate object of type '{}'; "
"only Series and DataFrame objs are valid"
)
for obj in [1, dict(), [1, 2], (1, 2)]:
with pytest.raises(TypeError, match=msg.format(type(obj))):

msg = (
f"cannot concatenate object of type '{type(obj)}'; "
"only Series and DataFrame objs are valid"
)
with pytest.raises(TypeError, match=msg):
concat([df1, obj])

def test_concat_invalid_first_argument(self):
Expand Down
6 changes: 3 additions & 3 deletions pandas/util/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ def wrapper(*args, **kwargs):
num_allow_args = allow_args
if len(args) > num_allow_args:
msg = (
"Starting with Pandas version {version} all arguments of {funcname}"
"{except_args} will be keyword-only"
).format(version=version, funcname=func.__name__, except_args=arguments)
f"Starting with Pandas version {version} all arguments of "
f"{func.__name__}{arguments} will be keyword-only"
)
warnings.warn(msg, FutureWarning, stacklevel=stacklevel)
return func(*args, **kwargs)

Expand Down