Skip to content

Full support of numpy dtypes #2848

Open
@seisman

Description

@seisman

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:

# 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())

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 into np.float32?
  • For np.bool_: maybe convert to 0 and 1 (e.g., array.astype("int8")
  • For np.timedelta: Not sure about this yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions