Skip to content

Commit dc94c13

Browse files
committed
Replaced .format{}/% with f-strings
Modifeid to python3 format strings ref: pandas-dev#29547
1 parent 5a7b5c9 commit dc94c13

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

pandas/core/tools/datetimes.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ def _adjust_to_origin(arg, origin, unit):
475475
j_min = Timestamp.min.to_julian_date() - j0
476476
if np.any(arg > j_max) or np.any(arg < j_min):
477477
raise tslibs.OutOfBoundsDatetime(
478-
"{original} is Out of Bounds for "
479-
"origin='julian'".format(original=original)
478+
f"{original} is Out of Bounds for "
479+
"origin='julian'"
480480
)
481481
else:
482482
# arg must be numeric
@@ -485,27 +485,25 @@ def _adjust_to_origin(arg, origin, unit):
485485
or is_numeric_dtype(np.asarray(arg))
486486
):
487487
raise ValueError(
488-
"'{arg}' is not compatible with origin='{origin}'; "
489-
"it must be numeric with a unit specified ".format(
490-
arg=arg, origin=origin
491-
)
488+
f"'{arg}' is not compatible with origin='{origin}'; "
489+
"it must be numeric with a unit specified "
492490
)
493491

494492
# we are going to offset back to unix / epoch time
495493
try:
496494
offset = Timestamp(origin)
497495
except tslibs.OutOfBoundsDatetime:
498496
raise tslibs.OutOfBoundsDatetime(
499-
"origin {origin} is Out of Bounds".format(origin=origin)
497+
f"origin {origin} is Out of Bounds"
500498
)
501499
except ValueError:
502500
raise ValueError(
503-
"origin {origin} cannot be converted "
504-
"to a Timestamp".format(origin=origin)
501+
f"origin {origin} cannot be converted "
502+
"to a Timestamp"
505503
)
506504

507505
if offset.tz is not None:
508-
raise ValueError("origin offset {} must be tz-naive".format(offset))
506+
raise ValueError(f"origin offset {offset} must be tz-naive")
509507
offset -= Timestamp(0)
510508

511509
# convert the offset to the unit of the arg
@@ -810,8 +808,8 @@ def f(value):
810808
if len(req):
811809
raise ValueError(
812810
"to assemble mappings requires at least that "
813-
"[year, month, day] be specified: [{required}] "
814-
"is missing".format(required=",".join(req))
811+
f"[year, month, day] be specified: [{','.join(req)}] "
812+
"is missing"
815813
)
816814

817815
# keys we don't recognize
@@ -820,7 +818,7 @@ def f(value):
820818
raise ValueError(
821819
"extra keys have been passed "
822820
"to the datetime assemblage: "
823-
"[{excess}]".format(excess=",".join(excess))
821+
f"[{','.join(excess)}]"
824822
)
825823

826824
def coerce(values):
@@ -983,9 +981,9 @@ def _convert_listlike(arg, format):
983981
except (ValueError, TypeError):
984982
if errors == "raise":
985983
msg = (
986-
"Cannot convert {element} to a time with given "
987-
"format {format}"
988-
).format(element=element, format=format)
984+
f"Cannot convert {element} to a time with given "
985+
f"format {format}"
986+
)
989987
raise ValueError(msg)
990988
elif errors == "ignore":
991989
return arg
@@ -1012,7 +1010,7 @@ def _convert_listlike(arg, format):
10121010
times.append(time_object)
10131011
elif errors == "raise":
10141012
raise ValueError(
1015-
"Cannot convert arg {arg} to a time".format(arg=arg)
1013+
f"Cannot convert arg {arg} to a time"
10161014
)
10171015
elif errors == "ignore":
10181016
return arg

0 commit comments

Comments
 (0)