@@ -1790,10 +1790,7 @@ def virtualfile_in( # noqa: PLR0912
17901790 "grid" : self .virtualfile_from_grid ,
17911791 "image" : tempfile_from_image ,
17921792 "stringio" : self .virtualfile_from_stringio ,
1793- # Note: virtualfile_from_matrix is not used because a matrix can be
1794- # converted to vectors instead, and using vectors allows for better
1795- # handling of string type inputs (e.g. for datetime data types)
1796- "matrix" : self .virtualfile_from_vectors ,
1793+ "matrix" : self .virtualfile_from_matrix ,
17971794 "vectors" : self .virtualfile_from_vectors ,
17981795 }[kind ]
17991796
@@ -1810,29 +1807,32 @@ def virtualfile_in( # noqa: PLR0912
18101807 warnings .warn (message = msg , category = RuntimeWarning , stacklevel = 2 )
18111808 _data = (data ,) if not isinstance (data , pathlib .PurePath ) else (str (data ),)
18121809 elif kind == "vectors" :
1813- _data = [np .atleast_1d (x ), np .atleast_1d (y )]
1814- if z is not None :
1815- _data .append (np .atleast_1d (z ))
1816- if extra_arrays :
1817- _data .extend (extra_arrays )
1818- elif kind == "matrix" : # turn 2-D arrays into list of vectors
1819- if hasattr (data , "items" ) and not hasattr (data , "to_frame" ):
1810+ if data is None :
1811+ # data is None, so data must be given via x/y/z.
1812+ _data = [np .atleast_1d (x ), np .atleast_1d (y )]
1813+ if z is not None :
1814+ _data .append (np .atleast_1d (z ))
1815+ if extra_arrays :
1816+ _data .extend (extra_arrays )
1817+ elif hasattr (data , "items" ) and not hasattr (data , "to_frame" ):
18201818 # pandas.DataFrame or xarray.Dataset types.
18211819 # pandas.Series will be handled below like a 1-D numpy.ndarray.
18221820 _data = [array for _ , array in data .items ()]
1823- elif hasattr (data , "ndim" ) and data .ndim == 2 and data .dtype .kind in "iuf" :
1824- # Just use virtualfile_from_matrix for 2-D numpy.ndarray
1825- # which are signed integer (i), unsigned integer (u) or
1826- # floating point (f) types
1827- _virtualfile_from = self .virtualfile_from_matrix
1828- _data = (data ,)
18291821 else :
18301822 # Python list, tuple, numpy.ndarray, and pandas.Series types
18311823 _data = np .atleast_2d (np .asanyarray (data ).T )
1824+ elif kind == "matrix" :
1825+ # GMT can only accept a 2-D matrix which are signed integer (i), unsigned
1826+ # integer (u) or floating point (f) types. For other data types, we need to
1827+ # use virtualfile_from_vectors instead, which turns the matrix into list of
1828+ # vectors and allows for better handling of string type inputs (e.g. for
1829+ # datetime data types).
1830+ _data = (data ,)
1831+ if data .dtype .kind not in "iuf" :
1832+ _virtualfile_from = self .virtualfile_from_vectors
18321833
18331834 # Finally create the virtualfile from the data, to be passed into GMT
18341835 file_context = _virtualfile_from (* _data )
1835-
18361836 return file_context
18371837
18381838 def virtualfile_from_data (
0 commit comments