Skip to content
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

STY: "{foo!r}" -> "{repr(foo)}" #batch-3 #29953

Merged
merged 18 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
5 changes: 3 additions & 2 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ 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"{repr(valid_limit_directions)}, "
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
f"got {repr(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", "")
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
raise TypeError(
f"reduction operation {repr(f_name)} not allowed for this dtype"
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
)
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 @@ -542,8 +542,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 object "
f"of type {repr(type(x).__name__)}"
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
)
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 @@ -1194,9 +1194,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
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,7 @@ def _try_kind_sort(arr):
sortedIdx[n:] = idx[good][argsorted]
sortedIdx[:n] = idx[bad]
else:
raise ValueError("invalid na_position: {!r}".format(na_position))
raise ValueError(f"invalid na_position: {repr(na_position)}")

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def lexsort_indexer(keys, orders=None, na_position="last"):
cat = Categorical(key, ordered=True)

if na_position not in ["last", "first"]:
raise ValueError("invalid na_position: {!r}".format(na_position))
raise ValueError(f"invalid na_position: {repr(na_position)}")
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved

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


Expand Down
9 changes: 3 additions & 6 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,13 +1932,10 @@ def _forbid_nonstring_types(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
if self._inferred_dtype not in allowed_types:
msg = (
"Cannot use .str.{name} with values of inferred dtype "
"{inf_type!r}.".format(
name=func_name, inf_type=self._inferred_dtype
)
raise TypeError(
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
f"Cannot use .str.{func_name} with values of "
f"inferred dtype {repr(self._inferred_dtype)}."
)
raise TypeError(msg)
return func(self, *args, **kwargs)

wrapper.__name__ = func_name
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"
ShaharNaveh marked this conversation as resolved.
Show resolved Hide resolved
f"Expected shape: {expected_shape}"
)
raise ValueError(msg)
self._update_ctx(result)
return self

Expand Down