Supported Array Dtypes
PyGMT uses NumPy arrays as its core data structure for storing data and exchanging data with the GMT C API. This design allows PyGMT to support a wide range of array-like objects and data types (dtypes), as long as they can be converted to NumPy arrays. This page provides a comprehensive overview of the array dtypes supported by PyGMT.
Numeric Dtypes
In addition to Python’s built-in numeric types (int and float), PyGMT
supports most of the numeric dtypes provided by NumPy, pandas, and PyArrow.
Signed Integers
numpy.int8,numpy.int16,numpy.int32,numpy.int64,numpy.longlongpandas.Int8Dtype,pandas.Int16Dtype,pandas.Int32Dtype,pandas.Int64Dtype
Unsigned Integers
numpy.uint8,numpy.uint16,numpy.uint32,numpy.uint64,numpy.ulonglongpandas.UInt8Dtype,pandas.UInt16Dtype,pandas.UInt32Dtype,pandas.UInt64Dtypepyarrow.uint8,pyarrow.uint16,pyarrow.uint32,pyarrow.uint64
Floating-point numbers
numpy.float32,numpy.float64
Note
Signed and unsigned integer dtypes from pandas and PyArrow (e.g.,
pandas.Int8Dtype,pyarrow.int8) support missing values likeNoneorpandas.NA, whereas NumPy’s corresponding dtypes (e.g.,numpy.int8) don’t. Arrays of these dtypes containing missing values are automatically cast tonumpy.float64internally.For 3-D
xarray.DataArrayobjects representing raster images, only 8-bit unsigned integers (i.e.,numpy.uint8) are supported.
Note
Examples of numeric arrays supported by PyGMT:
# A list of integers
[1, 2, 3]
# A NumPy array with dtype int32
np.array([1, 2, 3], dtype=np.int32)
# A pandas Series with nullable Int32 dtype
pd.Series([1, 2, 3], dtype="Int32")
# A pandas Series with nullable Int32 dtype and missing values
pd.Series([1, 2, pd.NA], dtype="Int32")
# A pandas Series using a PyArrow-backed float64 dtype
pd.Series([1, 2, 3], dtype="float64[pyarrow]")
# A PyArrow array with dtype uint8
pa.array([1, 2, 3], type=pa.uint8())
String Dtypes
In addition to Python’s built-in str type, PyGMT also supports the following
string dtypes:
NumPy:
numpy.str_or fixed-width Unicode string dtype (e.g.,"U10")pandas:
pandas.StringDtype, with different storage backends, includingstring[python]andstring[pyarrow]PyArrow:
pyarrow.string/pyarrow.utf8,pyarrow.large_string/pyarrow.large_utf8, andpyarrow.string_view
Note
Examples of string arrays supported by PyGMT:
# A list of strings
["a", "b", "c"]
# A NumPy string array
np.array(["a", "b", "c"])
np.array(["a", "b", "c"], dtype=np.str_)
# A pandas.Series string array
pd.Series(["a", "b", "c"], dtype="string")
pd.Series(["a", "b", "c"], dtype="string[python]")
pd.Series(["a", "b", "c"], dtype="string[pyarrow]")
# A PyArrow array with pyarrow.string dtype
pa.array(["a", "b", "c"], type=pa.string())
Datetime Dtypes
PyGMT supports a variety of datetime types:
A list/tuple of elements in Python’s built-in
datetime.datetimeordatetime.date, NumPy’snumpy.datetime64, pandas’pandas.Timestamptypes, datetime-like strings, or mixed.NumPy arrays:
numpy.datetime64with various resolutionspandas objects with
numpy.datetime64,pandas.DatetimeTZDtype,pyarrow.timestampwith various resolution and timezone support, and pyarrow-backend dtypes likedate32[day][pyarrow]anddate64[ms][pyarrow],PyArrow:
pyarrow.date32,pyarrow.date64andpyarrow.timestampwith various resolutions and timezone support.
Timedelta Dtypes
PyGMT supports NumPy arrays with the numpy.timedelta64 dtype. Timedelta values are
passed to GMT as their underlying integer values, so their unit determines the numeric
scale. For example, a timedelta64[D] array is interpreted as days, whereas a
timedelta64[s] array is interpreted as seconds.
Timedelta values can also be used in sequence-valued parameters such as region.
The timedelta dtype does not, by itself, configure a GMT relative-time axis; configure
GMT time settings explicitly when a relative-time axis is required.
Unsupported Dtypes
The following dtypes are intentionally unsupported, and should be cast to an appropriate supported dtype before passing to PyGMT:
Floating-point dtypes:
numpy.float16,pyarrow.float16,numpy.longdoubleBoolean dtypes:
numpy.bool_,pandas.BooleanDtype,pyarrow.bool_Complex dtypes:
numpy.complex64,numpy.complex128numpy.bytes_andnumpy.void
The numpy.object_ dtype is also not supported. PyGMT may convert object arrays
that can be interpreted as datetimes or text, but applications should create arrays with
an explicit supported dtype instead.