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

Support 1-D/2-D numpy arrays with longlong and ulonglong dtype #3566

Merged
merged 8 commits into from
Nov 5, 2024

Conversation

seisman
Copy link
Member

@seisman seisman commented Oct 31, 2024

See #2848 (comment) for context. np.longlong and np.ulonglong are valid numpy dtypes and are almost the same as np.int64/np.uint64 (xref: https://numpy.org/devdocs/reference/arrays.scalars.html#numpy.int64), although there are technical differences (xref: numpy/numpy#12264).

As shown below, a np.longlong array is shown with the int64 dtype, but x.dtype.type is still np.longlong, which means it can't be recognized by _check_dtype_and_dim.

In [1]: import numpy as np

In [2]: x = np.array([1, 2, 3], dtype=np.longlong)

In [3]: x.dtype
Out[3]: dtype('int64')

In [4]: x.dtype.type
Out[4]: numpy.longlong

In [5]: from pygmt.clib import Session

In [6]: with Session() as lib:
   ...:     lib._check_dtype_and_dim(x, ndim=1)
   ...:
---------------------------------------------------------------------------
GMTInvalidInput                           Traceback (most recent call last)
Cell In[6], line 2
      1 with Session() as lib:
----> 2     lib._check_dtype_and_dim(x, ndim=1)

File ~/OSS/gmt/pygmt/pygmt/clib/session.py:938, in Session._check_dtype_and_dim(self, array, ndim)
    936 if (dtype := array.dtype.type) not in valid_dtypes:
    937     msg = f"Unsupported numpy data type '{dtype}'."
--> 938     raise GMTInvalidInput(msg)
    939 return self[DTYPES[dtype]]

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

This PR adds support for np.longlong and np.ulonglong by mapping them to GMT_LONG and GMT_ULONG respectively.

Need to wait for #3565 first so that the newly supported dtypes are tested.

These newly supported dtypes are automatically tested after #3565.

@seisman seisman mentioned this pull request Oct 31, 2024
24 tasks
@seisman seisman added the enhancement Improving an existing feature label Oct 31, 2024
@seisman seisman added this to the 0.14.0 milestone Oct 31, 2024
@seisman seisman added the needs review This PR has higher priority and needs review. label Oct 31, 2024
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Nov 4, 2024
@seisman seisman merged commit f91475d into main Nov 5, 2024
20 of 21 checks passed
@seisman seisman deleted the numpy/longlong branch November 5, 2024 03:16
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Nov 5, 2024
seisman added a commit that referenced this pull request Nov 18, 2024
seisman added a commit that referenced this pull request Nov 18, 2024
seisman added a commit that referenced this pull request Nov 18, 2024
seisman added a commit that referenced this pull request Nov 18, 2024
seisman added a commit that referenced this pull request Nov 18, 2024
seisman added a commit that referenced this pull request Nov 18, 2024
seisman added a commit that referenced this pull request Nov 19, 2024
seisman added a commit that referenced this pull request Nov 20, 2024
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