Skip to content

Commit

Permalink
STY: "{foo!r}" -> "{repr(foo)}" #batch-3 (#29953)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaharNaveh authored and simonjayhawkins committed Dec 10, 2019
1 parent 52f5fdf commit 87dc029
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def interpolate_1d(
valid_limit_directions = ["forward", "backward", "both"]
limit_direction = limit_direction.lower()
if limit_direction not in valid_limit_directions:
msg = "Invalid limit_direction: expecting one of {valid!r}, got {invalid!r}."
raise ValueError(
msg.format(valid=valid_limit_directions, invalid=limit_direction)
f"Invalid limit_direction: expecting one of "
f"{valid_limit_directions}, got '{limit_direction}'."
)

if limit_area is not None:
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ def __call__(self, f):
def _f(*args, **kwargs):
obj_iter = itertools.chain(args, kwargs.values())
if any(self.check(obj) for obj in obj_iter):
msg = "reduction operation {name!r} not allowed for this dtype"
raise TypeError(msg.format(name=f.__name__.replace("nan", "")))
f_name = f.__name__.replace("nan", "")
raise TypeError(
f"reduction operation '{f_name}' not allowed for this dtype"
)
try:
with np.errstate(invalid="ignore"):
return f(*args, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ def _get_concat_axis(self) -> Index:
for i, x in enumerate(self.objs):
if not isinstance(x, Series):
raise TypeError(
"Cannot concatenate type 'Series' "
"with object of type {type!r}".format(type=type(x).__name__)
f"Cannot concatenate type 'Series' with "
f"object of type '{type(x).__name__}'"
)
if x.name is not None:
names[i] = x.name
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,9 +1197,7 @@ def _validate_specification(self):
)
)
if not common_cols.is_unique:
raise MergeError(
"Data columns not unique: {common!r}".format(common=common_cols)
)
raise MergeError(f"Data columns not unique: {repr(common_cols)}")
self.left_on = self.right_on = common_cols
elif self.on is not None:
if self.left_on is not None or self.right_on is not None:
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/reshape/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,8 @@ def _bins_to_cuts(
if len(unique_bins) < len(bins) and len(bins) != 2:
if duplicates == "raise":
raise ValueError(
"Bin edges must be unique: {bins!r}.\nYou "
"can drop duplicate edges by setting "
"the 'duplicates' kwarg".format(bins=bins)
f"Bin edges must be unique: {repr(bins)}.\n"
f"You can drop duplicate edges by setting the 'duplicates' kwarg"
)
else:
bins = unique_bins
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,8 +1933,8 @@ def _forbid_nonstring_types(func):
def wrapper(self, *args, **kwargs):
if self._inferred_dtype not in allowed_types:
msg = (
f"Cannot use .str.{func_name} with values of inferred dtype "
f"{repr(self._inferred_dtype)}."
f"Cannot use .str.{func_name} with values of "
f"inferred dtype '{self._inferred_dtype}'."
)
raise TypeError(msg)
return func(self, *args, **kwargs)
Expand Down
5 changes: 2 additions & 3 deletions pandas/io/formats/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __call__(self, declarations_str, inherited=None):

def size_to_pt(self, in_val, em_pt=None, conversions=UNIT_RATIOS):
def _error():
warnings.warn("Unhandled size: {val!r}".format(val=in_val), CSSWarning)
warnings.warn(f"Unhandled size: {repr(in_val)}", CSSWarning)
return self.size_to_pt("1!!default", conversions=conversions)

try:
Expand Down Expand Up @@ -252,7 +252,6 @@ def parse(self, declarations_str):
yield prop, val
else:
warnings.warn(
"Ill-formatted attribute: expected a colon "
"in {decl!r}".format(decl=decl),
f"Ill-formatted attribute: expected a colon in {repr(decl)}",
CSSWarning,
)
2 changes: 1 addition & 1 deletion pandas/io/formats/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def color_to_excel(self, val):
try:
return self.NAMED_COLORS[val]
except KeyError:
warnings.warn("Unhandled color format: {val!r}".format(val=val), CSSWarning)
warnings.warn(f"Unhandled color format: {repr(val)}", CSSWarning)

def build_number_format(self, props):
return {"format_code": props.get("number-format")}
Expand Down
22 changes: 9 additions & 13 deletions pandas/io/formats/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,29 +627,25 @@ def _apply(self, func, axis=0, subset=None, **kwargs):
result = func(data, **kwargs)
if not isinstance(result, pd.DataFrame):
raise TypeError(
"Function {func!r} must return a DataFrame when "
"passed to `Styler.apply` with axis=None".format(func=func)
f"Function {repr(func)} must return a DataFrame when "
f"passed to `Styler.apply` with axis=None"
)
if not (
result.index.equals(data.index) and result.columns.equals(data.columns)
):
msg = (
"Result of {func!r} must have identical index and "
"columns as the input".format(func=func)
raise ValueError(
f"Result of {repr(func)} must have identical "
f"index and columns as the input"
)
raise ValueError(msg)

result_shape = result.shape
expected_shape = self.data.loc[subset].shape
if result_shape != expected_shape:
msg = (
"Function {func!r} returned the wrong shape.\n"
"Result has shape: {res}\n"
"Expected shape: {expect}".format(
func=func, res=result.shape, expect=expected_shape
)
raise ValueError(
f"Function {repr(func)} returned the wrong shape.\n"
f"Result has shape: {result.shape}\n"
f"Expected shape: {expected_shape}"
)
raise ValueError(msg)
self._update_ctx(result)
return self

Expand Down

0 comments on commit 87dc029

Please sign in to comment.