question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support datetime data types as input

See original GitHub issue

Description of the problem I want to plot some datetime data on a map. However, gmt-python doesn’t accept string as input.

Full code that generated the error

import pygmt

x = ['2008-01-01', '2012-01-01']
y = [5, 5]

fig = pygmt.Figure()
fig.plot(x, y, J='X10c/5c', R='2005-01-01/2015-01-01/0/10', B=True, W='2p')
fig.show(method='external')

Full error message

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    fig.plot(x, y, J='X10c/5c', R='2005-01-01/2015/01-01/0/10', B=True, W='2p')
  File "/Users/seisman/Gits/gmt/gmt-python/gmt/helpers/decorators.py", line 199, in new_module
    return module_func(*args, **kwargs)
  File "/Users/seisman/Gits/gmt/gmt-python/gmt/helpers/decorators.py", line 294, in new_module
    return module_func(*args, **kwargs)
  File "/Users/seisman/Gits/gmt/gmt-python/gmt/base_plotting.py", line 344, in plot
    with file_context as fname:
  File "/Users/seisman/.anaconda/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "/Users/seisman/Gits/gmt/gmt-python/gmt/clib/session.py", line 1067, in virtualfile_from_vectors
    self.put_vector(dataset, column=col, vector=array)
  File "/Users/seisman/Gits/gmt/gmt-python/gmt/clib/session.py", line 754, in put_vector
    gmt_type = self._check_dtype_and_dim(vector, ndim=1)
  File "/Users/seisman/Gits/gmt/gmt-python/gmt/clib/session.py", line 703, in _check_dtype_and_dim
    "Unsupported numpy data type '{}'.".format(array.dtype.name)
gmt.exceptions.GMTInvalidInput: Unsupported numpy data type 'str320'.

System information

  • Operating system: macOS 10.14
  • Python installation (Anaconda, system, ETS): Anaconda
  • Version of GMT: 6.0.0_15a9160
  • Version of Python: 3.7.0
  • Version of this package: latest
  • If using conda, paste the output of conda list below:
