Skip to content

Commit dd790e8

Browse files
ShaharNavehMateusz Górski
authored and
Mateusz Górski
committed
F-strings (pandas-dev#29662)
1 parent ac6b557 commit dd790e8

File tree

4 files changed

+29
-45
lines changed

4 files changed

+29
-45
lines changed

pandas/compat/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def set_function_name(f, name, cls):
3030
Bind the name/qualname attributes of the function.
3131
"""
3232
f.__name__ = name
33-
f.__qualname__ = "{klass}.{name}".format(klass=cls.__name__, name=name)
33+
f.__qualname__ = f"{cls.__name__}.{name}"
3434
f.__module__ = cls.__module__
3535
return f
3636

pandas/compat/_optional.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@
2828
"xlsxwriter": "0.9.8",
2929
}
3030

31-
message = (
32-
"Missing optional dependency '{name}'. {extra} "
33-
"Use pip or conda to install {name}."
34-
)
35-
version_message = (
36-
"Pandas requires version '{minimum_version}' or newer of '{name}' "
37-
"(version '{actual_version}' currently installed)."
38-
)
39-
4031

4132
def _get_version(module: types.ModuleType) -> str:
4233
version = getattr(module, "__version__", None)
@@ -45,7 +36,7 @@ def _get_version(module: types.ModuleType) -> str:
4536
version = getattr(module, "__VERSION__", None)
4637

4738
if version is None:
48-
raise ImportError("Can't determine version for {}".format(module.__name__))
39+
raise ImportError(f"Can't determine version for {module.__name__}")
4940
return version
5041

5142

@@ -86,11 +77,15 @@ def import_optional_dependency(
8677
is False, or when the package's version is too old and `on_version`
8778
is ``'warn'``.
8879
"""
80+
msg = (
81+
f"Missing optional dependency '{name}'. {extra} "
82+
f"Use pip or conda to install {name}."
83+
)
8984
try:
9085
module = importlib.import_module(name)
9186
except ImportError:
9287
if raise_on_missing:
93-
raise ImportError(message.format(name=name, extra=extra)) from None
88+
raise ImportError(msg) from None
9489
else:
9590
return None
9691

@@ -99,8 +94,9 @@ def import_optional_dependency(
9994
version = _get_version(module)
10095
if distutils.version.LooseVersion(version) < minimum_version:
10196
assert on_version in {"warn", "raise", "ignore"}
102-
msg = version_message.format(
103-
minimum_version=minimum_version, name=name, actual_version=version
97+
msg = (
98+
f"Pandas requires version '{minimum_version}' or newer of '{name}' "
99+
f"(version '{version}' currently installed)."
104100
)
105101
if on_version == "warn":
106102
warnings.warn(msg, UserWarning)

pandas/compat/numpy/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
if _nlv < "1.13.3":
2020
raise ImportError(
21-
"this version of pandas is incompatible with "
22-
"numpy < 1.13.3\n"
23-
"your numpy version is {0}.\n"
24-
"Please upgrade numpy to >= 1.13.3 to use "
25-
"this pandas version".format(_np_version)
21+
f"this version of pandas is incompatible with "
22+
f"numpy < 1.13.3\n"
23+
f"your numpy version is {_np_version}.\n"
24+
f"Please upgrade numpy to >= 1.13.3 to use "
25+
f"this pandas version"
2626
)
2727

2828

pandas/compat/numpy/function.py

+14-26
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ def __call__(self, args, kwargs, fname=None, max_fname_arg_count=None, method=No
5858
fname, args, kwargs, max_fname_arg_count, self.defaults
5959
)
6060
else:
61-
raise ValueError(
62-
"invalid validation method '{method}'".format(method=method)
63-
)
61+
raise ValueError(f"invalid validation method '{method}'")
6462

6563

6664
ARGMINMAX_DEFAULTS = dict(out=None)
@@ -312,9 +310,8 @@ def validate_take_with_convert(convert, args, kwargs):
312310
def validate_window_func(name, args, kwargs):
313311
numpy_args = ("axis", "dtype", "out")
314312
msg = (
315-
"numpy operations are not "
316-
"valid with window objects. "
317-
"Use .{func}() directly instead ".format(func=name)
313+
f"numpy operations are not valid with window objects. "
314+
f"Use .{name}() directly instead "
318315
)
319316

320317
if len(args) > 0:
@@ -328,9 +325,8 @@ def validate_window_func(name, args, kwargs):
328325
def validate_rolling_func(name, args, kwargs):
329326
numpy_args = ("axis", "dtype", "out")
330327
msg = (
331-
"numpy operations are not "
332-
"valid with window objects. "
333-
"Use .rolling(...).{func}() instead ".format(func=name)
328+
f"numpy operations are not valid with window objects. "
329+
f"Use .rolling(...).{name}() instead "
334330
)
335331

336332
if len(args) > 0:
@@ -344,9 +340,8 @@ def validate_rolling_func(name, args, kwargs):
344340
def validate_expanding_func(name, args, kwargs):
345341
numpy_args = ("axis", "dtype", "out")
346342
msg = (
347-
"numpy operations are not "
348-
"valid with window objects. "
349-
"Use .expanding(...).{func}() instead ".format(func=name)
343+
f"numpy operations are not valid with window objects. "
344+
f"Use .expanding(...).{name}() instead "
350345
)
351346

352347
if len(args) > 0:
@@ -371,11 +366,9 @@ def validate_groupby_func(name, args, kwargs, allowed=None):
371366

372367
if len(args) + len(kwargs) > 0:
373368
raise UnsupportedFunctionCall(
374-
(
375-
"numpy operations are not valid "
376-
"with groupby. Use .groupby(...)."
377-
"{func}() instead".format(func=name)
378-
)
369+
f"numpy operations are not valid with "
370+
f"groupby. Use .groupby(...).{name}() "
371+
f"instead"
379372
)
380373

381374

@@ -391,11 +384,9 @@ def validate_resampler_func(method, args, kwargs):
391384
if len(args) + len(kwargs) > 0:
392385
if method in RESAMPLER_NUMPY_OPS:
393386
raise UnsupportedFunctionCall(
394-
(
395-
"numpy operations are not valid "
396-
"with resample. Use .resample(...)."
397-
"{func}() instead".format(func=method)
398-
)
387+
f"numpy operations are not "
388+
f"valid with resample. Use "
389+
f".resample(...).{method}() instead"
399390
)
400391
else:
401392
raise TypeError("too many arguments passed in")
@@ -418,7 +409,4 @@ def validate_minmax_axis(axis):
418409
if axis is None:
419410
return
420411
if axis >= ndim or (axis < 0 and ndim + axis < 0):
421-
raise ValueError(
422-
"`axis` must be fewer than the number of "
423-
"dimensions ({ndim})".format(ndim=ndim)
424-
)
412+
raise ValueError(f"`axis` must be fewer than the number of dimensions ({ndim})")

0 commit comments

Comments
 (0)