59
59
np .uint64 : "GMT_ULONG" ,
60
60
np .uint32 : "GMT_UINT" ,
61
61
np .datetime64 : "GMT_DATETIME" ,
62
+ np .str_ : "GMT_TEXT" ,
62
63
}
63
64
64
65
@@ -718,9 +719,7 @@ def _check_dtype_and_dim(self, array, ndim):
718
719
"""
719
720
# check the array has the given dimension
720
721
if array .ndim != ndim :
721
- raise GMTInvalidInput (
722
- "Expected a numpy 1d array, got {}d." .format (array .ndim )
723
- )
722
+ raise GMTInvalidInput (f"Expected a numpy 1d array, got { array .ndim } d." )
724
723
725
724
# check the array has a valid/known data type
726
725
if array .dtype .type not in DTYPES :
@@ -744,7 +743,7 @@ def put_vector(self, dataset, column, vector):
744
743
first. Use ``family='GMT_IS_DATASET|GMT_VIA_VECTOR'``.
745
744
746
745
Not at all numpy dtypes are supported, only: float64, float32, int64,
747
- int32, uint64, and uint32 .
746
+ int32, uint64, uint32, datetime64 and str_ .
748
747
749
748
.. warning::
750
749
The numpy array must be C contiguous in memory. If it comes from a
@@ -776,23 +775,24 @@ def put_vector(self, dataset, column, vector):
776
775
)
777
776
778
777
gmt_type = self ._check_dtype_and_dim (vector , ndim = 1 )
779
- if gmt_type == self ["GMT_DATETIME" ]:
778
+ if gmt_type in ( self ["GMT_TEXT" ], self [ " GMT_DATETIME" ]) :
780
779
vector_pointer = (ctp .c_char_p * len (vector ))()
781
- vector_pointer [:] = np .char .encode (
782
- np .datetime_as_string (array_to_datetime (vector ))
783
- )
780
+ if gmt_type == self ["GMT_DATETIME" ]:
781
+ vector_pointer [:] = np .char .encode (
782
+ np .datetime_as_string (array_to_datetime (vector ))
783
+ )
784
+ else :
785
+ vector_pointer [:] = np .char .encode (vector )
784
786
else :
785
787
vector_pointer = vector .ctypes .data_as (ctp .c_void_p )
786
788
status = c_put_vector (
787
789
self .session_pointer , dataset , column , gmt_type , vector_pointer
788
790
)
789
791
if status != 0 :
790
792
raise GMTCLibError (
791
- " " .join (
792
- [
793
- "Failed to put vector of type {}" .format (vector .dtype ),
794
- "in column {} of dataset." .format (column ),
795
- ]
793
+ (
794
+ f"Failed to put vector of type { vector .dtype } "
795
+ f"in column { column } of dataset."
796
796
)
797
797
)
798
798
0 commit comments