Skip to content

Commit 2b453f5

Browse files
JMBurleyAlexKirko
authored andcommitted
Replaced .format{}/% with f-strings in core/tools/datetime.py (pandas-dev#30440)
1 parent 1a71b94 commit 2b453f5

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
@@ -491,8 +491,7 @@ def _adjust_to_origin(arg, origin, unit):
491491
j_min = Timestamp.min.to_julian_date() - j0
492492
if np.any(arg > j_max) or np.any(arg < j_min):
493493
raise tslibs.OutOfBoundsDatetime(
494-
"{original} is Out of Bounds for "
495-
"origin='julian'".format(original=original)
494+
f"{original} is Out of Bounds for origin='julian'"
496495
)
497496
else:
498497
# arg must be numeric
@@ -501,27 +500,20 @@ def _adjust_to_origin(arg, origin, unit):
501500
or is_numeric_dtype(np.asarray(arg))
502501
):
503502
raise ValueError(
504-
"'{arg}' is not compatible with origin='{origin}'; "
505-
"it must be numeric with a unit specified ".format(
506-
arg=arg, origin=origin
507-
)
503+
f"'{arg}' is not compatible with origin='{origin}'; "
504+
"it must be numeric with a unit specified"
508505
)
509506

510507
# we are going to offset back to unix / epoch time
511508
try:
512509
offset = Timestamp(origin)
513510
except tslibs.OutOfBoundsDatetime:
514-
raise tslibs.OutOfBoundsDatetime(
515-
"origin {origin} is Out of Bounds".format(origin=origin)
516-
)
511+
raise tslibs.OutOfBoundsDatetime(f"origin {origin} is Out of Bounds")
517512
except ValueError:
518-
raise ValueError(
519-
"origin {origin} cannot be converted "
520-
"to a Timestamp".format(origin=origin)
521-
)
513+
raise ValueError(f"origin {origin} cannot be converted to a Timestamp")
522514

523515
if offset.tz is not None:
524-
raise ValueError("origin offset {} must be tz-naive".format(offset))
516+
raise ValueError(f"origin offset {offset} must be tz-naive")
525517
offset -= Timestamp(0)
526518

527519
# convert the offset to the unit of the arg
@@ -824,19 +816,19 @@ def f(value):
824816
required = ["year", "month", "day"]
825817
req = sorted(set(required) - set(unit_rev.keys()))
826818
if len(req):
819+
required = ",".join(req)
827820
raise ValueError(
828821
"to assemble mappings requires at least that "
829-
"[year, month, day] be specified: [{required}] "
830-
"is missing".format(required=",".join(req))
822+
f"[year, month, day] be specified: [{required}] "
823+
"is missing"
831824
)
832825

833826
# keys we don't recognize
834827
excess = sorted(set(unit_rev.keys()) - set(_unit_map.values()))
835828
if len(excess):
829+
excess = ",".join(excess)
836830
raise ValueError(
837-
"extra keys have been passed "
838-
"to the datetime assemblage: "
839-
"[{excess}]".format(excess=",".join(excess))
831+
f"extra keys have been passed to the datetime assemblage: [{excess}]"
840832
)
841833

842834
def coerce(values):
@@ -999,9 +991,9 @@ def _convert_listlike(arg, format):
999991
except (ValueError, TypeError):
1000992
if errors == "raise":
1001993
msg = (
1002-
"Cannot convert {element} to a time with given "
1003-
"format {format}"
1004-
).format(element=element, format=format)
994+
f"Cannot convert {element} to a time with given "
995+
f"format {format}"
996+
)
1005997
raise ValueError(msg)
1006998
elif errors == "ignore":
1007999
return arg
@@ -1027,9 +1019,7 @@ def _convert_listlike(arg, format):
10271019
if time_object is not None:
10281020
times.append(time_object)
10291021
elif errors == "raise":
1030-
raise ValueError(
1031-
"Cannot convert arg {arg} to a time".format(arg=arg)
1032-
)
1022+
raise ValueError(f"Cannot convert arg {arg} to a time")
10331023
elif errors == "ignore":
10341024
return arg
10351025
else:

0 commit comments

Comments
 (0)