diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index 6e5a62b69d8..bb8e294351b 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -834,8 +834,11 @@ def _check_dtype_and_dim(self, array, ndim): # Check that the array has a valid/known data type if array.dtype.type not in DTYPES: try: - # Try to convert any unknown numpy data types to np.datetime64 - array = array_to_datetime(array) + if array.dtype.type is np.object_: + # Try to convert unknown object type to np.datetime64 + array = array_to_datetime(array) + else: + raise ValueError except ValueError as e: raise GMTInvalidInput( f"Unsupported numpy data type '{array.dtype.type}'." diff --git a/pygmt/tests/test_clib_put_vector.py b/pygmt/tests/test_clib_put_vector.py index e9da9e6242a..09a4235298b 100644 --- a/pygmt/tests/test_clib_put_vector.py +++ b/pygmt/tests/test_clib_put_vector.py @@ -170,16 +170,26 @@ def test_put_vector_invalid_dtype(): """ Check that it fails with an exception for invalid data types. """ - with clib.Session() as lib: - dataset = lib.create_data( - family="GMT_IS_DATASET|GMT_VIA_VECTOR", - geometry="GMT_IS_POINT", - mode="GMT_CONTAINER_ONLY", - dim=[2, 3, 1, 0], # columns, rows, layers, dtype - ) - data = np.array([37, 12, 556], dtype="object") - with pytest.raises(GMTInvalidInput): - lib.put_vector(dataset, column=1, vector=data) + for dtype in [ + np.bool_, + np.bytes_, + np.csingle, + np.cdouble, + np.clongfloat, + np.half, + np.longdouble, + np.object_, + ]: + with clib.Session() as lib: + dataset = lib.create_data( + family="GMT_IS_DATASET|GMT_VIA_VECTOR", + geometry="GMT_IS_POINT", + mode="GMT_CONTAINER_ONLY", + dim=[2, 3, 1, 0], # columns, rows, layers, dtype + ) + data = np.array([37, 12, 556], dtype=dtype) + with pytest.raises(GMTInvalidInput, match="Unsupported numpy data type"): + lib.put_vector(dataset, column=1, vector=data) def test_put_vector_wrong_column():