Skip to content

Let pygmt.info load datetime columns into a str dtype array - #960

Merged
weiji14 merged 3 commits into
masterfrom
info_load_datetime_as_str
Mar 3, 2021
Merged

Let pygmt.info load datetime columns into a str dtype array#960
weiji14 merged 3 commits into
masterfrom
info_load_datetime_as_str

Conversation

@weiji14

@weiji14weiji14 commented Feb 24, 2021

Copy link
Copy Markdown
Member

Description of proposed changes

Fixes problem with pygmt.info not being able to handle datetime64 inputs. I.e. ValueError: could not convert string to float: '2021-01-01T12:34:56'.

However, users will still need to usepygmt.info(..., f="0T") until upstream issue at GenericMappingTools/gmt#4241 is resolved. Something like so:

importpandasaspdimportpygmttable=pd.date_range(start="2020-01-01", periods=5).to_numpy()
output=pygmt.info(table=table, per_column=True, f="0T")
print(output)
# ['2020-01-01T00:00:00' '2020-01-05T00:00:00']

Also added two extra unit tests using numpy datetime64 types.

References:

Addresses #597 on the pygmt side using fix mentioned in #597 (comment). Assuming that GenericMappingTools/gmt#4241 is fixed in GMT 6.2.0, then issue #597 can be closed once PyGMT bumps minimum required GMT version to 6.2.0.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

Fixes problem with pygmt.info not being able to handle datetime64 inputs.
I.e. `ValueError: could not convert string to float: '2021-01-01T12:34:56'`
However, users will still need to use`pygmt.info(..., f="0T")` until
upstream issue at GenericMappingTools/gmt#4241
is resolved. Also added two extra unit tests using numpy datetime64 types.
@weiji14weiji14 added the bug Something isn't working label Feb 24, 2021
@weiji14weiji14 added this to the 0.3.1 milestone Feb 24, 2021
Comment threadpygmt/tests/test_info.py Outdated
Comment threadpygmt/tests/test_info.py Outdated
Comment threadpygmt/src/info.py
@weiji14
weiji14 marked this pull request as ready for review March 3, 2021 21:19
@weiji14

Copy link
Copy Markdown
MemberAuthor

Hmm, that crash on the Windows GMT dev test at https://github.com/GenericMappingTools/pygmt/runs/2025836161?check_suite_focus=true#step:15:86 at the start (before any tests got run) doesn't look nice.

@seisman

seisman commented Mar 3, 2021

Copy link
Copy Markdown
Member

/test-gmt-dev

Hmm, that crash on the Windows GMT dev test at GenericMappingTools/pygmt/runs/2025836161?check_suite_focus=true#step:15:86 at the start (before any tests got run) doesn't look nice.

It may be just a sporadic crash. Just re-triggered the dev tests.

Edit: Jobs at https://github.com/GenericMappingTools/pygmt/actions/runs/619017413

@weiji14

weiji14 commented Mar 3, 2021

Copy link
Copy Markdown
MemberAuthor

Thanks! Windows tests have passed at https://github.com/GenericMappingTools/pygmt/runs/2026019634?check_suite_focus=true#step:15:867. Any other comment on this PR?

@weiji14
weiji14 merged commit 52dbd7a into masterMar 3, 2021
@weiji14
weiji14 deleted the info_load_datetime_as_str branch March 3, 2021 22:17
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
…appingTools#960)
Fixes problem with pygmt.info not being able to handle datetime64 inputs.
I.e. `ValueError: could not convert string to float: '2021-01-01T12:34:56'`
However, users will still need to use`pygmt.info(..., coltypes="0T")` until
upstream issue at GenericMappingTools/gmt#4241
is resolved. Also added two extra unit tests using numpy datetime64 types.
* Use common alias coltypes (f) in tests and make a note on the workaround
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugSomething isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@weiji14@seisman