Skip to content

Commit ec1aa21

Browse files
ShaharNavehproost
authored andcommitted
1 parent 12793f1 commit ec1aa21

File tree

10 files changed

+45
-56
lines changed

10 files changed

+45
-56
lines changed

pandas/io/html.py

+10-16
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,7 @@ def _parse_tables(self, doc, match, attrs):
560560
unique_tables.add(table)
561561

562562
if not result:
563-
raise ValueError(
564-
"No tables found matching pattern {patt!r}".format(patt=match.pattern)
565-
)
563+
raise ValueError(f"No tables found matching pattern {repr(match.pattern)}")
566564
return result
567565

568566
def _text_getter(self, obj):
@@ -618,7 +616,7 @@ def _build_xpath_expr(attrs) -> str:
618616
if "class_" in attrs:
619617
attrs["class"] = attrs.pop("class_")
620618

621-
s = ["@{key}={val!r}".format(key=k, val=v) for k, v in attrs.items()]
619+
s = [f"@{k}={repr(v)}" for k, v in attrs.items()]
622620
return "[{expr}]".format(expr=" and ".join(s))
623621

624622

@@ -661,8 +659,7 @@ def _parse_tables(self, doc, match, kwargs):
661659

662660
# 1. check all descendants for the given pattern and only search tables
663661
# 2. go up the tree until we find a table
664-
query = "//table//*[re:test(text(), {patt!r})]/ancestor::table"
665-
xpath_expr = query.format(patt=pattern)
662+
xpath_expr = f"//table//*[re:test(text(), {repr(pattern)})]/ancestor::table"
666663

667664
# if any table attributes were given build an xpath expression to
668665
# search for them
@@ -682,9 +679,7 @@ def _parse_tables(self, doc, match, kwargs):
682679
elem.getparent().remove(elem)
683680

684681
if not tables:
685-
raise ValueError(
686-
"No tables found matching regex {patt!r}".format(patt=pattern)
687-
)
682+
raise ValueError(f"No tables found matching regex {repr(pattern)}")
688683
return tables
689684

690685
def _equals_tag(self, obj, tag):
@@ -833,8 +828,7 @@ def _parser_dispatch(flavor):
833828
valid_parsers = list(_valid_parsers.keys())
834829
if flavor not in valid_parsers:
835830
raise ValueError(
836-
"{invalid!r} is not a valid flavor, valid flavors "
837-
"are {valid}".format(invalid=flavor, valid=valid_parsers)
831+
f"{repr(flavor)} is not a valid flavor, valid flavors are {valid_parsers}"
838832
)
839833

840834
if flavor in ("bs4", "html5lib"):
@@ -863,13 +857,13 @@ def _validate_flavor(flavor):
863857
elif isinstance(flavor, abc.Iterable):
864858
if not all(isinstance(flav, str) for flav in flavor):
865859
raise TypeError(
866-
"Object of type {typ!r} is not an iterable of "
867-
"strings".format(typ=type(flavor).__name__)
860+
f"Object of type {repr(type(flavor).__name__)} "
861+
f"is not an iterable of strings"
868862
)
869863
else:
870-
fmt = "{flavor!r}" if isinstance(flavor, str) else "{flavor}"
871-
fmt += " is not a valid flavor"
872-
raise ValueError(fmt.format(flavor=flavor))
864+
msg = repr(flavor) if isinstance(flavor, str) else str(flavor)
865+
msg += " is not a valid flavor"
866+
raise ValueError(msg)
873867

874868
flavor = tuple(flavor)
875869
valid_flavors = set(_valid_parsers)

pandas/io/parsers.py

+19-22
Original file line numberDiff line numberDiff line change
@@ -972,10 +972,10 @@ def _clean_options(self, options, engine):
972972
elif engine not in ("python", "python-fwf"):
973973
# wait until regex engine integrated
974974
fallback_reason = (
975-
"the 'c' engine does not support"
976-
" regex separators (separators > 1 char and"
977-
r" different from '\s+' are"
978-
" interpreted as regex)"
975+
"the 'c' engine does not support "
976+
"regex separators (separators > 1 char and "
977+
r"different from '\s+' are "
978+
"interpreted as regex)"
979979
)
980980
engine = "python"
981981
elif delim_whitespace:
@@ -990,9 +990,9 @@ def _clean_options(self, options, engine):
990990
encodeable = False
991991
if not encodeable and engine not in ("python", "python-fwf"):
992992
fallback_reason = (
993-
"the separator encoded in {encoding}"
994-
" is > 1 char long, and the 'c' engine"
995-
" does not support such separators".format(encoding=encoding)
993+
"the separator encoded in {encoding} "
994+
"is > 1 char long, and the 'c' engine "
995+
"does not support such separators".format(encoding=encoding)
996996
)
997997
engine = "python"
998998

@@ -1021,21 +1021,19 @@ def _clean_options(self, options, engine):
10211021
if "python" in engine:
10221022
for arg in _python_unsupported:
10231023
if fallback_reason and result[arg] != _c_parser_defaults[arg]:
1024-
msg = (
1025-
"Falling back to the 'python' engine because"
1026-
" {reason}, but this causes {option!r} to be"
1027-
" ignored as it is not supported by the 'python'"
1028-
" engine."
1029-
).format(reason=fallback_reason, option=arg)
1030-
raise ValueError(msg)
1024+
raise ValueError(
1025+
f"Falling back to the 'python' engine because "
1026+
f"{fallback_reason}, but this causes {repr(arg)} to be "
1027+
f"ignored as it is not supported by the 'python' engine."
1028+
)
10311029
del result[arg]
10321030

