@@ -1790,10 +1790,7 @@ def virtualfile_in( # noqa: PLR0912
1790
1790
"grid" : self .virtualfile_from_grid ,
1791
1791
"image" : tempfile_from_image ,
1792
1792
"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 ,
1797
1794
"vectors" : self .virtualfile_from_vectors ,
1798
1795
}[kind ]
1799
1796
@@ -1810,29 +1807,32 @@ def virtualfile_in( # noqa: PLR0912
1810
1807
warnings .warn (message = msg , category = RuntimeWarning , stacklevel = 2 )
1811
1808
_data = (data ,) if not isinstance (data , pathlib .PurePath ) else (str (data ),)
1812
1809
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" ):
1820
1818
# pandas.DataFrame or xarray.Dataset types.
1821
1819
# pandas.Series will be handled below like a 1-D numpy.ndarray.
1822
1820
_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 ,)
1829
1821
else :
1830
1822
# Python list, tuple, numpy.ndarray, and pandas.Series types
1831
1823
_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
1832
1833
1833
1834
# Finally create the virtualfile from the data, to be passed into GMT
1834
1835
file_context = _virtualfile_from (* _data )
1835
-
1836
1836
return file_context
1837
1837
1838
1838
def virtualfile_from_data (
0 commit comments