Open
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
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_LONG
in Support 1-D/2-D numpy arrays with longlong and ulonglong dtype #3566 -
numpy.ulonglong
:GMT_ULONG
in 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_LONG
Support 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.