@@ -1747,6 +1747,8 @@ def virtualfile_to_dataset(
1747
1747
vfname : str ,
1748
1748
output_type : Literal ["pandas" , "numpy" , "file" ] = "pandas" ,
1749
1749
column_names : list [str ] | None = None ,
1750
+ dtype : type | dict [str , type ] | None = None ,
1751
+ index_col : str | int | None = None ,
1750
1752
) -> pd .DataFrame | np .ndarray | None :
1751
1753
"""
1752
1754
Output a tabular dataset stored in a virtual file to a different format.
@@ -1766,6 +1768,11 @@ def virtualfile_to_dataset(
1766
1768
- ``"file"`` means the result was saved to a file and will return ``None``.
1767
1769
column_names
1768
1770
The column names for the :class:`pandas.DataFrame` output.
1771
+ dtype
1772
+ Data type for the columns of the :class:`pandas.DataFrame` output. Can be a
1773
+ single type for all columns or a dictionary mapping column names to types.
1774
+ index_col
1775
+ Column to set as the index of the :class:`pandas.DataFrame` output.
1769
1776
1770
1777
Returns
1771
1778
-------
@@ -1854,13 +1861,13 @@ def virtualfile_to_dataset(
1854
1861
return None
1855
1862
1856
1863
# Read the virtual file as a GMT dataset and convert to pandas.DataFrame
1857
- result = self .read_virtualfile (vfname , kind = "dataset" ).contents .to_dataframe ()
1864
+ result = self .read_virtualfile (vfname , kind = "dataset" ).contents .to_dataframe (
1865
+ column_names = column_names ,
1866
+ dtype = dtype ,
1867
+ index_col = index_col ,
1868
+ )
1858
1869
if output_type == "numpy" : # numpy.ndarray output
1859
1870
return result .to_numpy ()
1860
-
1861
- # Assign column names
1862
- if column_names is not None :
1863
- result .columns = column_names
1864
1871
return result # pandas.DataFrame output
1865
1872
1866
1873
def extract_region (self ):
0 commit comments