10331031
if fallback_reason:
10341032
warnings.warn(
10351033
(
1036-
"Falling back to the 'python' engine because"
1037-
" {0}; you can avoid this warning by specifying"
1038-
" engine='python'."
1034+
"Falling back to the 'python' engine because "
1035+
"{0}; you can avoid this warning by specifying "
1036+
"engine='python'."
10391037
).format(fallback_reason),
10401038
ParserWarning,
10411039
stacklevel=5,
@@ -1056,8 +1054,8 @@ def _clean_options(self, options, engine):
10561054
depr_default = _deprecated_defaults[arg]
10571055

10581056
msg = (
1059-
"The '{arg}' argument has been deprecated "
1060-
"and will be removed in a future version.".format(arg=arg)
1057+
f"The {repr(arg)} argument has been deprecated and will be "
1058+
f"removed in a future version."
10611059
)
10621060

10631061
if result.get(arg, depr_default) != depr_default:
@@ -1081,9 +1079,8 @@ def _clean_options(self, options, engine):
10811079
if converters is not None:
10821080
if not isinstance(converters, dict):
10831081
raise TypeError(
1084-
"Type converters must be a dict or"
1085-
" subclass, input was "
1086-
"a {0!r}".format(type(converters).__name__)
1082+
f"Type converters must be a dict or subclass, "
1083+
f"input was a {repr(type(converters).__name__)}"
10871084
)
10881085
else:
10891086
converters = {}

pandas/plotting/_core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def _get_call_args(backend_name, data, args, kwargs):
743743
if args and isinstance(data, ABCSeries):
744744
positional_args = str(args)[1:-1]
745745
keyword_args = ", ".join(
746-
f"{name}={value!r}" for (name, default), value in zip(arg_def, args)
746+
f"{name}={repr(value)}" for (name, default), value in zip(arg_def, args)
747747
)
748748
msg = (
749749
"`Series.plot()` should not be called with positional "

pandas/tests/computation/test_eval.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,11 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
11141114
if not is_python_engine:
11151115
assert len(w) == 1
11161116
msg = str(w[0].message)
1117+
loged = np.log10(s.size - df.shape[1])
11171118
expected = (
1118-
"Alignment difference on axis {0} is larger"
1119-
" than an order of magnitude on term {1!r}, "
1120-
"by more than {2:.4g}; performance may suffer"
1121-
"".format(1, "df", np.log10(s.size - df.shape[1]))
1119+
f"Alignment difference on axis 1 is larger "
1120+
f"than an order of magnitude on term 'df', "
1121+
f"by more than {loged:.4g}; performance may suffer"
11221122
)
11231123
assert msg == expected
11241124

pandas/tests/frame/test_alter_axes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def __init__(self, name, color):
342342
self.color = color
343343

344344
def __str__(self) -> str:
345-
return "<Thing {self.name!r}>".format(self=self)
345+
return f"<Thing {repr(self.name)}>"
346346

347347
# necessary for pretty KeyError
348348
__repr__ = __str__
@@ -419,7 +419,7 @@ def __init__(self, name, color):
419419
self.color = color
420420

421421
def __str__(self) -> str:
422-
return "<Thing {self.name!r}>".format(self=self)
422+
return f"<Thing {repr(self.name)}>"
423423

424424
thing1 = Thing("One", "red")
425425
thing2 = Thing("Two", "blue")

pandas/tests/frame/test_query_eval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def engine(request):
2727

2828
def skip_if_no_pandas_parser(parser):
2929
if parser != "pandas":
30-
pytest.skip("cannot evaluate with parser {0!r}".format(parser))
30+
pytest.skip(f"cannot evaluate with parser {repr(parser)}")
3131

3232

3333
class TestCompat:

pandas/tests/indexes/timedeltas/test_timedelta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def test_pickle(self):
234234
def test_hash_error(self):
235235
index = timedelta_range("1 days", periods=10)
236236
with pytest.raises(
237-
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
237+
TypeError, match=(f"unhashable type: {repr(type(index).__name__)}")
238238
):
239239
hash(index)
240240

pandas/tests/io/parser/test_unsupported.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ def test_python_engine(self, python_engine):
9696

9797
for default in py_unsupported:
9898
msg = (
99-
"The {default!r} option is not supported with the {python_engine!r}"
100-
" engine"
101-
).format(default=default, python_engine=python_engine)
99+
f"The {repr(default)} option is not "
100+
f"supported with the {repr(python_engine)} engine"
101+
)
102102

103103
kwargs = {default: object()}
104104
with pytest.raises(ValueError, match=msg):

pandas/tests/io/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,8 @@ def test_computer_sales_page(self, datapath):
902902

903903
def test_wikipedia_states_table(self, datapath):
904904
data = datapath("io", "data", "html", "wikipedia_states.html")
905-
assert os.path.isfile(data), "{data!r} is not a file".format(data=data)
906-
assert os.path.getsize(data), "{data!r} is an empty file".format(data=data)
905+
assert os.path.isfile(data), f"{repr(data)} is not a file"
906+
assert os.path.getsize(data), f"{repr(data)} is an empty file"
907907
result = self.read_html(data, "Arizona", header=1)[0]
908908
assert result["sq mi"].dtype == np.dtype("float64")
909909

pandas/tests/test_strings.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,8 @@ def test_api_per_method(
296296
else:
297297
# GH 23011, GH 23163
298298
msg = (
299-
"Cannot use .str.{name} with values of inferred dtype "
300-
"{inferred_dtype!r}.".format(
301-
name=method_name, inferred_dtype=inferred_dtype
302-
)
299+
f"Cannot use .str.{method_name} with values of "
300+
f"inferred dtype {repr(inferred_dtype)}."
303301
)
304302
with pytest.raises(TypeError, match=msg):
305303
method(*args, **kwargs)

0 commit comments

Comments
 (0)