Skip to content

CLN:F-strings #29662

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
Nov 16, 2019
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
2 changes: 1 addition & 1 deletion pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def set_function_name(f, name, cls):
Bind the name/qualname attributes of the function.
"""
f.__name__ = name
f.__qualname__ = "{klass}.{name}".format(klass=cls.__name__, name=name)
f.__qualname__ = f"{cls.__name__}.{name}"
f.__module__ = cls.__module__
return f

Expand Down
22 changes: 9 additions & 13 deletions pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@
"xlsxwriter": "0.9.8",
}

message = (
"Missing optional dependency '{name}'. {extra} "
"Use pip or conda to install {name}."
)
version_message = (
"Pandas requires version '{minimum_version}' or newer of '{name}' "
"(version '{actual_version}' currently installed)."
)


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

if version is None:
raise ImportError("Can't determine version for {}".format(module.__name__))
raise ImportError(f"Can't determine version for {module.__name__}")
return version


Expand Down Expand Up @@ -86,11 +77,15 @@ def import_optional_dependency(
is False, or when the package's version is too old and `on_version`
is ``'warn'``.
"""
msg = (
f"Missing optional dependency '{name}'. {extra} "
f"Use pip or conda to install {name}."
)
try:
module = importlib.import_module(name)
except ImportError:
if raise_on_missing:
raise ImportError(message.format(name=name, extra=extra)) from None
raise ImportError(msg) from None
else:
return None

Expand All @@ -99,8 +94,9 @@ def import_optional_dependency(
version = _get_version(module)
if distutils.version.LooseVersion(version) < minimum_version:
assert on_version in {"warn", "raise", "ignore"}
msg = version_message.format(
minimum_version=minimum_version, name=name, actual_version=version
msg = (
f"Pandas requires version '{minimum_version}' or newer of '{name}' "
f"(version '{version}' currently installed)."
)
if on_version == "warn":
warnings.warn(msg, UserWarning)
Expand Down
10 changes: 5 additions & 5 deletions pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

if _nlv < "1.13.3":
raise ImportError(
"this version of pandas is incompatible with "
"numpy < 1.13.3\n"
"your numpy version is {0}.\n"
"Please upgrade numpy to >= 1.13.3 to use "
"this pandas version".format(_np_version)
f"this version of pandas is incompatible with "
f"numpy < 1.13.3\n"
f"your numpy version is {_np_version}.\n"
f"Please upgrade numpy to >= 1.13.3 to use "
f"this pandas version"
)


Expand Down
40 changes: 14 additions & 26 deletions pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def __call__(self, args, kwargs, fname=None, max_fname_arg_count=None, method=No
fname, args, kwargs, max_fname_arg_count, self.defaults
)
else:
raise ValueError(
"invalid validation method '{method}'".format(method=method)
)
raise ValueError(f"invalid validation method '{method}'")


ARGMINMAX_DEFAULTS = dict(out=None)
Expand Down Expand Up @@ -312,9 +310,8 @@ def validate_take_with_convert(convert, args, kwargs):
def validate_window_func(name, args, kwargs):
numpy_args = ("axis", "dtype", "out")
msg = (
"numpy operations are not "
"valid with window objects. "
"Use .{func}() directly instead ".format(func=name)
f"numpy operations are not valid with window objects. "
f"Use .{name}() directly instead "
)

if len(args) > 0:
Expand All @@ -328,9 +325,8 @@ def validate_window_func(name, args, kwargs):
def validate_rolling_func(name, args, kwargs):
numpy_args = ("axis", "dtype", "out")
msg = (
"numpy operations are not "
"valid with window objects. "
"Use .rolling(...).{func}() instead ".format(func=name)
f"numpy operations are not valid with window objects. "
f"Use .rolling(...).{name}() instead "
)

if len(args) > 0:
Expand All @@ -344,9 +340,8 @@ def validate_rolling_func(name, args, kwargs):
def validate_expanding_func(name, args, kwargs):
numpy_args = ("axis", "dtype", "out")
msg = (
"numpy operations are not "
"valid with window objects. "
"Use .expanding(...).{func}() instead ".format(func=name)
f"numpy operations are not valid with window objects. "
f"Use .expanding(...).{name}() instead "
)

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

if len(args) + len(kwargs) > 0:
raise UnsupportedFunctionCall(
(
"numpy operations are not valid "
"with groupby. Use .groupby(...)."
"{func}() instead".format(func=name)
)
f"numpy operations are not valid with "
f"groupby. Use .groupby(...).{name}() "
f"instead"
)


Expand All @@ -391,11 +384,9 @@ def validate_resampler_func(method, args, kwargs):
if len(args) + len(kwargs) > 0:
if method in RESAMPLER_NUMPY_OPS:
raise UnsupportedFunctionCall(
(
"numpy operations are not valid "
"with resample. Use .resample(...)."
"{func}() instead".format(func=method)
)
f"numpy operations are not "
f"valid with resample. Use "
f".resample(...).{method}() instead"
)
else:
raise TypeError("too many arguments passed in")
Expand All @@ -418,7 +409,4 @@ def validate_minmax_axis(axis):
if axis is None:
return
if axis >= ndim or (axis < 0 and ndim + axis < 0):
raise ValueError(
"`axis` must be fewer than the number of "
"dimensions ({ndim})".format(ndim=ndim)
)
raise ValueError(f"`axis` must be fewer than the number of dimensions ({ndim})")