@@ -1738,6 +1738,42 @@ def read_virtualfile(
1738
1738
dtype = {"dataset" : _GMT_DATASET , "grid" : _GMT_GRID }[kind ]
1739
1739
return ctp .cast (pointer , ctp .POINTER (dtype ))
1740
1740
1741
+ def return_table (
1742
+ self ,
1743
+ output_type : Literal ["pandas" , "numpy" , "file" ],
1744
+ vfile : str ,
1745
+ column_names : list [str ] | None = None ,
1746
+ ) -> pd .DataFrame | np .ndarray | None :
1747
+ """
1748
+ Return an output table from a virtual file based on the output type.
1749
+
1750
+ Parameters
1751
+ ----------
1752
+ output_type
1753
+ The output type. Valid values are ``"pandas"``, ``"numpy"``, or ``"file"``.
1754
+ vfile
1755
+ The virtual file name.
1756
+ column_names
1757
+ The column names for the :class:`pandas.DataFrame` output.
1758
+
1759
+ Returns
1760
+ -------
1761
+ :class:`pandas.DataFrame` or :class:`numpy.ndarray` or None
1762
+ The output table. If ``output_type`` is ``"file"``, returns ``None``.
1763
+ """
1764
+ if output_type == "file" : # Already written to file, so return None
1765
+ return None
1766
+ # Read the virtual file as a GMT dataset and convert to pandas.DataFrame
1767
+ result = self .read_virtualfile (vfile , kind = "dataset" ).contents .to_dataframe ()
1768
+ # Assign column names
1769
+ if column_names is not None :
1770
+ result .columns = column_names
1771
+ # Pandas.DataFrame output
1772
+ if output_type == "pandas" :
1773
+ return result
1774
+ # NumPy.ndarray output
1775
+ return result .to_numpy ()
1776
+
1741
1777
def extract_region (self ):
1742
1778
"""
1743
1779
Extract the WESN bounding box of the currently active figure.
0 commit comments