Skip to content

Commit 8fad60d

Browse files
JMBurleyjreback
authored andcommitted
Replaced .format{}/% with f-strings in core/tools/datetime.py (#30440)
1 parent 85b4e80 commit 8fad60d

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

pandas/core/tools/datetimes.py

+15-25
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ 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 origin='julian'"
480479
)
481480
else:
482481
# arg must be numeric
@@ -485,27 +484,20 @@ def _adjust_to_origin(arg, origin, unit):
485484
or is_numeric_dtype(np.asarray(arg))
486485
):
487486
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-
)
487+
f"'{arg}' is not compatible with origin='{origin}'; "
488+
"it must be numeric with a unit specified"
492489
)
493490

494491
# we are going to offset back to unix / epoch time
495492
try:
496493
offset = Timestamp(origin)
497494
except tslibs.OutOfBoundsDatetime:
498-
raise tslibs.OutOfBoundsDatetime(
499-
"origin {origin} is Out of Bounds".format(origin=origin)
500-
)
495+
raise tslibs.OutOfBoundsDatetime(f"origin {origin} is Out of Bounds")
501496
except ValueError:
502-
raise ValueError(
503-
"origin {origin} cannot be converted "
504-
"to a Timestamp".format(origin=origin)
505-
)
497+
raise ValueError(f"origin {origin} cannot be converted to a Timestamp")
506498

507499
if offset.tz is not None:
508-
raise ValueError("origin offset {} must be tz-naive".format(offset))
500+
raise ValueError(f"origin offset {offset} must be tz-naive")
509501
offset -= Timestamp(0)
510502

511503
# convert the offset to the unit of the arg
@@ -808,19 +800,19 @@ def f(value):
808800
required = ["year", "month", "day"]
809801
req = sorted(set(required) - set(unit_rev.keys()))
810802
if len(req):
803+
required = ",".join(req)
811804
raise ValueError(
812805
"to assemble mappings requires at least that "
813-
"[year, month, day] be specified: [{required}] "
814-
"is missing".format(required=",".join(req))
806+
f"[year, month, day] be specified: [{required}] "
807+
"is missing"
815808
)
816809

817810
# keys we don't recognize
818811
excess = sorted(set(unit_rev.keys()) - set(_unit_map.values()))
819812
if len(excess):
813+
excess = ",".join(excess)
820814
raise ValueError(
821-
"extra keys have been passed "
822-
"to the datetime assemblage: "
823-
"[{excess}]".format(excess=",".join(excess))
815+
f"extra keys have been passed to the datetime assemblage: [{excess}]"
824816
)
825817

826818
def coerce(values):
@@ -983,9 +975,9 @@ def _convert_listlike(arg, format):
983975
except (ValueError, TypeError):
984976
if errors == "raise":
985977
msg = (
986-
"Cannot convert {element} to a time with given "
987-
"format {format}"
988-
).format(element=element, format=format)
978+
f"Cannot convert {element} to a time with given "
979+
f"format {format}"
980+
)
989981
raise ValueError(msg)
990982
elif errors == "ignore":
991983
return arg
@@ -1011,9 +1003,7 @@ def _convert_listlike(arg, format):
10111003
if time_object is not None:
10121004
times.append(time_object)
10131005
elif errors == "raise":
1014-
raise ValueError(
1015-
"Cannot convert arg {arg} to a time".format(arg=arg)
1016-
)
1006+
raise ValueError(f"Cannot convert arg {arg} to a time")
10171007
elif errors == "ignore":
10181008
return arg
10191009
else:

0 commit comments

Comments
 (0)