Skip to content
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

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

Merged
merged 3 commits into from
Mar 3, 2021

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Feb 24, 2021

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:

import pandas as pd
import pygmt

table = 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.
@weiji14 weiji14 added the bug Something isn't working label Feb 24, 2021
@weiji14 weiji14 added this to the 0.3.1 milestone Feb 24, 2021
pygmt/tests/test_info.py Outdated Show resolved Hide resolved
pygmt/tests/test_info.py Outdated Show resolved Hide resolved
@weiji14 weiji14 mentioned this pull request Mar 3, 2021
23 tasks
@weiji14 weiji14 marked this pull request as ready for review March 3, 2021 21:19
@weiji14
Copy link
Member Author

weiji14 commented Mar 3, 2021

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
Copy link
Member

seisman commented Mar 3, 2021

/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
Copy link
Member Author

weiji14 commented Mar 3, 2021

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 master Mar 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants