Skip to content

Commit

Permalink
Deal with TIME_EPOCH
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed May 25, 2024
1 parent bf59e61 commit 9bc063a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pygmt/src/x2sys_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,20 @@ def x2sys_cross(
# "t_1"/"t_2" means they are absolute datetimes.
# "i_1"/"i_2" means they are dummy times relative to unix epoch.
if output_type == "pandas":
t_or_i = result.columns[2][0]
to_func = {"t": pd.to_datetime, "i": pd.to_timedelta}[t_or_i]
if (time_unit := lib.get_default("TIME_UNIT")) != "s":
msg = (

Check warning on line 233 in pygmt/src/x2sys_cross.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/x2sys_cross.py#L233

Added line #L233 was not covered by tests
f"Configuration TIME_UNIT must be 's' but '{time_unit}' "
"is given."
)
raise GMTInvalidInput(msg)

Check warning on line 237 in pygmt/src/x2sys_cross.py

View check run for this annotation

Codecov / codecov/patch

pygmt/src/x2sys_cross.py#L237

Added line #L237 was not covered by tests
to_args = {"unit": "s"}
match result.columns[2][0]: # "t" or "i".
case "t":
to_func = pd.to_datetime
to_args["origin"] = lib.get_default("TIME_EPOCH")
case "i":
to_func = pd.to_timeldelta
result[result.columns[2:4]] = result[result.columns[2:4]].apply(
to_func, unit="s"
to_func, **to_args
)
return result

0 comments on commit 9bc063a

Please sign in to comment.