output of conda list
# packages in environment at /Users/seisman/.anaconda:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0                    py37_0
alabaster                 0.7.11                   py37_0
anaconda                  5.3.0                    py37_0
anaconda-client           1.7.2                    py37_0
anaconda-navigator        1.9.2                    py37_0
anaconda-project          0.8.2                    py37_0
appdirs                   1.4.3            py37h28b3542_0
appnope                   0.1.0                    py37_0
appscript                 1.0.1            py37h1de35cc_1
argh                      0.26.2                    <pip>
asn1crypto                0.24.0                   py37_0
astroid                   2.0.4                    py37_0
astropy                   3.0.4            py37h1de35cc_0
atomicwrites              1.2.1                    py37_0
attrs                     18.2.0           py37h28b3542_0
automat                   0.7.0                    py37_0
babel                     2.6.0                    py37_0
backcall                  0.1.0                    py37_0
backports                 1.0                      py37_1
backports.shutil_get_terminal_size 1.0.0                    py37_2
basemap                   1.2.0            py37h0acbc05_0
beautifulsoup4            4.6.3                    py37_0
bitarray                  0.8.3            py37h1de35cc_0
bkcharts                  0.2                      py37_0
black                     18.9b0                    <pip>
blas                      1.0                         mkl
blaze                     0.11.3                   py37_0
bleach                    2.1.4                    py37_0
blosc                     1.14.4               hd9629dc_0
bokeh                     0.13.0                   py37_0
boto                      2.49.0                   py37_0
bottleneck                1.2.1            py37h1d22016_1
bzip2                     1.0.6                h1de35cc_5
ca-certificates           2018.03.07                    0
cartopy                   0.16.0           py37h9263bd1_0
certifi                   2018.8.24                py37_1
cffi                      1.11.5           py37h6174b99_1
cftime                    1.0.0b1          py37h1d22016_0
chardet                   3.0.4                    py37_1
click                     6.7                      py37_0
cloud-sptheme             1.9.4                     <pip>
cloudpickle               0.5.5                    py37_0
clyent                    1.2.2                    py37_1
cmarkgfm                  0.4.2                     <pip>
colorama                  0.3.9                    py37_0
conda                     4.5.11                py37_1000    conda-forge
conda-build               3.15.1                   py37_0
conda-env                 2.6.0                         1
constantly                15.1.0           py37h28b3542_0
contextlib2               0.5.5                    py37_0
cryptography              2.3.1            py37hdbc3d79_0
curl                      7.61.0               ha441bb4_0
cycler                    0.10.0                   py37_0
cython                    0.28.5           py37h0a44026_0
cytoolz                   0.9.0.1          py37h1de35cc_1
dask                      0.19.1                   py37_0
dask-core                 0.19.1                   py37_0
datashape                 0.5.4                    py37_1
dbus                      1.13.2               h760590f_1
decorator                 4.3.0                    py37_0
defusedxml                0.5.0                    py37_1
distributed               1.23.1                   py37_0
docutils                  0.14                     py37_0
entrypoints               0.2.3                    py37_2
et_xmlfile                1.0.1                    py37_0
expat                     2.2.6                h0a44026_0
fastcache                 1.0.2            py37h1de35cc_2
filelock                  3.0.8                    py37_0
flask                     1.0.2                    py37_1
flask-cors                3.0.6                    py37_0
freetype                  2.9.1                hb4e5f40_0
future                    0.16.0                    <pip>
future                    0.17.0                py37_1000    conda-forge
geographiclib             1.49                      <pip>
geos                      3.6.2                h5470d99_2
get_terminal_size         1.0.0                h7520d66_0
gettext                   0.19.8.1             h15daf44_3
gevent                    1.3.6            py37h1de35cc_0
glib                      2.56.2               hd9629dc_0
glob2                     0.6                      py37_0
gmp                       6.1.2                hb37e062_1
gmpy2                     2.0.8            py37h6ef4df4_2
gmt-python                0.1a3+126.g4617492.dirty           <pip>
greenlet                  0.4.15           py37h1de35cc_0
guzzle-sphinx-theme       0.7.11                    <pip>
h5py                      2.8.0            py37h878fce3_3
hdf4                      4.2.13               h39711bb_2
hdf5                      1.10.2               hfa1e0ec_1
heapdict                  1.0.0                    py37_2
html5lib                  1.0.1                    py37_0
hyperlink                 18.0.0                   py37_0
icu                       58.2                 h4b95b61_1
idna                      2.7                      py37_0
imageio                   2.4.1                    py37_0
imagesize                 1.1.0                    py37_0
incremental               17.5.0                   py37_0
intel-openmp              2019.0                      118
ipykernel                 4.9.0                    py37_1
ipython                   6.5.0                    py37_0
ipython_genutils          0.2.0                    py37_0
ipywidgets                7.4.1                    py37_0
isort                     4.3.4                    py37_0
itsdangerous              0.24                     py37_1
jbig                      2.1                  h4d881f8_0
jdcal                     1.4                      py37_0
jedi                      0.12.1                   py37_0
jinja2                    2.10                     py37_0
jpeg                      9b                   he5867d9_2
jsonschema                2.6.0                    py37_0
jupyter                   1.0.0                    py37_7
jupyter_client            5.2.3                    py37_0
jupyter_console           5.2.0                    py37_1
jupyter_core              4.4.0                    py37_0
jupyterlab                0.34.9                   py37_0
jupyterlab_launcher       0.13.1                   py37_0
keyring                   13.2.1                   py37_0
kiwisolver                1.0.1            py37h0a44026_0
lazy-object-proxy         1.3.1            py37h1de35cc_2
libcurl                   7.61.0               hf30b1f0_0
libcxx                    4.0.1                h579ed51_0
libcxxabi                 4.0.1                hebd6815_0
libedit                   3.1.20170329         hb402a30_2
libffi                    3.2.1                h475c297_4
libgfortran               3.0.1                h93005f0_2
libiconv                  1.15                 hdd342a3_7
libnetcdf                 4.6.1                h4e6abe9_1
libpng                    1.6.34               he12f830_0
libsodium                 1.0.16               h3efe00b_0
libssh2                   1.8.0                h322a93b_4
libtiff                   4.0.9                hcb84e12_2
libxml2                   2.9.8                hab757c2_1
libxslt                   1.1.32               hb819dd2_0
livereload                2.5.2                     <pip>
llvmlite                  0.24.0           py37hc454e04_0
locket                    0.2.0                    py37_1
lxml                      4.2.5            py37hef8c89e_0
lzo                       2.10                 h362108e_2
markupsafe                1.0              py37h1de35cc_1
matplotlib                2.2.3            py37h54f8f79_0
mccabe                    0.6.1                    py37_1
mistune                   0.8.3            py37h1de35cc_1
mkl                       2019.0                      118
mkl-service               1.1.2            py37h6b9c3cc_5
mkl_fft                   1.0.4            py37h5d10147_1
mkl_random                1.0.1            py37h5d10147_1
more-itertools            4.3.0                    py37_0
mpc                       1.1.0                h6ef4df4_1
mpfr                      4.0.1                h3018a27_3
mpmath                    1.0.0                    py37_2
msgpack-python            0.5.6            py37h04f5b5a_1
multipledispatch          0.6.0                    py37_0
navigator-updater         0.2.1                    py37_0
nbconvert                 5.4.0                    py37_1
nbformat                  4.4.0                    py37_0
ncurses                   6.1                  h0a44026_0
netcdf4                   1.4.1            py37h08833f9_0
networkx                  2.1                      py37_0
nltk                      3.3.0                    py37_0
nose                      1.3.7                    py37_2
notebook                  5.6.0                    py37_0
numba                     0.39.0           py37h6440ff4_0
numexpr                   2.6.8            py37h1dc9127_0
numpy                     1.15.1           py37h6a91979_0
numpy-base                1.15.1           py37h8a80b8c_0
numpydoc                  0.8.0                    py37_0
obspy                     1.1.0            py37h39e3cac_2    conda-forge
obspy                     1.1.0                     <pip>
odo                       0.5.1                    py37_0
olefile                   0.46                     py37_0
openpyxl                  2.5.6                    py37_0
openssl                   1.0.2p               h1de35cc_0
owslib                    0.17.0                   py37_0
packaging                 17.1                     py37_0
pandas                    0.23.4           py37h6440ff4_0
pandoc                    1.19.2.1             ha5e8f32_1
pandocfilters             1.4.2                    py37_1
parso                     0.3.1                    py37_0
partd                     0.3.8                    py37_0
path.py                   11.1.0                   py37_0
pathlib2                  2.3.2                    py37_0
pathtools                 0.1.2                     <pip>
patsy                     0.5.0                    py37_0
pcre                      8.42                 h378b8a2_0
pep8                      1.7.1                    py37_0
pexpect                   4.6.0                    py37_0
pickleshare               0.7.4                    py37_0
pillow                    5.2.0            py37hb68e598_0
pip                       10.0.1                   py37_0
pkginfo                   1.4.2                    py37_1
pluggy                    0.7.1            py37h28b3542_0
ply                       3.11                     py37_0
port-for                  0.3.1                     <pip>
proj4                     5.0.1                h1de35cc_0
prometheus_client         0.3.1            py37h28b3542_0
prompt_toolkit            1.0.15                   py37_0
psutil                    5.4.7            py37h1de35cc_0
ptyprocess                0.6.0                    py37_0
py                        1.6.0                    py37_0
pyasn1                    0.4.4            py37h28b3542_0
pyasn1-modules            0.2.2                    py37_0
pycodestyle               2.4.0                    py37_0
pycosat                   0.6.3            py37h1de35cc_0
pycparser                 2.18                     py37_1
pycrypto                  2.6.1            py37h1de35cc_9
pycurl                    7.43.0.2         py37hdbc3d79_0
pyepsg                    0.3.2                    py37_0
pyflakes                  2.0.0                    py37_0
pygments                  2.2.0                    py37_0
pylint                    2.1.1                    py37_0
pyodbc                    4.0.24           py37h0a44026_0
pyopenssl                 18.0.0                   py37_0
pyparsing                 2.2.0                    py37_1
pyproj                    1.9.5.1          py37h833a5d7_1
pyqt                      5.9.2            py37h655552a_2
pyshp                     1.2.12                   py37_0
pysocks                   1.6.8                    py37_0
pytables                  3.4.4            py37h13cba08_0
pytest                    3.8.0                    py37_0
pytest-arraydiff          0.2              py37h39e3cac_0
pytest-astropy            0.4.0                    py37_0
pytest-doctestplus        0.1.3                    py37_0
pytest-mpl                0.10                      <pip>
pytest-openfiles          0.3.0                    py37_0
pytest-remotedata         0.3.0                    py37_0
python                    3.7.0                hc167b69_0
python-dateutil           2.7.3                    py37_0
python.app                2                        py37_8
pytz                      2018.5                   py37_0
pywavelets                1.0.0            py37h1d22016_0
pyyaml                    3.13             py37h1de35cc_0
pyzmq                     17.1.2           py37h1de35cc_0
qt                        5.9.6                h45cd832_2
qtawesome                 0.4.4                    py37_0
qtconsole                 4.4.1                    py37_0
qtpy                      1.5.0                    py37_0
readline                  7.0                  h1de35cc_5
readme-renderer           22.0                      <pip>
requests                  2.19.1                   py37_0
requests-toolbelt         0.8.0                     <pip>
rope                      0.11.0                   py37_0
ruamel_yaml               0.15.46          py37h1de35cc_0
scikit-image              0.14.0           py37h0a44026_1
scikit-learn              0.19.2           py37h4f467ca_0
scipy                     1.1.0            py37h28f7352_1
seaborn                   0.9.0                    py37_0
send2trash                1.5.0                    py37_0
service_identity          17.0.0           py37h28b3542_0
setuptools                40.2.0                   py37_0
shapely                   1.6.4            py37h20de77a_0
simplegeneric             0.8.1                    py37_2
singledispatch            3.4.0.3                  py37_0
sip                       4.19.8           py37h0a44026_0
six                       1.11.0                   py37_1
snappy                    1.1.7                he62c110_3
snowballstemmer           1.2.1                    py37_0
sortedcollections         1.0.1                    py37_0
sortedcontainers          2.0.5                    py37_0
sphinx                    1.7.9                    py37_0
Sphinx                    1.8.1                     <pip>
sphinx-autobuild          0.7.1                     <pip>
sphinx-cjkspace           0.1.2                     <pip>
sphinx-intl               0.9.11                    <pip>
sphinx-rtd-theme          0.4.1                     <pip>
sphinxcontrib             1.0                      py37_1
sphinxcontrib-websupport  1.1.0                    py37_1
spyder                    3.3.1                    py37_1
spyder-kernels            0.2.6                    py37_0
sqlalchemy                1.2.11           py37h1de35cc_0
sqlite                    3.24.0               ha441bb4_0
statsmodels               0.9.0            py37h1d22016_0
sympy                     1.2                      py37_0
tblib                     1.3.2                    py37_0
terminado                 0.8.1                    py37_1
testpath                  0.3.1                    py37_0
tk                        8.6.8                ha441bb4_0
toml                      0.10.0                    <pip>
toolz                     0.9.0                    py37_0
tornado                   5.1              py37h1de35cc_0
tqdm                      4.26.0           py37h28b3542_0
traitlets                 4.3.2                    py37_0
twine                     1.12.1                    <pip>
twisted                   18.7.0           py37h1de35cc_1
unicodecsv                0.14.1                   py37_0
unixodbc                  2.3.7                h1de35cc_0
urllib3                   1.23                     py37_0
watchdog                  0.9.0                     <pip>
wcwidth                   0.1.7                    py37_0
webencodings              0.5.1                    py37_1
werkzeug                  0.14.1                   py37_0
wheel                     0.31.1                   py37_0
widgetsnbextension        3.4.1                    py37_0
wrapt                     1.10.11          py37h1de35cc_2
xarray                    0.10.8                   py37_0
xlrd                      1.1.0                    py37_1
xlsxwriter                1.1.0                    py37_0
xlwings                   0.11.8                   py37_0
xlwt                      1.3.0                    py37_0
xz                        5.2.4                h1de35cc_4
yaml                      0.1.7                hc338f04_2
zeromq                    4.2.5                h0a44026_1
zhon                      1.1.5                     <pip>
zict                      0.1.3                    py37_0
zlib                      1.2.11               hf3cbc9b_2
zope                      1.0                      py37_1
zope.interface            4.5.0            py37h1de35cc_0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:22 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
seismancommented, May 30, 2020

