diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 2d43623cec92c..f193865d90b71 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -475,8 +475,7 @@ def _adjust_to_origin(arg, origin, unit): j_min = Timestamp.min.to_julian_date() - j0 if np.any(arg > j_max) or np.any(arg < j_min): raise tslibs.OutOfBoundsDatetime( - "{original} is Out of Bounds for " - "origin='julian'".format(original=original) + f"{original} is Out of Bounds for origin='julian'" ) else: # arg must be numeric @@ -485,27 +484,20 @@ def _adjust_to_origin(arg, origin, unit): or is_numeric_dtype(np.asarray(arg)) ): raise ValueError( - "'{arg}' is not compatible with origin='{origin}'; " - "it must be numeric with a unit specified ".format( - arg=arg, origin=origin - ) + f"'{arg}' is not compatible with origin='{origin}'; " + "it must be numeric with a unit specified" ) # we are going to offset back to unix / epoch time try: offset = Timestamp(origin) except tslibs.OutOfBoundsDatetime: - raise tslibs.OutOfBoundsDatetime( - "origin {origin} is Out of Bounds".format(origin=origin) - ) + raise tslibs.OutOfBoundsDatetime(f"origin {origin} is Out of Bounds") except ValueError: - raise ValueError( - "origin {origin} cannot be converted " - "to a Timestamp".format(origin=origin) - ) + raise ValueError(f"origin {origin} cannot be converted to a Timestamp") if offset.tz is not None: - raise ValueError("origin offset {} must be tz-naive".format(offset)) + raise ValueError(f"origin offset {offset} must be tz-naive") offset -= Timestamp(0) # convert the offset to the unit of the arg @@ -808,19 +800,19 @@ def f(value): required = ["year", "month", "day"] req = sorted(set(required) - set(unit_rev.keys())) if len(req): + required = ",".join(req) raise ValueError( "to assemble mappings requires at least that " - "[year, month, day] be specified: [{required}] " - "is missing".format(required=",".join(req)) + f"[year, month, day] be specified: [{required}] " + "is missing" ) # keys we don't recognize excess = sorted(set(unit_rev.keys()) - set(_unit_map.values())) if len(excess): + excess = ",".join(excess) raise ValueError( - "extra keys have been passed " - "to the datetime assemblage: " - "[{excess}]".format(excess=",".join(excess)) + f"extra keys have been passed to the datetime assemblage: [{excess}]" ) def coerce(values): @@ -983,9 +975,9 @@ def _convert_listlike(arg, format): except (ValueError, TypeError): if errors == "raise": msg = ( - "Cannot convert {element} to a time with given " - "format {format}" - ).format(element=element, format=format) + f"Cannot convert {element} to a time with given " + f"format {format}" + ) raise ValueError(msg) elif errors == "ignore": return arg @@ -1011,9 +1003,7 @@ def _convert_listlike(arg, format): if time_object is not None: times.append(time_object) elif errors == "raise": - raise ValueError( - "Cannot convert arg {arg} to a time".format(arg=arg) - ) + raise ValueError(f"Cannot convert arg {arg} to a time") elif errors == "ignore": return arg else: