Skip to content

Commit 6bf0c13

Browse files
author
MomIsBestFriend
committed
repr()
1 parent 7711a5e commit 6bf0c13

File tree

11 files changed

+30
-38
lines changed

11 files changed

+30
-38
lines changed

pandas/core/missing.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ 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"{repr(valid_limit_directions)}, "
217+
f"got {repr(limit_direction)}."
217218
)
218219

219220
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 {repr(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
@@ -542,8 +542,8 @@ def _get_concat_axis(self) -> Index:
542542
for i, x in enumerate(self.objs):
543543
if not isinstance(x, Series):
544544
raise TypeError(
545-
"Cannot concatenate type 'Series' "
546-
"with object of type {type!r}".format(type=type(x).__name__)
545+
f"Cannot concatenate type 'Series' with object "
546+
f"of type {repr(type=type(x).__name__)}"
547547
)
548548
if x.name is not None:
549549
names[i] = x.name

pandas/core/reshape/merge.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1194,9 +1194,7 @@ def _validate_specification(self):
11941194
)
11951195
)
11961196
if not common_cols.is_unique:
1197-
raise MergeError(
1198-
"Data columns not unique: {common!r}".format(common=common_cols)
1199-
)
1197+
raise MergeError(f"Data columns not unique: {repr(common_cols)}")
12001198
self.left_on = self.right_on = common_cols
12011199
elif self.on is not None:
12021200
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/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2944,7 +2944,7 @@ def _try_kind_sort(arr):
29442944
sortedIdx[n:] = idx[good][argsorted]
29452945
sortedIdx[:n] = idx[bad]
29462946
else:
2947-
raise ValueError("invalid na_position: {!r}".format(na_position))
2947+
raise ValueError(f"invalid na_position: {repr(na_position)}")
29482948

29492949
result = self._constructor(arr[sortedIdx], index=self.index[sortedIdx])
29502950

pandas/core/sorting.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def lexsort_indexer(keys, orders=None, na_position="last"):
208208
cat = Categorical(key, ordered=True)
209209

210210
if na_position not in ["last", "first"]:
211-
raise ValueError("invalid na_position: {!r}".format(na_position))
211+
raise ValueError(f"invalid na_position: {repr(na_position)}")
212212

213213
n = len(cat.categories)
214214
codes = cat.codes.copy()
@@ -264,7 +264,7 @@ def nargsort(items, kind="quicksort", ascending: bool = True, na_position="last"
264264
elif na_position == "first":
265265
indexer = np.concatenate([nan_idx, indexer])
266266
else:
267-
raise ValueError("invalid na_position: {!r}".format(na_position))
267+
raise ValueError(f"invalid na_position: {repr(na_position)}")
268268
return indexer
269269

270270

pandas/core/strings.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1932,13 +1932,10 @@ def _forbid_nonstring_types(func):
19321932
@wraps(func)
19331933
def wrapper(self, *args, **kwargs):
19341934
if self._inferred_dtype not in allowed_types:
1935-
msg = (
1936-
"Cannot use .str.{name} with values of inferred dtype "
1937-
"{inf_type!r}.".format(
1938-
name=func_name, inf_type=self._inferred_dtype
1939-
)
1935+
raise TypeError(
1936+
f"Cannot use .str.{func_name} with values of "
1937+
f"inferred dtype {repr(self.inferred_dtype)}."
19401938
)
1941-
raise TypeError(msg)
19421939
return func(self, *args, **kwargs)
19431940

19441941
wrapper.__name__ = func_name

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)