Skip to content

Commit

Permalink
Set date_format to ISO8601 to silence pandas 2.0 UserWarning on read_csv
Browse files Browse the repository at this point in the history
Use `pd.read_csv(..., date_format="ISO8601")` to silence `UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format.`. Xref pandas-dev/pandas#50601
  • Loading branch information
weiji14 committed Jun 9, 2023
1 parent 4f2c7f4 commit 615a585
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pygmt/src/x2sys_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def tempfile_from_dftrack(track, suffix):
sep="\t",
index=False,
na_rep="NaN", # write a NaN value explicitly instead of a blank string
date_format="%Y-%m-%dT%H:%M:%S.%fZ",
date_format="%Y-%m-%dT%H:%M:%S.%fZ", # ISO8601 format
)
yield tmpfilename
finally:
Expand Down Expand Up @@ -235,6 +235,7 @@ def x2sys_cross(tracks=None, outfile=None, **kwargs):
header=2, # Column names are on 2nd row
comment=">", # Skip the 3rd row with a ">"
parse_dates=[2, 3], # Datetimes on 3rd and 4th column
date_format="ISO8601",
)
# Remove the "# " from "# x" in the first column
table = table.rename(columns={table.columns[0]: table.columns[0][2:]})
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_x2sys_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_x2sys_cross_input_two_dataframes(mock_x2sys_home):
for i in range(2):
np.random.seed(seed=i)
track = pd.DataFrame(data=np.random.rand(10, 3), columns=("x", "y", "z"))
track["time"] = pd.date_range(start=f"2020-{i}1-01", periods=10, freq="ms")
track["time"] = pd.date_range(start=f"2020-{i}1-01", periods=10, freq="min")
tracks.append(track)

output = x2sys_cross(tracks=tracks, tag=tag, coe="e")
Expand Down

0 comments on commit 615a585

Please sign in to comment.