-
Notifications
You must be signed in to change notification settings - Fork 234
Open
Labels
feature requestNew feature wantedNew feature wanted
Description
Before starting to support PyArrow arrays (#2800), I think we should first ensure that PyGMT has complete support for NumPy dtypes. Currently, the following NumPy dtypes are supported:
Lines 85 to 102 in e5ecee9
| # Dictionary for mapping numpy dtypes to GMT data types. | |
| DTYPES_NUMERIC = { | |
| np.int8: "GMT_CHAR", | |
| np.int16: "GMT_SHORT", | |
| np.int32: "GMT_INT", | |
| np.int64: "GMT_LONG", | |
| np.uint8: "GMT_UCHAR", | |
| np.uint16: "GMT_USHORT", | |
| np.uint32: "GMT_UINT", | |
| np.uint64: "GMT_ULONG", | |
| np.float32: "GMT_FLOAT", | |
| np.float64: "GMT_DOUBLE", | |
| np.timedelta64: "GMT_LONG", | |
| } | |
| DTYPES_TEXT = { | |
| np.str_: "GMT_TEXT", | |
| np.datetime64: "GMT_DATETIME", | |
| } |
Here is a simple way to list all the available NumPy dtypes (xref: https://numpy.org/doc/stable/reference/arrays.scalars.html):
>>> import numpy as np
>>> set(np.sctypeDict.values())-
numpy.int8:GMT_CHAR -
numpy.int16:GMT_SHORT -
numpy.int32:GMT_INT -
numpy.int64:GMT_LONG -
numpy.uint8:GMT_UCHAR -
numpy.uint16:GMT_USHORT -
numpy.uint32:GMT_UINT -
numpy.uint64:GMT_ULONG -
numpy.float16 -
numpy.float32:GMT_FLOAT -
numpy.float64:GMT_DOUBLE -
numpy.longlong:GMT_LONGin Support 1-D/2-D numpy arrays with longlong and ulonglong dtype #3566 -
numpy.ulonglong:GMT_ULONGin Support 1-D/2-D numpy arrays with longlong and ulonglong dtype #3566 -
numpy.longdouble: alias for np.float96 or np.float128 (xref: https://numpy.org/devdocs/reference/arrays.scalars.html#numpy.longdouble) -
: GMT doesn't support complex floating point data types.numpy.complex64 -
: GMT doesn't support complex floating point data types.numpy.complex128 -
: GMT doesn't support complex floating point data types.numpy.clongdouble -
numpy.bool -
: For bytestring. Makes no sense in GMT.numpy.bytes_ -
numpy.str_:GMT_TEXT -
numpy.datetime64:GMT_DATETIME. But still need to check all time units (https://numpy.org/doc/stable/reference/arrays.datetime.html#datetime-units) -
numpy.timedelta64:GMT_LONGSupport timedelta64 dtype as input #2884 -
numpy.object_: Any Python objects. We should try to convert it to np.datetime64 or np.str_. -
: For creating a new structured or unstructured void scalar. Make no sense in GMT.numpy.void
As you can see, most NumPy types are already supported in PyGMT. It's clear that GMT and PyGMT can't support float128 and any complex floating-point types, but at least it's possible to support np.float16 (np.half), np.bool_ and np.timedelta.
- For
np.float16: maybe we have to cast the array intonp.float32? - For
np.bool_: maybe convert to 0 and 1 (e.g.,array.astype("int8") - For
np.timedelta: Not sure about this yet.
weiji14
Metadata
Metadata
Assignees
Labels
feature requestNew feature wantedNew feature wanted