Skip to content

Commit 615a585

Browse files
committed
Set date_format to ISO8601 to silence pandas 2.0 UserWarning on read_csv
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
1 parent 4f2c7f4 commit 615a585

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pygmt/src/x2sys_cross.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def tempfile_from_dftrack(track, suffix):
4747
sep="\t",
4848
index=False,
4949
na_rep="NaN", # write a NaN value explicitly instead of a blank string
50-
date_format="%Y-%m-%dT%H:%M:%S.%fZ",
50+
date_format="%Y-%m-%dT%H:%M:%S.%fZ", # ISO8601 format
5151
)
5252
yield tmpfilename
5353
finally:
@@ -235,6 +235,7 @@ def x2sys_cross(tracks=None, outfile=None, **kwargs):
235235
header=2, # Column names are on 2nd row
236236
comment=">", # Skip the 3rd row with a ">"
237237
parse_dates=[2, 3], # Datetimes on 3rd and 4th column
238+
date_format="ISO8601",
238239
)
239240
# Remove the "# " from "# x" in the first column
240241
table = table.rename(columns={table.columns[0]: table.columns[0][2:]})

pygmt/tests/test_x2sys_cross.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_x2sys_cross_input_two_dataframes(mock_x2sys_home):
112112
for i in range(2):
113113
np.random.seed(seed=i)
114114
track = pd.DataFrame(data=np.random.rand(10, 3), columns=("x", "y", "z"))
115-
track["time"] = pd.date_range(start=f"2020-{i}1-01", periods=10, freq="ms")
115+
track["time"] = pd.date_range(start=f"2020-{i}1-01", periods=10, freq="min")
116116
tracks.append(track)
117117

118118
output = x2sys_cross(tracks=tracks, tag=tag, coe="e")

0 commit comments

Comments
 (0)