Any datetime types (raw strings, datetime, np.datetim64 and pandas.DatetimeIndex) are converted to strings (char ** in C) before passing to the GMT API. NaT is converted to the string NaT. GMT can’t handle NaT, so it just gives an error and skips the NaT data points. (Perhaps it should be a warning instead of an error).

pygmt-session [ERROR]: Unable to parse 1 datetime strings (ISO datetime format required)
0reactions
weiji14commented, May 30, 2020

NaT is basically like NaN, but for time. To be honest, I’m not sure why they don’t just use NaN, but yeah, it exists…

NaT is converted to the string NaT. GMT can’t handle NaT, so it just gives an error and skips the NaT data points. (Perhaps it should be a warning instead of an error).

pygmt-session [ERROR]: Unable to parse 1 datetime strings (ISO datetime format required)

Yeah, a warning might be better here. Not sure if there is an ISO datetime for NaT.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date and time input types | Can I use... Support ... - CanIUse
Date and time input types. - LS. Form field widgets to easily allow users to enter a date, time or both, generally by...
Read more >
<input type="date"> - HTML: HyperText Markup Language
Date inputs provide an easy interface for choosing dates, and they normalize the data format sent to the server regardless of the user's...
Read more >
4 Datetime Data Types and Time Zone Support
The datetime data types are DATE , TIMESTAMP , TIMESTAMP WITH TIME ZONE, and TIMESTAMP WITH LOCAL TIME ZONE . Values of datetime...
Read more >
Date & Time Data Types - Snowflake Documentation
This topic describes the data types supported in Snowflake for managing dates, times, and timestamps (combined date + time). It also describes the...
Read more >
Date and Time Data Types
Date /time data values have the following data type input formats: • Ansidate ... Note: The ingresdate type is not supported in X100...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found