Skip to content

Replaced .format{}/% with f-strings in core/tools/datetime.py #30440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions pandas/core/tools/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down