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

Improve the error messages for unsupported numpy dtypes #2856

Merged
merged 4 commits into from
Dec 7, 2023

Conversation

seisman
Copy link
Member

@seisman seisman commented Dec 6, 2023

Description of proposed changes
Address #2848 (comment).

The current issue is, the error message is helpless and very confusing, so users don't know that np.float16 is not supported:

With this branch, now the error message is more clear:

>>> import numpy as np
>>> import pygmt
>>> x = np.array([1, 2, 3, 4], dtype=np.float16)
>>> pygmt.info(x)
...
File ~/OSS/gmt/pygmt/pygmt/clib/session.py:843, in Session._check_dtype_and_dim(self, array, ndim)
    841             raise ValueError
    842     except ValueError as e:
--> 843         raise GMTInvalidInput(
    844             f"Unsupported numpy data type '{array.dtype.type}'."
    845         ) from e
    846 return self[DTYPES[array.dtype.type]]

GMTInvalidInput: Unsupported numpy data type '<class 'numpy.float16'>'.

The test test_put_vector_invalid_dtype is also updated to test passing arrays with invalid dtypes.

Support for np.float16, np.bool_ as requested in #2848 will be addressed in separate PRs.

@seisman seisman added enhancement Improving an existing feature skip-changelog Skip adding Pull Request to changelog labels Dec 6, 2023
@seisman seisman added this to the 0.11.0 milestone Dec 6, 2023
@seisman seisman added needs review This PR has higher priority and needs review. and removed skip-changelog Skip adding Pull Request to changelog labels Dec 6, 2023
@seisman seisman mentioned this pull request Dec 7, 2023
24 tasks
@seisman seisman removed the needs review This PR has higher priority and needs review. label Dec 7, 2023
@seisman seisman merged commit f7b2f4c into main Dec 7, 2023
@seisman seisman deleted the numpy-invalid-dtypes branch December 7, 2023 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improving an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants