Skip to content

Commit 87dc029

Browse files
ShaharNavehsimonjayhawkins
authored andcommitted
STY: "{foo!r}" -> "{repr(foo)}" #batch-3 (#29953)
1 parent 52f5fdf commit 87dc029

File tree

9 files changed

+25
-31
lines changed

9 files changed

+25
-31
lines changed

pandas/core/missing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ def interpolate_1d(
211211
valid_limit_directions = ["forward", "backward", "both"]
212212
limit_direction = limit_direction.lower()
213213
if limit_direction not in valid_limit_directions:
214-
msg = "Invalid limit_direction: expecting one of {valid!r}, got {invalid!r}."
215214
raise ValueError(
216-
msg.format(valid=valid_limit_directions, invalid=limit_direction)
215+
f"Invalid limit_direction: expecting one of "
216+
f"{valid_limit_directions}, got '{limit_direction}'."
217217
)
218218

219219
if limit_area is not None:

pandas/core/nanops.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ def __call__(self, f):
6060
def _f(*args, **kwargs):
6161
obj_iter = itertools.chain(args, kwargs.values())
6262
if any(self.check(obj) for obj in obj_iter):
63-
msg = "reduction operation {name!r} not allowed for this dtype"
64-
raise TypeError(msg.format(name=f.__name__.replace("nan", "")))
63+
f_name = f.__name__.replace("nan", "")
64+
raise TypeError(
65+
f"reduction operation '{f_name}' not allowed for this dtype"
66+
)
6567
try:
6668
with np.errstate(invalid="ignore"):
6769
return f(*args, **kwargs)

pandas/core/reshape/concat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ def _get_concat_axis(self) -> Index:
507507
for i, x in enumerate(self.objs):
508508
if not isinstance(x, Series):
509509
raise TypeError(
510-
"Cannot concatenate type 'Series' "
511-
"with object of type {type!r}".format(type=type(x).__name__)
510+
f"Cannot concatenate type 'Series' with "
511+
f"object of type '{type(x).__name__}'"
512512
)
513513
if x.name is not None:
514514
names[i] = x.name

pandas/core/reshape/merge.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1197,9 +1197,7 @@ def _validate_specification(self):
11971197
)
11981198
)
11991199
if not common_cols.is_unique:
1200-
raise MergeError(
1201-
"Data columns not unique: {common!r}".format(common=common_cols)
1202-
)
1200+
raise MergeError(f"Data columns not unique: {repr(common_cols)}")
12031201
self.left_on = self.right_on = common_cols
12041202
elif self.on is not None:
12051203
if self.left_on is not None or self.right_on is not None:

pandas/core/reshape/tile.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,8 @@ def _bins_to_cuts(
376376
if len(unique_bins) < len(bins) and len(bins) != 2:
377377
if duplicates == "raise":
378378
raise ValueError(
379-
"Bin edges must be unique: {bins!r}.\nYou "
380-
"can drop duplicate edges by setting "
381-
"the 'duplicates' kwarg".format(bins=bins)
379+
f"Bin edges must be unique: {repr(bins)}.\n"
380+
f"You can drop duplicate edges by setting the 'duplicates' kwarg"
382381
)
383382
else:
384383
bins = unique_bins

pandas/core/strings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1933,8 +1933,8 @@ def _forbid_nonstring_types(func):
19331933
def wrapper(self, *args, **kwargs):
19341934
if self._inferred_dtype not in allowed_types:
19351935
msg = (
1936-
f"Cannot use .str.{func_name} with values of inferred dtype "
1937-
f"{repr(self._inferred_dtype)}."
1936+
f"Cannot use .str.{func_name} with values of "
1937+
f"inferred dtype '{self._inferred_dtype}'."
19381938
)
19391939
raise TypeError(msg)
19401940
return func(self, *args, **kwargs)

pandas/io/formats/css.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def __call__(self, declarations_str, inherited=None):
173173

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

179179
try:
@@ -252,7 +252,6 @@ def parse(self, declarations_str):
252252
yield prop, val
253253
else:
254254
warnings.warn(
255-
"Ill-formatted attribute: expected a colon "
256-
"in {decl!r}".format(decl=decl),
255+
f"Ill-formatted attribute: expected a colon in {repr(decl)}",
257256
CSSWarning,
258257
)

pandas/io/formats/excel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def color_to_excel(self, val):
321321
try:
322322
return self.NAMED_COLORS[val]
323323
except KeyError:
324-
warnings.warn("Unhandled color format: {val!r}".format(val=val), CSSWarning)
324+
warnings.warn(f"Unhandled color format: {repr(val)}", CSSWarning)
325325

326326
def build_number_format(self, props):
327327
return {"format_code": props.get("number-format")}

pandas/io/formats/style.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -627,29 +627,25 @@ def _apply(self, func, axis=0, subset=None, **kwargs):
627627
result = func(data, **kwargs)
628628
if not isinstance(result, pd.DataFrame):
629629
raise TypeError(
630-
"Function {func!r} must return a DataFrame when "
631-
"passed to `Styler.apply` with axis=None".format(func=func)
630+
f"Function {repr(func)} must return a DataFrame when "
631+
f"passed to `Styler.apply` with axis=None"
632632
)
633633
if not (
634634
result.index.equals(data.index) and result.columns.equals(data.columns)
635635
):
636-
msg = (
637-
"Result of {func!r} must have identical index and "
638-
"columns as the input".format(func=func)
636+
raise ValueError(
637+
f"Result of {repr(func)} must have identical "
638+
f"index and columns as the input"
639639
)
640-
raise ValueError(msg)
641640

642641
result_shape = result.shape
643642
expected_shape = self.data.loc[subset].shape
644643
if result_shape != expected_shape:
645-
msg = (
646-
"Function {func!r} returned the wrong shape.\n"
647-
"Result has shape: {res}\n"
648-
"Expected shape: {expect}".format(
649-
func=func, res=result.shape, expect=expected_shape
650-
)
644+
raise ValueError(
645+
f"Function {repr(func)} returned the wrong shape.\n"
646+
f"Result has shape: {result.shape}\n"
647+
f"Expected shape: {expected_shape}"
651648
)
652-
raise ValueError(msg)
653649
self._update_ctx(result)
654650
return self
655651

0 commit comments

Comments
 (0)