-
Notifications
You must be signed in to change notification settings - Fork 225
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
Running info on pandas.DataFrame with time column doesn't work #597
Comments
Here is the definition of the int GMT_Put_Matrix (void *API, struct GMT_MATRIX *M, unsigned int type, int pad, void *matrix) The third parameter type is the data type of the matrix, e.g., The fix seems easy. We may have to pass 2D arrays as a series of vectors, via |
Ping @weiji14. |
Right, so we'll need to have something like an if-then or try-except to handle mixed dtypes. A couple of other details to consider:
Note that
I've got a unit test for this written up already and will submit a PR soon, just need to work out these implementation details 😄. |
Just following up on this, we've merged in #619 so if you install PyGMT from the master branch, passing in A workaround for this as mentioned at GenericMappingTools/gmt#4241 (comment) is to use something like We will close this issue once this upstream GMT issue at GenericMappingTools/gmt#4241 is resolved, and perhaps when PyGMT bumps the minimum required version to GMT 6.2.0 and/or when conda GMT 6.2.0.dev builds are available with conda-forge/gmt-feedstock#100. |
So the workaround doesn't quite work because of the way we've implemented things in #619 using import pandas as pd
import pygmt
table = pd.date_range(start="2010-01-01", end="2020-01-01")
pygmt.info(table=table, spacing="1Y", f="0T") errors with: ---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-88-cac984c8d7d8> in <module>
----> 1 pygmt.info(table=df[[time_var, elev_var]], spacing=f"1W/{spacing}", f="0T")
~/miniconda3/envs/pygmt/src/pygmt/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
268 if alias in kwargs:
269 kwargs[arg] = kwargs.pop(alias)
--> 270 return module_func(*args, **kwargs)
271
272 new_module.aliases = aliases
~/miniconda3/envs/pygmt/src/pygmt/pygmt/modules.py in info(table, **kwargs)
137 if result.startswith(("-R", "-T")): # e.g. -R0/1/2/3 or -T0/9/1
138 result = result[2:].replace("/", " ")
--> 139 result = np.loadtxt(result.splitlines())
140
141 return result
~/miniconda3/envs/pygmt/lib/python3.8/site-packages/numpy/lib/npyio.py in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin, encoding, max_rows)
1137 # converting the data
1138 X = None
-> 1139 for x in read_data(_loadtxt_chunksize):
1140 if X is None:
1141 X = np.array(x, dtype)
~/miniconda3/envs/pygmt/lib/python3.8/site-packages/numpy/lib/npyio.py in read_data(chunk_size)
1065
1066 # Convert each value according to its column and store
-> 1067 items = [conv(val) for (conv, val) in zip(converters, vals)]
1068
1069 # Then pack it according to the dtype's nesting
~/miniconda3/envs/pygmt/lib/python3.8/site-packages/numpy/lib/npyio.py in <listcomp>(.0)
1065
1066 # Convert each value according to its column and store
-> 1067 items = [conv(val) for (conv, val) in zip(converters, vals)]
1068
1069 # Then pack it according to the dtype's nesting
~/miniconda3/envs/pygmt/lib/python3.8/site-packages/numpy/lib/npyio.py in floatconv(x)
761 if '0x' in x:
762 return float.fromhex(x)
--> 763 return float(x)
764
765 typ = dtype.type
ValueError: could not convert string to float: '2019-05-19T20:53:51' np.loadtxt assumes that the text are to be read as floating point numbers, but datetimes like "2019-05-19T20:53:51" are not floats. We'll need to set the dtype using Line 139 in c7c5eae
|
Alright, with #960 merged. Anyone installing PyGMT from the master branch (see https://www.pygmt.org/v0.3.0/install.html#using-pip) should be able to use the import pandas as pd
import pygmt
table = pd.date_range(start="2010-01-01", end="2020-01-01")
region = pygmt.info(table=table, spacing="1Y", coltypes="0T")
print(region)
# ['2010-01-01T00:00:00' '2020-01-01T00:00:00' '0' '0'] Assuming that GenericMappingTools/gmt#4241 is resolved in GMT 6.2.0, then GMT 6.2.0 users won't need to use the |
FYI, GenericMappingTools/gmt#4241 has been magically resolved, so this issue can be resolved when PyGMT bumps the minimum version to GMT 6.2.0! |
Fixed by GenericMappingTools/gmt#4849 |
Phew, thanks team, glad to close down another >6 month old issue! |
Description of the problem
Just noticed that datetime columns being passed into
pygmt.info
doesn't work. This follows on from thepandas.DataFrame
inputs intopygmt.info
functionality added in #574, see also #464 and #562 where the datetime machinery should be more or less implemented.Full code that generated the error
Note that the equivalent
gmt
command does work on datetime inputs.Full error message
System information
Please paste the output of
python -c "import pygmt; pygmt.show_versions()"
:The text was updated successfully, but these errors were encountered: