Open yvonnefroehlich opened 11 months ago
The following two GMT commands explain the behavior of the GMT's grdtrack module:
$ echo 46 48 56 1994-11-01 | gmt grdtrack -G@earth_relief_01d_g
46 48 56 1994-11-01T00:00:00 -2
$ echo 46 48 56 TEXT | gmt grdtrack -G@earth_relief_01d_g
46 48 56 -2 TEXT
In the first case, the z value (-2) is appended as the last column, while in the 2nd case, the z value is inserted at the 3rd case (column number starting from 0) and the text column is appended as the last column. The philosophy of the GMT I/O mechanism is always putting text at the end of a row.
In your example, the df["trashdate"]
has an object
dtype, which is recognized as a string column, rather then a datetime column.
df["trashdate"] = (51 + 7 * np.random.randn(100)) \
* datetime.timedelta(seconds=3e7) + datetime.date(1950, 1, 1)
To fix the issue, you need to explicitly convert the column to a datetime column instead. For example:
df["trashdate"] = (51 + 7 * np.random.randn(100)) \
* datetime.timedelta(seconds=3e7) + datetime.date(1950, 1, 1)
df["trashdate"] = df["trashdate"].astype("datetime64[ms]")
Description of the problem
This is related to the GMT forum post at https://forum.generic-mapping-tools.org/t/type-error-with-pygmt-grdtrack-possible-bug-or-intended/4286.
If the input pandas DataFrame contains an additional column with datetime objects,
pygmt.grdtrack
mixes up the column names of the output pandas Dataframe.Maybe this is partly related to the issue #2463?
Minimal Complete Verifiable Example
Compare the pandas DataFrames:
and
Full error message
No error message occurs, but the column names after applying
grdtrack
are mixed up in case the pandas DataFrame contains a column with datetime objects.System information